{
BEGIN {
$ENV
{DANCER_APPHANDLER} =
'PSGI'
}
setting(
session
=>
'PSGI'
);
get
'/set/*'
=>
sub
{
my
(
$thing
) = splat;
session
thing
=>
$thing
;
};
get
'/get'
=>
sub
{
return
session(
'thing'
);
};
get
'/delete'
=>
sub
{
context->destroy_session;
return
'destroyed'
;
};
}
my
$jar
= HTTP::Cookies->new;
my
$app
||= Plack::Test->create(
builder {
enable
"Session::Cookie"
;
dance();
}
);
subtest
'Basic session set then retrieve'
=>
sub
{
my
$string
=
"boooorrrring"
;
get_request(
"/set/$string"
);
my
$res
= get_request(
'/get'
);
is
$res
->content,
$string
,
"Retrieved content back from session"
;
};
subtest
'session destruction'
=>
sub
{
my
$res
= get_request(
'/delete'
);
is
$jar
->as_string,
''
,
"destroying session expired cookie"
;
};
done_testing();
sub
get_request {
my
$path
=
shift
;
$jar
->add_cookie_header(
$req
);
my
$res
=
$app
->request(
$req
);
$jar
->extract_cookies(
$res
);
return
$res
;
}