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 $@; |
c4a96adb |
13 | plan skip_all => 'Test::WWW::Mechanize::Catalyst >= 0.40 required' if $Test::WWW::Mechanize::Catalyst::VERSION < 0.40; |
db1cda22 |
14 | plan 'no_plan'; |
15 | } |
16 | |
17 | { |
18 | |
19 | package CookieTestApp; |
20 | use Catalyst qw/ |
21 | Session |
22 | Session::Store::Dummy |
23 | Session::State::Cookie |
24 | /; |
25 | |
26 | sub page : Local { |
27 | my ( $self, $c ) = @_; |
28 | $c->res->body( "Hi! hit number " . ++$c->session->{counter} ); |
29 | } |
30 | |
31 | sub stream : Local { |
32 | my ( $self, $c ) = @_; |
58730edc |
33 | my $count = ++$c->session->{counter}; |
db1cda22 |
34 | $c->res->write("hit number "); |
58730edc |
35 | $c->res->write($count); |
db1cda22 |
36 | } |
37 | |
dbec0a9d |
38 | sub deleteme : Local { |
39 | my ( $self, $c ) = @_; |
40 | my $id = $c->get_session_id; |
41 | $c->delete_session; |
42 | my $id2 = $c->get_session_id; |
43 | $c->res->body( $id ne ( $id2 || '' ) ); |
44 | } |
45 | |
db1cda22 |
46 | __PACKAGE__->setup; |
47 | } |
48 | |
49 | use Test::WWW::Mechanize::Catalyst qw/CookieTestApp/; |
50 | |
51 | my $m = Test::WWW::Mechanize::Catalyst->new; |
52 | |
a79a56a8 |
53 | $m->get_ok( "http://localhost/stream", "get page" ); |
58730edc |
54 | $m->content_contains( "hit number 1", "session data created" ); |
db1cda22 |
55 | |
56 | my $expired; |
c4a96adb |
57 | $m->cookie_jar->scan( sub { $expired = $_[8]; } ); |
db1cda22 |
58 | |
a79a56a8 |
59 | $m->get_ok( "http://localhost/page", "get page" ); |
58730edc |
60 | $m->content_contains( "hit number 2", "session data restored" ); |
db1cda22 |
61 | |
a79a56a8 |
62 | $m->get_ok( "http://localhost/stream", "get stream" ); |
58730edc |
63 | $m->content_contains( "hit number 3", "session data restored" ); |
db1cda22 |
64 | |
a79a56a8 |
65 | sleep 1; |
db1cda22 |
66 | |
a79a56a8 |
67 | $m->get_ok( "http://localhost/page", "get stream" ); |
58730edc |
68 | $m->content_contains( "hit number 4", "session data restored" ); |
db1cda22 |
69 | |
70 | my $updated_expired; |
c4a96adb |
71 | $m->cookie_jar->scan( sub { $updated_expired = $_[8]; } ); |
db1cda22 |
72 | |
58730edc |
73 | cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended" ); |
dbec0a9d |
74 | |
a79a56a8 |
75 | $m->get_ok( "http://localhost/deleteme", "get page" ); |
dbec0a9d |
76 | $m->content_is( 1, 'session id changed' ); |