9 eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) }
11 "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test";
14 require Test::WWW::Mechanize::Catalyst;
15 Test::WWW::Mechanize::Catalyst->VERSION(0.51);
18 'Test::WWW::Mechanize::Catalyst >= 0.51 is required for this test';
22 use Test::WWW::Mechanize::Catalyst "SessionTestApp";
24 my $ua1 = Test::WWW::Mechanize::Catalyst->new;
25 my $ua2 = Test::WWW::Mechanize::Catalyst->new;
27 $_->get_ok( "http://localhost/page", "initial get" ) for $ua1, $ua2;
29 $ua1->content_contains( "please login", "ua1 not logged in" );
30 $ua2->content_contains( "please login", "ua2 not logged in" );
32 $ua1->get_ok( "http://localhost/login", "log ua1 in" );
33 $ua1->content_contains( "logged in", "ua1 logged in" );
35 $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
37 $ua1->content_contains( "you are logged in", "ua1 logged in" );
38 $ua2->content_contains( "please login", "ua2 not logged in" );
40 $ua2->get_ok( "http://localhost/login", "get main page" );
41 $ua2->content_contains( "logged in", "log ua2 in" );
43 $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
45 $ua1->content_contains( "you are logged in", "ua1 logged in" );
46 $ua2->content_contains( "you are logged in", "ua2 logged in" );
48 my ( $u1_expires ) = ($ua1->content =~ /(\d+)$/);
49 my ( $u2_expires ) = ($ua2->content =~ /(\d+)$/);
53 $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
55 $ua1->content_contains( "you are logged in", "ua1 logged in" );
56 $ua2->content_contains( "you are logged in", "ua2 logged in" );
58 my ( $u1_expires_updated ) = ($ua1->content =~ /(\d+)$/);
59 my ( $u2_expires_updated ) = ($ua2->content =~ /(\d+)$/);
61 cmp_ok( $u1_expires, "<", $u1_expires_updated, "expiry time updated");
62 cmp_ok( $u2_expires, "<", $u2_expires_updated, "expiry time updated");
64 $ua2->get_ok( "http://localhost/logout", "log ua2 out" );
65 $ua2->content_like( qr/logged out/, "ua2 logged out" );
66 $ua2->content_like( qr/after 2 request/,
67 "ua2 made 2 requests for page in the session" );
69 $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
71 $ua1->content_contains( "you are logged in", "ua1 logged in" );
72 $ua2->content_contains( "please login", "ua2 not logged in" );
74 $ua1->get_ok( "http://localhost/logout", "log ua1 out" );
75 $ua1->content_like( qr/logged out/, "ua1 logged out" );
76 $ua1->content_like( qr/after 4 requests/,
77 "ua1 made 4 request for page in the session" );
79 $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
81 $ua1->content_contains( "please login", "ua1 not logged in" );
82 $ua2->content_contains( "please login", "ua2 not logged in" );
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');
89 diag("Testing against Catalyst $Catalyst::VERSION");
90 diag("Testing Catalyst::Plugin::Session $Catalyst::Plugin::Session::VERSION");