Checking in changes prior to tagging of version 0.11. Changelog diff is:
[catagits/Catalyst-Plugin-Session-State-Cookie.git] / t / live_app.t
CommitLineData
db1cda22 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
602b9593 6use FindBin qw/$Bin/;
7use lib "$Bin/lib";
8
db1cda22 9use Test::More;
10
11BEGIN {
12 eval { require Test::WWW::Mechanize::Catalyst };
13 plan skip_all =>
14 "This test requires Test::WWW::Mechanize::Catalyst in order to run"
15 if $@;
c4a96adb 16 plan skip_all => 'Test::WWW::Mechanize::Catalyst >= 0.40 required' if $Test::WWW::Mechanize::Catalyst::VERSION < 0.40;
db1cda22 17 plan 'no_plan';
18}
19
db1cda22 20use Test::WWW::Mechanize::Catalyst qw/CookieTestApp/;
21
22my $m = Test::WWW::Mechanize::Catalyst->new;
23
a79a56a8 24$m->get_ok( "http://localhost/stream", "get page" );
58730edc 25$m->content_contains( "hit number 1", "session data created" );
db1cda22 26
27my $expired;
c4a96adb 28$m->cookie_jar->scan( sub { $expired = $_[8]; } );
db1cda22 29
a79a56a8 30$m->get_ok( "http://localhost/page", "get page" );
58730edc 31$m->content_contains( "hit number 2", "session data restored" );
db1cda22 32
a79a56a8 33$m->get_ok( "http://localhost/stream", "get stream" );
58730edc 34$m->content_contains( "hit number 3", "session data restored" );
db1cda22 35
a79a56a8 36sleep 1;
db1cda22 37
9013c08b 38$m->get_ok( "http://localhost/stream", "get page" );
58730edc 39$m->content_contains( "hit number 4", "session data restored" );
db1cda22 40
41my $updated_expired;
c4a96adb 42$m->cookie_jar->scan( sub { $updated_expired = $_[8]; } );
58730edc 43cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended" );
dbec0a9d 44
9013c08b 45$expired = $m->cookie_jar->scan( sub { $expired = $_[8] } );
46$m->get_ok( "http://localhost/page", "get page again");
47$m->content_contains( "hit number 5", "session data restored (blah)" );
48
49sleep 1;
50
51$m->get_ok( "http://localhost/stream", "get stream" );
52$m->content_contains( "hit number 6", "session data restored" );
53
54$m->cookie_jar->scan( sub { $updated_expired = $_[8]; } );
55cmp_ok( $expired, "<", $updated_expired, "streaming also extends cookie" );
56
a79a56a8 57$m->get_ok( "http://localhost/deleteme", "get page" );
dbec0a9d 58$m->content_is( 1, 'session id changed' );