Commit | Line | Data |
300eb468 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | |
8 | BEGIN { |
340449a2 |
9 | eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) } |
300eb468 |
10 | or plan skip_all => |
340449a2 |
11 | "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test"; |
300eb468 |
12 | |
f8f81744 |
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'; |
300eb468 |
19 | } |
20 | |
21 | use lib "t/lib"; |
22 | use Test::WWW::Mechanize::Catalyst "SessionTestApp"; |
23 | |
24 | my $ua1 = Test::WWW::Mechanize::Catalyst->new; |
25 | my $ua2 = Test::WWW::Mechanize::Catalyst->new; |
26 | |
45c0711b |
27 | $_->get_ok( "http://localhost/page", "initial get" ) for $ua1, $ua2; |
300eb468 |
28 | |
29 | $ua1->content_contains( "please login", "ua1 not logged in" ); |
30 | $ua2->content_contains( "please login", "ua2 not logged in" ); |
31 | |
45c0711b |
32 | $ua1->get_ok( "http://localhost/login", "log ua1 in" ); |
300eb468 |
33 | $ua1->content_contains( "logged in", "ua1 logged in" ); |
34 | |
45c0711b |
35 | $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; |
300eb468 |
36 | |
37 | $ua1->content_contains( "you are logged in", "ua1 logged in" ); |
38 | $ua2->content_contains( "please login", "ua2 not logged in" ); |
39 | |
45c0711b |
40 | $ua2->get_ok( "http://localhost/login", "get main page" ); |
300eb468 |
41 | $ua2->content_contains( "logged in", "log ua2 in" ); |
42 | |
45c0711b |
43 | $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; |
300eb468 |
44 | |
45 | $ua1->content_contains( "you are logged in", "ua1 logged in" ); |
46 | $ua2->content_contains( "you are logged in", "ua2 logged in" ); |
47 | |
6687905d |
48 | my ( $u1_expires ) = ($ua1->content =~ /(\d+)$/); |
49 | my ( $u2_expires ) = ($ua2->content =~ /(\d+)$/); |
50 | |
51 | sleep 1; |
52 | |
53 | $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; |
54 | |
55 | $ua1->content_contains( "you are logged in", "ua1 logged in" ); |
56 | $ua2->content_contains( "you are logged in", "ua2 logged in" ); |
57 | |
58 | my ( $u1_expires_updated ) = ($ua1->content =~ /(\d+)$/); |
59 | my ( $u2_expires_updated ) = ($ua2->content =~ /(\d+)$/); |
60 | |
61 | cmp_ok( $u1_expires, "<", $u1_expires_updated, "expiry time updated"); |
62 | cmp_ok( $u2_expires, "<", $u2_expires_updated, "expiry time updated"); |
63 | |
45c0711b |
64 | $ua2->get_ok( "http://localhost/logout", "log ua2 out" ); |
300eb468 |
65 | $ua2->content_like( qr/logged out/, "ua2 logged out" ); |
6687905d |
66 | $ua2->content_like( qr/after 2 request/, |
67 | "ua2 made 2 requests for page in the session" ); |
300eb468 |
68 | |
45c0711b |
69 | $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; |
300eb468 |
70 | |
71 | $ua1->content_contains( "you are logged in", "ua1 logged in" ); |
72 | $ua2->content_contains( "please login", "ua2 not logged in" ); |
73 | |
45c0711b |
74 | $ua1->get_ok( "http://localhost/logout", "log ua1 out" ); |
300eb468 |
75 | $ua1->content_like( qr/logged out/, "ua1 logged out" ); |
6687905d |
76 | $ua1->content_like( qr/after 4 requests/, |
77 | "ua1 made 4 request for page in the session" ); |
300eb468 |
78 | |
45c0711b |
79 | $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; |
300eb468 |
80 | |
81 | $ua1->content_contains( "please login", "ua1 not logged in" ); |
82 | $ua2->content_contains( "please login", "ua2 not logged in" ); |
83 | |
834ab0b8 |
84 | my $ua3 = Test::WWW::Mechanize::Catalyst->new; |
85 | $ua3->get_ok( "http://localhost/login", "log ua3 in" ); |
86 | $ua3->get_ok( "http://localhost/dump_these_loads_session"); |
87 | $ua3->content_contains('NOT'); |
88 | |
d32c2b5a |
89 | my $ua4 = Test::WWW::Mechanize::Catalyst->new; |
90 | $ua4->get_ok( "http://localhost/page", "initial get" ); |
91 | $ua4->content_contains( "please login", "ua4 not logged in" ); |
92 | |
93 | $ua4->get_ok( "http://localhost/login", "log ua4 in" ); |
94 | $ua4->content_contains( "logged in", "ua4 logged in" ); |
95 | |
d32c2b5a |
96 | |
601be17a |
97 | $ua4->get( "http://localhost/page", "get page" ); |
98 | my ( $ua4_expires1 ) = ($ua4->content =~ /(\d+)$/); |
99 | $ua4->get( "http://localhost/page", "get page" ); |
100 | my ( $ua4_expires2 ) = ($ua4->content =~ /(\d+)$/); |
101 | is( $ua4_expires1, $ua4_expires2, 'expires has not changed' ); |
182d9460 |
102 | |
601be17a |
103 | $ua4->get( "http://localhost/change_session_expires", "get page" ); |
182d9460 |
104 | $ua4->get( "http://localhost/page", "get page" ); |
601be17a |
105 | my ( $ua4_expires3 ) = ($ua4->content =~ /(\d+)$/); |
106 | ok( $ua4_expires3 > ( $ua4_expires1 + 30000000), 'expires has been extended' ); |
d32c2b5a |
107 | |
32c879d3 |
108 | diag("Testing against Catalyst $Catalyst::VERSION"); |
109 | diag("Testing Catalyst::Plugin::Session $Catalyst::Plugin::Session::VERSION"); |
110 | |
834ab0b8 |
111 | done_testing; |