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