Commit | Line | Data |
db1cda22 |
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 ) = @_; |
58730edc |
32 | my $count = ++$c->session->{counter}; |
db1cda22 |
33 | $c->res->write("hit number "); |
58730edc |
34 | $c->res->write($count); |
db1cda22 |
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 | |
58730edc |
44 | $m->get_ok( "http://foo.com/stream", "get page" ); |
45 | $m->content_contains( "hit number 1", "session data created" ); |
db1cda22 |
46 | |
47 | my $expired; |
58730edc |
48 | $m->cookie_jar->scan( sub { $expired = $_[8] } ); |
db1cda22 |
49 | |
58730edc |
50 | $m->get_ok( "http://foo.com/page", "get page" ); |
51 | $m->content_contains( "hit number 2", "session data restored" ); |
db1cda22 |
52 | |
58730edc |
53 | $m->get_ok( "http://foo.com/stream", "get stream" ); |
54 | $m->content_contains( "hit number 3", "session data restored" ); |
db1cda22 |
55 | |
56 | sleep 1; |
57 | |
58730edc |
58 | $m->get_ok( "http://foo.com/page", "get stream" ); |
59 | $m->content_contains( "hit number 4", "session data restored" ); |
db1cda22 |
60 | |
61 | my $updated_expired; |
58730edc |
62 | $m->cookie_jar->scan( sub { $updated_expired = $_[8] } ); |
db1cda22 |
63 | |
58730edc |
64 | cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended" ); |