Added high performance version of the Sessions code as a branch
[catagits/Catalyst-Plugin-Session.git] / t / live_app_session.t
CommitLineData
95c6f6e8 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Data::Dumper;
8local $Data::Dumper::Sortkeys = 1;
9
10BEGIN {
11 eval {
12 require Catalyst::Plugin::Session::State::Cookie;
13 Catalyst::Plugin::Session::State::Cookie->VERSION(0.03);
14 }
15 or plan skip_all =>
16 "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test";
17
18 eval { require Test::WWW::Mechanize::Catalyst }
19 or plan skip_all =>
20 "Test::WWW::Mechanize::Catalyst is required for this test";
21
22 plan tests => 42;
23}
24
25use lib "t/lib";
26use Test::WWW::Mechanize::Catalyst "SessionTestApp";
27
28my $ua1 = Test::WWW::Mechanize::Catalyst->new;
29my $ua2 = Test::WWW::Mechanize::Catalyst->new;
30
31$_->get_ok( "http://localhost/page", "initial get" ) for $ua1, $ua2;
32
33$ua1->content_contains( "please login", "ua1 not logged in" );
34$ua2->content_contains( "please login", "ua2 not logged in" );
35
36$_->get_ok( "http://localhost/inspect_session", "check for value in session" )
37 for $ua1, $ua2;
38
39$ua1->content_contains( "value of logged_in is 'undef'",
40 "check ua1 'logged_in' val" );
41$ua2->content_contains( "value of logged_in is 'undef'",
42 "check ua2 'logged_in' val" );
43
44$_->get_ok( "http://localhost/page", "initial get" ) for $ua1, $ua2;
45
46$ua1->content_contains( "please login", "ua1 not logged in" );
47$ua2->content_contains( "please login", "ua2 not logged in" );
48
49$ua1->get_ok( "http://localhost/login", "log ua1 in" );
50$ua1->content_contains( "logged in", "ua1 logged in" );
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( "please login", "ua2 not logged in" );
56
57$ua2->get_ok( "http://localhost/login", "get main page" );
58$ua2->content_contains( "logged in", "log ua2 in" );
59
60$_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
61
62$ua1->content_contains( "you are logged in", "ua1 logged in" );
63$ua2->content_contains( "you are logged in", "ua2 logged in" );
64
65$_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
66$ua1->content_contains( "you are logged in", "ua1 logged in" );
67$ua2->content_contains( "you are logged in", "ua2 logged in" );
68
69$ua2->get_ok( "http://localhost/logout", "log ua2 out" );
70$ua2->content_like( qr/logged out/, "ua2 logged out" );
71$ua2->content_like( qr/after 2 request/,
72 "ua2 made 2 requests for page in the session" );
73
74$_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
75
76$ua1->content_contains( "you are logged in", "ua1 logged in" );
77$ua2->content_contains( "please login", "ua2 not logged in" );
78
79$ua1->get_ok( "http://localhost/logout", "log ua1 out" );
80$ua1->content_like( qr/logged out/, "ua1 logged out" );
81$ua1->content_like( qr/after 4 requests/,
82 "ua1 made 4 request for page in the session" );
83
84$_->get_ok( "http://localhost/page", "get main page" ) for $ua1, $ua2;
85
86$ua1->content_contains( "please login", "ua1 not logged in" );
87$ua2->content_contains( "please login", "ua2 not logged in" );
88