Debian Codegraph @

t/response.t

raw
1 use strict;
2 use warnings;
3 use Test::More import => ['!pass'];
4 use Dancer2;
5 use Dancer2::Core::Response;
6
7 my $r = Dancer2::Core::Response->new( content => "hello" );
8 is $r->status, 200;
9 is $r->content, 'hello';
10
11 note "content_type";
12 $r = Dancer2::Core::Response->new(
13 headers => [ 'Content-Type' => 'text/html' ],
14 content => 'foo',
15 );
16
17 is_deeply $r->to_psgi,
18 [ 200,
19 [ 'Content-Length' => 3,
20 'Content-Type' => 'text/html',
21 ],
22 ['foo']
23 ];
24
25 isa_ok $r->headers, 'HTTP::Headers';
26 is $r->content_type, 'text/html';
27
28 $r->content_type('text/plain');
29 is $r->content_type, 'text/plain';
30
31 ok( !$r->is_forwarded );
32 $r->forward('http://perldancer.org');
33 ok( $r->is_forwarded );
34
35 is $r->header('X-Foo'), undef;
36
37 $r->header( 'X-Foo' => 42 );
38 is $r->header('X-Foo'), 42;
39
40 $r->header( 'X-Foo' => 432 );
41 is $r->header('X-Foo'), 432;
42
43 $r->push_header( 'X-Foo' => 777 );
44 is $r->header('X-Foo'), '432, 777';
45
46 $r->header( 'X-Bar' => 234 );
47 is $r->header('X-Bar'), '234';
48
49 is scalar( @{ $r->headers_to_array } ), 10;
50
51 # stringify HTTP status
52 $r = Dancer2::Core::Response->new( content => "foo", status => "Not Found" );
53 is $r->status, 404;
54
55 $r =
56 Dancer2::Core::Response->new( content => "foo", status => "not_modified" );
57 is $r->status, 304;
58
59 # test setting content as "0"
60 $r = Dancer2::Core::Response->new( content => "foo" );
61 $r->content("0");
62 is $r->content, "0";
63
64 done_testing;