Ignore .git from MANIFEST
[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 {
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';
19
20     plan tests => 36;
21 }
22
23 use lib "t/lib";
24 use Test::WWW::Mechanize::Catalyst "SessionTestApp";
25
26 my $ua1 = Test::WWW::Mechanize::Catalyst->new;
27 my $ua2 = Test::WWW::Mechanize::Catalyst->new;
28
29 $_->get_ok( "http://localhost/page", "initial get" ) for $ua1, $ua2;
30
31 $ua1->content_contains( "please login", "ua1 not logged in" );
32 $ua2->content_contains( "please login", "ua2 not logged in" );
33
34 $ua1->get_ok( "http://localhost/login", "log ua1 in" );
35 $ua1->content_contains( "logged in", "ua1 logged in" );
36
37 $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
38
39 $ua1->content_contains( "you are logged in", "ua1 logged in" );
40 $ua2->content_contains( "please login",      "ua2 not logged in" );
41
42 $ua2->get_ok( "http://localhost/login", "get main page" );
43 $ua2->content_contains( "logged in", "log ua2 in" );
44
45 $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
46
47 $ua1->content_contains( "you are logged in", "ua1 logged in" );
48 $ua2->content_contains( "you are logged in", "ua2 logged in" );
49
50 my ( $u1_expires ) = ($ua1->content =~ /(\d+)$/);
51 my ( $u2_expires ) = ($ua2->content =~ /(\d+)$/);
52
53 sleep 1;
54
55 $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
56
57 $ua1->content_contains( "you are logged in", "ua1 logged in" );
58 $ua2->content_contains( "you are logged in", "ua2 logged in" );
59
60 my ( $u1_expires_updated ) = ($ua1->content =~ /(\d+)$/);
61 my ( $u2_expires_updated ) = ($ua2->content =~ /(\d+)$/);
62
63 cmp_ok( $u1_expires, "<", $u1_expires_updated, "expiry time updated");
64 cmp_ok( $u2_expires, "<", $u2_expires_updated, "expiry time updated");
65
66 $ua2->get_ok( "http://localhost/logout", "log ua2 out" );
67 $ua2->content_like( qr/logged out/, "ua2 logged out" );
68 $ua2->content_like( qr/after 2 request/,
69     "ua2 made 2 requests for page in the session" );
70
71 $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
72
73 $ua1->content_contains( "you are logged in", "ua1 logged in" );
74 $ua2->content_contains( "please login",      "ua2 not logged in" );
75
76 $ua1->get_ok( "http://localhost/logout", "log ua1 out" );
77 $ua1->content_like( qr/logged out/, "ua1 logged out" );
78 $ua1->content_like( qr/after 4 requests/,
79     "ua1 made 4 request for page in the session" );
80
81 $_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
82
83 $ua1->content_contains( "please login", "ua1 not logged in" );
84 $ua2->content_contains( "please login", "ua2 not logged in" );
85
86 diag("Testing against Catalyst $Catalyst::VERSION");
87 diag("Testing Catalyst::Plugin::Session $Catalyst::Plugin::Session::VERSION");
88