Test for cookie expiration and extension behavior, add cookie_expires, disable condit...
[catagits/Catalyst-Plugin-Session-State-Cookie.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 Test::WWW::Mechanize::Catalyst };
10     plan skip_all =>
11       "This test requires Test::WWW::Mechanize::Catalyst in order to run"
12       if $@;
13     plan 'no_plan';
14 }
15
16 {
17
18     package CookieTestApp;
19     use Catalyst qw/
20       Session
21       Session::Store::Dummy
22       Session::State::Cookie
23       /;
24
25     sub page : Local {
26         my ( $self, $c ) = @_;
27         $c->res->body( "Hi! hit number " . ++$c->session->{counter} );
28     }
29
30     sub stream : Local {
31         my ( $self, $c ) = @_;
32                 my $count = ++$c->session->{counter};
33         $c->res->write("hit number ");
34         $c->res->write( $count );
35     }
36
37     __PACKAGE__->setup;
38 }
39
40 use Test::WWW::Mechanize::Catalyst qw/CookieTestApp/;
41
42 my $m = Test::WWW::Mechanize::Catalyst->new;
43
44 $m->get_ok("http://foo.com/stream", "get page");
45 $m->content_contains("hit number 1", "session data created");
46
47 my $expired;
48 $m->cookie_jar->scan(sub { $expired = $_[8] });
49
50 $m->get_ok("http://foo.com/page", "get page");
51 $m->content_contains("hit number 2", "session data restored");
52
53 $m->get_ok("http://foo.com/stream", "get stream");
54 $m->content_contains("hit number 3", "session data restored");
55
56 sleep 1;
57
58 $m->get_ok("http://foo.com/page", "get stream");
59 $m->content_contains("hit number 4", "session data restored");
60
61 my $updated_expired;
62 $m->cookie_jar->scan(sub { $updated_expired = $_[8] });
63
64 cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended");