X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flive_app.t;h=6b9c3add2a05289a22550272c9f5ec913122a78b;hb=6afac921e72ecb6671e1a6a0b51b9dc791316bc9;hp=9abd52a31010465761b18a287f7ce507e44d2b15;hpb=45c0711b8429053673b753e54d6afa1328a5fd86;p=catagits%2FCatalyst-Plugin-Session.git diff --git a/t/live_app.t b/t/live_app.t index 9abd52a..6b9c3ad 100644 --- a/t/live_app.t +++ b/t/live_app.t @@ -6,15 +6,16 @@ use warnings; use Test::More; BEGIN { - eval { require Catalyst::Plugin::Session::State::Cookie } + eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) } or plan skip_all => - "Catalyst::Plugin::Session::State::Cookie is required for this test"; - - eval { require Test::WWW::Mechanize::Catalyst } - or plan skip_all => - "Test::WWW::Mechanize::Catalyst is required for this test"; - - plan tests => 30; + "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test"; + + eval { + require Test::WWW::Mechanize::Catalyst; + Test::WWW::Mechanize::Catalyst->VERSION(0.51); + } + or plan skip_all => + 'Test::WWW::Mechanize::Catalyst >= 0.51 is required for this test'; } use lib "t/lib"; @@ -44,10 +45,26 @@ $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; $ua1->content_contains( "you are logged in", "ua1 logged in" ); $ua2->content_contains( "you are logged in", "ua2 logged in" ); +my ( $u1_expires ) = ($ua1->content =~ /(\d+)$/); +my ( $u2_expires ) = ($ua2->content =~ /(\d+)$/); + +sleep 1; + +$_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; + +$ua1->content_contains( "you are logged in", "ua1 logged in" ); +$ua2->content_contains( "you are logged in", "ua2 logged in" ); + +my ( $u1_expires_updated ) = ($ua1->content =~ /(\d+)$/); +my ( $u2_expires_updated ) = ($ua2->content =~ /(\d+)$/); + +cmp_ok( $u1_expires, "<", $u1_expires_updated, "expiry time updated"); +cmp_ok( $u2_expires, "<", $u2_expires_updated, "expiry time updated"); + $ua2->get_ok( "http://localhost/logout", "log ua2 out" ); $ua2->content_like( qr/logged out/, "ua2 logged out" ); -$ua2->content_like( qr/after 1 request/, - "ua2 made 1 request for page in the session" ); +$ua2->content_like( qr/after 2 request/, + "ua2 made 2 requests for page in the session" ); $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; @@ -56,11 +73,39 @@ $ua2->content_contains( "please login", "ua2 not logged in" ); $ua1->get_ok( "http://localhost/logout", "log ua1 out" ); $ua1->content_like( qr/logged out/, "ua1 logged out" ); -$ua1->content_like( qr/after 3 requests/, - "ua1 made 3 request for page in the session" ); +$ua1->content_like( qr/after 4 requests/, + "ua1 made 4 request for page in the session" ); $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2; $ua1->content_contains( "please login", "ua1 not logged in" ); $ua2->content_contains( "please login", "ua2 not logged in" ); +my $ua3 = Test::WWW::Mechanize::Catalyst->new; +$ua3->get_ok( "http://localhost/login", "log ua3 in" ); +$ua3->get_ok( "http://localhost/dump_these_loads_session"); +$ua3->content_contains('NOT'); + +my $ua4 = Test::WWW::Mechanize::Catalyst->new; +$ua4->get_ok( "http://localhost/page", "initial get" ); +$ua4->content_contains( "please login", "ua4 not logged in" ); + +$ua4->get_ok( "http://localhost/login", "log ua4 in" ); +$ua4->content_contains( "logged in", "ua4 logged in" ); + + +$ua4->get( "http://localhost/page", "get page" ); +my ( $ua4_expires1 ) = ($ua4->content =~ /(\d+)$/); +$ua4->get( "http://localhost/page", "get page" ); +my ( $ua4_expires2 ) = ($ua4->content =~ /(\d+)$/); +is( $ua4_expires1, $ua4_expires2, 'expires has not changed' ); + +$ua4->get( "http://localhost/change_session_expires", "get page" ); +$ua4->get( "http://localhost/page", "get page" ); +my ( $ua4_expires3 ) = ($ua4->content =~ /(\d+)$/); +ok( $ua4_expires3 > ( $ua4_expires1 + 30000000), 'expires has been extended' ); + +diag("Testing against Catalyst $Catalyst::VERSION"); +diag("Testing Catalyst::Plugin::Session $Catalyst::Plugin::Session::VERSION"); + +done_testing;