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