Fix RT#58856
[catagits/Catalyst-Plugin-Session.git] / t / live_app.t
CommitLineData
300eb468 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8BEGIN {
340449a2 9 eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) }
300eb468 10 or plan skip_all =>
340449a2 11 "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test";
300eb468 12
f8f81744 13 eval {
14 require Test::WWW::Mechanize::Catalyst;
15 Test::WWW::Mechanize::Catalyst->VERSION(0.51);
16 }
17 or plan skip_all =>
18 'Test::WWW::Mechanize::Catalyst >= 0.51 is required for this test';
300eb468 19}
20
21use lib "t/lib";
22use Test::WWW::Mechanize::Catalyst "SessionTestApp";
23
24my $ua1 = Test::WWW::Mechanize::Catalyst->new;
25my $ua2 = Test::WWW::Mechanize::Catalyst->new;
26
45c0711b 27$_->get_ok( "http://localhost/page", "initial get" ) for $ua1, $ua2;
300eb468 28
29$ua1->content_contains( "please login", "ua1 not logged in" );
30$ua2->content_contains( "please login", "ua2 not logged in" );
31
45c0711b 32$ua1->get_ok( "http://localhost/login", "log ua1 in" );
300eb468 33$ua1->content_contains( "logged in", "ua1 logged in" );
34
45c0711b 35$_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
300eb468 36
37$ua1->content_contains( "you are logged in", "ua1 logged in" );
38$ua2->content_contains( "please login", "ua2 not logged in" );
39
45c0711b 40$ua2->get_ok( "http://localhost/login", "get main page" );
300eb468 41$ua2->content_contains( "logged in", "log ua2 in" );
42
45c0711b 43$_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
300eb468 44
45$ua1->content_contains( "you are logged in", "ua1 logged in" );
46$ua2->content_contains( "you are logged in", "ua2 logged in" );
47
6687905d 48my ( $u1_expires ) = ($ua1->content =~ /(\d+)$/);
49my ( $u2_expires ) = ($ua2->content =~ /(\d+)$/);
50
51sleep 1;
52
53$_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
54
55$ua1->content_contains( "you are logged in", "ua1 logged in" );
56$ua2->content_contains( "you are logged in", "ua2 logged in" );
57
58my ( $u1_expires_updated ) = ($ua1->content =~ /(\d+)$/);
59my ( $u2_expires_updated ) = ($ua2->content =~ /(\d+)$/);
60
61cmp_ok( $u1_expires, "<", $u1_expires_updated, "expiry time updated");
62cmp_ok( $u2_expires, "<", $u2_expires_updated, "expiry time updated");
63
45c0711b 64$ua2->get_ok( "http://localhost/logout", "log ua2 out" );
300eb468 65$ua2->content_like( qr/logged out/, "ua2 logged out" );
6687905d 66$ua2->content_like( qr/after 2 request/,
67 "ua2 made 2 requests for page in the session" );
300eb468 68
45c0711b 69$_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
300eb468 70
71$ua1->content_contains( "you are logged in", "ua1 logged in" );
72$ua2->content_contains( "please login", "ua2 not logged in" );
73
45c0711b 74$ua1->get_ok( "http://localhost/logout", "log ua1 out" );
300eb468 75$ua1->content_like( qr/logged out/, "ua1 logged out" );
6687905d 76$ua1->content_like( qr/after 4 requests/,
77 "ua1 made 4 request for page in the session" );
300eb468 78
45c0711b 79$_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
300eb468 80
81$ua1->content_contains( "please login", "ua1 not logged in" );
82$ua2->content_contains( "please login", "ua2 not logged in" );
83
834ab0b8 84my $ua3 = Test::WWW::Mechanize::Catalyst->new;
85$ua3->get_ok( "http://localhost/login", "log ua3 in" );
86$ua3->get_ok( "http://localhost/dump_these_loads_session");
87$ua3->content_contains('NOT');
88
32c879d3 89diag("Testing against Catalyst $Catalyst::VERSION");
90diag("Testing Catalyst::Plugin::Session $Catalyst::Plugin::Session::VERSION");
91
834ab0b8 92done_testing;