1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
use strict;
use warnings;
use Test::More;
use Plack::Test;
use HTTP::Request::Common;
use Ref::Util qw<is_coderef>;
{
package App;
use Dancer2;
get '/' => sub {
'home:' . join( ',', params );
};
get '/bounce/' => sub { forward '/' };
get '/bounce/:withparams/' => sub { forward '/' };
get '/bounce2/adding_params/' => sub {
forward '/', { withparams => 'foo' };
};
get '/go_to_post/' => sub {
forward '/simple_post_route/',
{ foo => 'bar' },
{ method => 'post' };
};
post '/simple_post_route/' => sub {
'post:' . join( ',', params );
};
post '/' => sub {'post-home'};
post '/bounce/' => sub { forward '/' };
}
my $app = Dancer2->psgi_app;
ok( is_coderef($app), 'Got app' );
test_psgi $app, sub {
my $cb = shift;
my $res = $cb->(GET "/");
is $res->code => 200;
like $res->content => qr/home:/;
$res = $cb->(GET "/bounce/");
is $res->code => 200;
like $res->content => qr/home:/;
$res = $cb->(GET "/bounce/thesethings/");
is $res->code => 200;
is $res->content => 'home:withparams,thesethings';
$res = $cb->(GET "/bounce2/adding_params/");
is $res->code => 200;
is $res->content => 'home:withparams,foo';
$res = $cb->(GET "/go_to_post/");
is $res->code => 200;
is $res->content => 'post:foo,bar';
$res = $cb->(GET "/bounce/");
is $res->header('Content-Length') => 5;
is $res->header('Content-Type') => 'text/html; charset=UTF-8';
is $res->header('Server') => "Perl Dancer2 " . Dancer2->VERSION;
$res = $cb->(POST "/");
is $res->code => 200;
is $res->content => 'post-home';
$res = $cb->(POST "/bounce/");
is $res->code => 200;
is $res->content => 'post-home';
is $res->header('Content-Length') => 9;
is $res->header('Content-Type') => 'text/html; charset=UTF-8';
is $res->header('Server') => "Perl Dancer2 " . Dancer2->VERSION;
};
done_testing();
|