fix State::Cookie so that tests work with newer TWMCs
[catagits/Catalyst-Plugin-Session-State-Cookie.git] / t / live_app.t
CommitLineData
db1cda22 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8BEGIN {
9 eval { require Test::WWW::Mechanize::Catalyst };
10 plan skip_all =>
11 "This test requires Test::WWW::Mechanize::Catalyst in order to run"
12 if $@;
13 plan 'no_plan';
14}
15
16{
17
18 package CookieTestApp;
19 use Catalyst qw/
20 Session
21 Session::Store::Dummy
22 Session::State::Cookie
23 /;
24
25 sub page : Local {
26 my ( $self, $c ) = @_;
27 $c->res->body( "Hi! hit number " . ++$c->session->{counter} );
28 }
29
30 sub stream : Local {
31 my ( $self, $c ) = @_;
58730edc 32 my $count = ++$c->session->{counter};
db1cda22 33 $c->res->write("hit number ");
58730edc 34 $c->res->write($count);
db1cda22 35 }
36
dbec0a9d 37 sub deleteme : Local {
38 my ( $self, $c ) = @_;
39 my $id = $c->get_session_id;
40 $c->delete_session;
41 my $id2 = $c->get_session_id;
42 $c->res->body( $id ne ( $id2 || '' ) );
43 }
44
db1cda22 45 __PACKAGE__->setup;
46}
47
48use Test::WWW::Mechanize::Catalyst qw/CookieTestApp/;
49
50my $m = Test::WWW::Mechanize::Catalyst->new;
51
a79a56a8 52$m->get_ok( "http://localhost/stream", "get page" );
58730edc 53$m->content_contains( "hit number 1", "session data created" );
db1cda22 54
55my $expired;
a79a56a8 56$m->cookie_jar->scan( sub { $expired = $_[8]; warn join":",@_; } );
db1cda22 57
a79a56a8 58$m->get_ok( "http://localhost/page", "get page" );
58730edc 59$m->content_contains( "hit number 2", "session data restored" );
db1cda22 60
a79a56a8 61$m->get_ok( "http://localhost/stream", "get stream" );
58730edc 62$m->content_contains( "hit number 3", "session data restored" );
db1cda22 63
a79a56a8 64sleep 1;
db1cda22 65
a79a56a8 66$m->get_ok( "http://localhost/page", "get stream" );
58730edc 67$m->content_contains( "hit number 4", "session data restored" );
db1cda22 68
69my $updated_expired;
a79a56a8 70$m->cookie_jar->scan( sub { $updated_expired = $_[8]; warn join":",@_; } );
db1cda22 71
58730edc 72cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended" );
dbec0a9d 73
a79a56a8 74$m->get_ok( "http://localhost/deleteme", "get page" );
dbec0a9d 75$m->content_is( 1, 'session id changed' );