fix lighttpd tests when using local::lib
[catagits/Catalyst-Runtime.git] / t / data_handler.t
CommitLineData
e2aa4a21 1#!/usr/bin/env perl
2
3use warnings;
4use strict;
5
6use FindBin;
7use Test::More;
8use HTTP::Request::Common;
9use JSON::MaybeXS;
10
11use lib "$FindBin::Bin/lib";
12use Catalyst::Test 'TestDataHandlers';
13
14ok my($res, $c) = ctx_request('/');
3eba0dd5 15
16{
17 ok my $message = 'helloworld';
18 ok my $post = encode_json +{message=>$message};
19 ok my $req = POST $c->uri_for_action('/test_json'),
20 Content_Type => 'application/json',
21 Content => $post;
22
23 ok my $response = request $req, 'got a response from a catalyst controller';
24 is $response->content, $message, 'expected content body';
25}
26
27{
28 ok my $req = POST $c->uri_for_action('/test_nested_for'), [ 'nested.value' => 'expected' ];
29 ok my $response = request $req, 'got a response from a catalyst controller';
30 is $response->content, 'expected', 'expected content body';
31}
32
c63ec19d 33{
34 my $out;
35 local *STDERR;
36 open(STDERR, ">", \$out) or die "Can't open STDERR: $!";
37 ok my $req = POST $c->uri_for_action('/test_nested_for'), 'Content-Type' => 'multipart/form-data', Content => { die => "a horrible death" };
38 ok my $response = request $req;
39 is($out, "[error] multipart/form-data does not have an available data handler. Valid data_handlers are application/json, application/x-www-form-urlencoded.\n", 'yep we throw the slightly more usefull error');
40}
e2aa4a21 41
42done_testing;