add test for extend_session_expires
[catagits/Catalyst-Plugin-Session.git] / t / live_app.t
index 63f69cb..97f7102 100644 (file)
@@ -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 => 36;
+      "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";
@@ -80,3 +81,33 @@ $_->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_ok( "http://localhost/extend_session_expires", "ua4 extend expire session" );
+
+my ( $ua4_expires ) = ($ua4->content =~ /(\d+)$/);
+
+ok( ($ua4_expires - time() - 86400) >= 0, 'extend_session_expires with really long value' );
+
+sleep 1;
+
+$ua4->get( "http://localhost/page", "get page" );
+my ( $ua4_expires_updated ) = ($ua4->content =~ /(\d+)$/);
+diag( "ua4_expires => $ua4_expires");
+diag( "ua4_expires_updated => $ua4_expires_updated");
+ok( $ua4_expires < $ua4_expires_updated, 'update extended session' );
+
+diag("Testing against Catalyst $Catalyst::VERSION");
+diag("Testing Catalyst::Plugin::Session $Catalyst::Plugin::Session::VERSION");
+
+done_testing;