root/lang/perl/HTTP-Engine/trunk/t/10_request_builder.t @ 11543

Revision 11543, 1.6 kB (checked in by tokuhirom, 7 years ago)

$c->env is not a useful, we should use %ENV directly.

Line 
1use Test::Base;
2use YAML ();
3use HTTP::Engine::Context;
4use HTTP::Engine::RequestBuilder;
5use IO::Scalar;
6
7plan tests => 7;
8
9can_ok(
10    'HTTP::Engine::RequestBuilder' => 'prepare'
11);
12
13filters {
14    env => [qw/yaml/]
15};
16
17my $builder = HTTP::Engine::RequestBuilder->new;
18
19run {
20    my $block = shift;
21
22    local %ENV = %{ $block->env };
23    my $c = HTTP::Engine::Context->new();
24
25    tie *STDIN, 'IO::Scalar', \( $block->body );
26    $builder->prepare($c);
27    untie *STDIN;
28
29    eval $block->test;
30    die $@ if $@;
31};
32
33__END__
34
35===
36--- env
37REMOTE_ADDR:    127.0.0.1
38SERVER_PORT:    80
39QUERY_STRING:   ''
40REQUEST_METHOD: 'GET'
41HTTP_HOST: localhost
42--- body
43--- test
44is $c->req->address, '127.0.0.1';
45
46===
47--- env
48REMOTE_ADDR:    127.0.0.1
49SERVER_PORT:    80
50QUERY_STRING:   ''
51REQUEST_METHOD: 'POST'
52HTTP_HOST: localhost
53HTTP_CONTENT_LENGTH: 7
54HTTP_CONTENT_TYPE: application/x-www-form-urlencoded
55--- body: a=b&c=d
56--- test
57is_deeply $c->req->body_params, {a => 'b', c => 'd'};
58
59===
60--- env
61REMOTE_ADDR:    127.0.0.1
62SERVER_PORT:    80
63QUERY_STRING:   ''
64REQUEST_METHOD: 'POST'
65HTTP_HOST: localhost
66HTTP_CONTENT_LENGTH: 12
67HTTP_CONTENT_TYPE: application/octet-stream
68--- body: OCTET STREAM
69--- test
70isa_ok $c->req->body, 'IO::Handle';
71$c->req->body->sysread(my $buf, $c->req->content_length);
72is $buf, 'OCTET STREAM';
73
74=== cookie
75--- env
76REMOTE_ADDR:    127.0.0.1
77SERVER_PORT:    80
78QUERY_STRING:   ''
79REQUEST_METHOD: 'POST'
80HTTP_HOST: localhost
81HTTP_CONTENT_LENGTH: 12
82HTTP_CONTENT_TYPE: application/octet-stream
83HTTP_COOKIE: foo=hoge; foo=hoge; path=/
84--- body: OCTET STREAM
85--- test
86is $c->req->cookie('unknown'), undef;
87is $c->req->cookie('foo')->value, 'hoge';
88
Note: See TracBrowser for help on using the browser.