9 eval { require Test::WWW::Mechanize::Catalyst };
11 "This test requires Test::WWW::Mechanize::Catalyst in order to run"
18 package CookieTestApp;
22 Session::State::Cookie
26 my ( $self, $c ) = @_;
27 $c->res->body( "Hi! hit number " . ++$c->session->{counter} );
31 my ( $self, $c ) = @_;
32 my $count = ++$c->session->{counter};
33 $c->res->write("hit number ");
34 $c->res->write($count);
37 sub deleteme : Local {
38 my ( $self, $c ) = @_;
39 my $id = $c->get_session_id;
41 my $id2 = $c->get_session_id;
42 $c->res->body( $id ne ( $id2 || '' ) );
48 use Test::WWW::Mechanize::Catalyst qw/CookieTestApp/;
50 my $m = Test::WWW::Mechanize::Catalyst->new;
52 $m->get_ok( "http://localhost/stream", "get page" );
53 $m->content_contains( "hit number 1", "session data created" );
56 $m->cookie_jar->scan( sub { $expired = $_[8]; warn join":",@_; } );
58 $m->get_ok( "http://localhost/page", "get page" );
59 $m->content_contains( "hit number 2", "session data restored" );
61 $m->get_ok( "http://localhost/stream", "get stream" );
62 $m->content_contains( "hit number 3", "session data restored" );
66 $m->get_ok( "http://localhost/page", "get stream" );
67 $m->content_contains( "hit number 4", "session data restored" );
70 $m->cookie_jar->scan( sub { $updated_expired = $_[8]; warn join":",@_; } );
72 cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended" );
74 $m->get_ok( "http://localhost/deleteme", "get page" );
75 $m->content_is( 1, 'session id changed' );