Commit | Line | Data |
0421e89a |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | |
8 | BEGIN { |
9 | eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) } |
10 | or plan skip_all => |
11 | "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test"; |
12 | |
13 | eval { |
14 | require Test::WWW::Mechanize::Catalyst; |
15 | Test::WWW::Mechanize::Catalyst->VERSION(0.51); |
16 | } |
17 | or plan skip_all => |
18 | 'Test::WWW::Mechanize::Catalyst >= 0.51 is required for this test'; |
19 | } |
20 | |
21 | use lib "t/lib"; |
079b2fbe |
22 | use Test::WWW::Mechanize::Catalyst "SessionExpiry"; |
0421e89a |
23 | |
24 | my $ua = Test::WWW::Mechanize::Catalyst->new; |
25 | |
079b2fbe |
26 | my $res = $ua->get( "http://localhost/session_data_expires" ); |
27 | ok($res->is_success, "session_data_expires"); |
0421e89a |
28 | |
079b2fbe |
29 | my $expiry = $res->decoded_content + 0; |
30 | |
31 | $res = $ua->get( "http://localhost/session_expires" ); |
32 | ok($res->is_success, "session_expires"); |
33 | is($res->decoded_content, $expiry, "session_expires == session_data_expires"); |
0421e89a |
34 | |
35 | sleep(1); |
36 | |
079b2fbe |
37 | $res = $ua->get( "http://localhost/session_data_expires" ); |
38 | ok($res->is_success, "session_data_expires"); |
0421e89a |
39 | |
40 | is($res->decoded_content, $expiry, "expiration not updated"); |
41 | |
079b2fbe |
42 | $res = $ua->get( "http://localhost/session_expires" ); |
43 | ok($res->is_success, "session_expires"); |
44 | is($res->decoded_content, $expiry, "session_expires == session_data_expires"); |
45 | |
3d03a2ba |
46 | # |
47 | |
48 | $res = $ua->get( "http://localhost/update_session" ); |
49 | ok($res->is_success, "update_session"); |
0421e89a |
50 | |
079b2fbe |
51 | $res = $ua->get( "http://localhost/session_data_expires" ); |
52 | ok($res->is_success, "session_data_expires"); |
53 | |
54 | my $updated = $res->decoded_content + 0; |
55 | ok($updated > $expiry, "expiration updated"); |
56 | |
3d03a2ba |
57 | $expiry = $updated; |
58 | |
59 | $res = $ua->get( "http://localhost/session_data_expires" ); |
60 | ok($res->is_success, "session_data_expires"); |
61 | |
62 | is($res->decoded_content, $expiry, "expiration not updated"); |
63 | |
64 | $res = $ua->get( "http://localhost/session_expires" ); |
65 | ok($res->is_success, "session_expires"); |
66 | is($res->decoded_content, $expiry, "session_expires == session_data_expires"); |
67 | |
68 | sleep(10); |
69 | |
70 | $res = $ua->get( "http://localhost/session_data_expires" ); |
71 | ok($res->is_success, "session_data_expires"); |
72 | |
73 | $updated = $res->decoded_content + 0; |
74 | ok($updated > $expiry, "expiration updated"); |
75 | |
079b2fbe |
76 | $res = $ua->get( "http://localhost/session_expires" ); |
77 | ok($res->is_success, "session_expires"); |
78 | is($res->decoded_content, $updated, "session_expires == session_data_expires"); |
0421e89a |
79 | |
0421e89a |
80 | |
81 | done_testing; |