Added a failing test for a situation that occurs when you have a cookie for a session...
Adam Prime [Wed, 4 Nov 2009 19:53:19 +0000 (19:53 +0000)]
t/lib/SessionValid.pm [new file with mode: 0644]
t/lib/SessionValid/Controller/Root.pm [new file with mode: 0644]
t/session_valid.t [new file with mode: 0644]

diff --git a/t/lib/SessionValid.pm b/t/lib/SessionValid.pm
new file mode 100644 (file)
index 0000000..17c640c
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+
+package SessionValid;
+use Catalyst qw/Session Session::Store::Dummy Session::State::Cookie/;
+
+use strict;
+use warnings;
+
+__PACKAGE__->config->{'session'} = {
+    cookie_expires => 0,
+    expires => 1,
+};
+
+__PACKAGE__->setup;
+
+__PACKAGE__;
+
diff --git a/t/lib/SessionValid/Controller/Root.pm b/t/lib/SessionValid/Controller/Root.pm
new file mode 100644 (file)
index 0000000..9d6581d
--- /dev/null
@@ -0,0 +1,17 @@
+package SessionValid::Controller::Root;
+use strict;
+use warnings;
+use Data::Dumper;
+
+use base qw/Catalyst::Controller/;
+
+__PACKAGE__->config( namespace => '' );
+
+sub index :Path :Args(0) {
+    my ( $self, $c ) = @_;
+    $c->session->{'value'} = 'value set';
+    $c->session_is_valid;
+    $c->res->output($c->session->{'value'});
+}
+
+1;
diff --git a/t/session_valid.t b/t/session_valid.t
new file mode 100644 (file)
index 0000000..1d9d7d6
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+BEGIN {
+    eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) }
+      or plan skip_all =>
+      "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';
+
+    plan tests => 4;
+}
+
+use lib "t/lib";
+use Test::WWW::Mechanize::Catalyst "SessionValid";
+
+my $ua = Test::WWW::Mechanize::Catalyst->new;
+
+$ua->get_ok( "http://localhost/", "initial get" );
+$ua->content_contains( "value set", "page contains expected value" );
+
+sleep 2;
+
+$ua->get_ok( "http://localhost/", "grab the page again, after the session has expired" );
+$ua->content_contains( "value set", "page contains expected value" );
+