Debian Codegraph @

t/shared_engines.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4 use Plack::Test;
5 use HTTP::Cookies;
6 use HTTP::Request::Common;
7
8 {
9 package App;
10
11 # call stuff before next use() statement
12 BEGIN {
13 use Dancer2;
14 set session => 'Simple';
15 engine('session')->{'__marker__'} = 1;
16 }
17
18 use lib '.';
19 use t::lib::Foo with => { session => engine('session') };
20
21 get '/main' => sub {
22 session( 'test' => 42 );
23 };
24 }
25
26 my $jar = HTTP::Cookies->new;
27 my $url = 'http://localhost';
28
29 {
30 my $test = Plack::Test->create( App->to_app );
31 my $res = $test->request( GET "$url/main" );
32 like $res->content, qr{42}, "session is set in main";
33 $jar->extract_cookies($res);
34
35 ok( $jar->as_string, 'Got cookie' );
36 }
37
38 {
39 my $test = Plack::Test->create( t::lib::Foo->to_app );
40 my $req = GET "$url/in_foo";
41 $jar->add_cookie_header($req);
42
43 my $res = $test->request($req);
44 like $res->content, qr{42}, "session is set in foo";
45 }
46
47 my $engine = t::lib::Foo->dsl->engine('session');
48 is $engine->{__marker__}, 1,
49 "the session engine in subapp is the same";
50
51 done_testing;