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'; |
45c0711b |
19 | |
6687905d |
20 | plan tests => 36; |
300eb468 |
21 | } |
22 | |
23 | use lib "t/lib"; |
24 | use Test::WWW::Mechanize::Catalyst "SessionTestApp"; |
25 | |
26 | my $ua1 = Test::WWW::Mechanize::Catalyst->new; |
27 | my $ua2 = Test::WWW::Mechanize::Catalyst->new; |
28 | |
45c0711b |
29 | $_->get_ok( "http://localhost/page", "initial get" ) for $ua1, $ua2; |
300eb468 |
30 | |
31 | $ua1->content_contains( "please login", "ua1 not logged in" ); |
32 | $ua2->content_contains( "please login", "ua2 not logged in" ); |
33 | |
45c0711b |
34 | $ua1->get_ok( "http://localhost/login", "log ua1 in" ); |
300eb468 |
35 | $ua1->content_contains( "logged in", "ua1 logged in" ); |
36 | |
45c0711b |
37 | $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; |
300eb468 |
38 | |
39 | $ua1->content_contains( "you are logged in", "ua1 logged in" ); |
40 | $ua2->content_contains( "please login", "ua2 not logged in" ); |
41 | |
45c0711b |
42 | $ua2->get_ok( "http://localhost/login", "get main page" ); |
300eb468 |
43 | $ua2->content_contains( "logged in", "log ua2 in" ); |
44 | |
45c0711b |
45 | $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; |
300eb468 |
46 | |
47 | $ua1->content_contains( "you are logged in", "ua1 logged in" ); |
48 | $ua2->content_contains( "you are logged in", "ua2 logged in" ); |
49 | |
6687905d |
50 | my ( $u1_expires ) = ($ua1->content =~ /(\d+)$/); |
51 | my ( $u2_expires ) = ($ua2->content =~ /(\d+)$/); |
52 | |
53 | sleep 1; |
54 | |
55 | $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; |
56 | |
57 | $ua1->content_contains( "you are logged in", "ua1 logged in" ); |
58 | $ua2->content_contains( "you are logged in", "ua2 logged in" ); |
59 | |
60 | my ( $u1_expires_updated ) = ($ua1->content =~ /(\d+)$/); |
61 | my ( $u2_expires_updated ) = ($ua2->content =~ /(\d+)$/); |
62 | |
63 | cmp_ok( $u1_expires, "<", $u1_expires_updated, "expiry time updated"); |
64 | cmp_ok( $u2_expires, "<", $u2_expires_updated, "expiry time updated"); |
65 | |
45c0711b |
66 | $ua2->get_ok( "http://localhost/logout", "log ua2 out" ); |
300eb468 |
67 | $ua2->content_like( qr/logged out/, "ua2 logged out" ); |
6687905d |
68 | $ua2->content_like( qr/after 2 request/, |
69 | "ua2 made 2 requests for page in the session" ); |
300eb468 |
70 | |
45c0711b |
71 | $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; |
300eb468 |
72 | |
73 | $ua1->content_contains( "you are logged in", "ua1 logged in" ); |
74 | $ua2->content_contains( "please login", "ua2 not logged in" ); |
75 | |
45c0711b |
76 | $ua1->get_ok( "http://localhost/logout", "log ua1 out" ); |
300eb468 |
77 | $ua1->content_like( qr/logged out/, "ua1 logged out" ); |
6687905d |
78 | $ua1->content_like( qr/after 4 requests/, |
79 | "ua1 made 4 request for page in the session" ); |
300eb468 |
80 | |
45c0711b |
81 | $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; |
300eb468 |
82 | |
83 | $ua1->content_contains( "please login", "ua1 not logged in" ); |
84 | $ua2->content_contains( "please login", "ua2 not logged in" ); |
85 | |
32c879d3 |
86 | diag("Testing against Catalyst $Catalyst::VERSION"); |
87 | diag("Testing Catalyst::Plugin::Session $Catalyst::Plugin::Session::VERSION"); |
88 | |