updated gitignore
[catagits/Catalyst-Plugin-Session-State-Stash.git] / t / 05-live.t
CommitLineData
642b19cf 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use URI::Escape;
7use Test::More;
8
9BEGIN {
10 eval { require Test::WWW::Mechanize::Catalyst };
11 plan skip_all =>
12 "This test requires Test::WWW::Mechanize::Catalyst in order to run"
13 if $@;
14 plan skip_all => 'Test::WWW::Mechanize::Catalyst >= 0.40 required' if $Test::WWW::Mechanize::Catalyst::VERSION < 0.40;
15}
16
17{
18
19 package TestApp;
20 use Catalyst qw/
21 Session
22 Session::Store::Dummy
23 Session::State::Stash
24 -Debug
25 /;
26
27 sub start_session : Local {
28 my ( $self, $c ) = @_;
29 $c->session->{counter} = 1;
30 $c->res->body($c->stash->{_session}->{id});
31 }
32
33 sub page : Local {
34 my ( $self, $c, $id ) = @_;
35 $c->stash ( '_session' => {id => $id} );
36 $c->res->body( "Hi! hit number " . ++$c->session->{counter} );
37 }
38
39 sub stream : Local {
40 my ( $self, $c, $id ) = @_;
41 $c->stash ( '_session' => {id => $id} );
42 my $count = ++$c->session->{counter};
43 $c->res->body("hit number $count");
44 }
45
46 sub deleteme : Local {
47 my ( $self, $c, $id ) = @_;
48 $c->stash ( '_session' => {id => $id} );
49 my $id2 = $c->get_session_id;
50 $c->delete_session;
51 my $id3 = $c->get_session_id;
52
53 # In the success case, print 'Pass'
54 if (defined $id2 &&
55 defined $id3 &&
56 $id2 ne $id3
57 ) {
58 $c->res->body('PASS');
59 } else {
60 #In the failure case, provide debug info
61 $c->res->body("FAIL: Matching ids, $id3");
62 }
63 }
64
65 __PACKAGE__->setup;
66}
67
68use Test::WWW::Mechanize::Catalyst qw/TestApp/;
69
70my $m = Test::WWW::Mechanize::Catalyst->new;
71
72#Number of tests to run. A begin block every 10 will ensure the count is correct
73my $tests;
74plan tests => $tests;
75
76$m->get_ok( "http://localhost/start_session", "get page" );
77my $session = uri_escape($m->content);
78
79$m->get_ok( "http://localhost/page/$session", "get page" );
80$m->content_contains( "hit number 2", "session data restored" );
81
82$m->get_ok( "http://localhost/stream/$session", "get stream" );
83$m->content_contains( "hit number 3", "session data restored" );
84
85BEGIN { $tests += 5; }
86
87$m->get_ok( "http://localhost/stream/$session", "get page" );
88$m->content_contains( "hit number 4", "session data restored" );
89$m->get_ok( "http://localhost/deleteme/$session", "get page" );
90
91TODO: {
92 local $TODO = "Changing sessions is broken and I've had no success fixing it. Patches welcome";
93 $m->content_is( 'PASS' , 'session id changed' );
94}
95BEGIN { $tests += 4; }