Merge branch 'distar' into release-candidates/rc-5.90116
[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;
c63ec19d 10use Capture::Tiny qw/:all/;
e2aa4a21 11
12use lib "$FindBin::Bin/lib";
13use Catalyst::Test 'TestDataHandlers';
14
15ok my($res, $c) = ctx_request('/');
3eba0dd5 16
17{
18 ok my $message = 'helloworld';
19 ok my $post = encode_json +{message=>$message};
20 ok my $req = POST $c->uri_for_action('/test_json'),
21 Content_Type => 'application/json',
22 Content => $post;
23
24 ok my $response = request $req, 'got a response from a catalyst controller';
25 is $response->content, $message, 'expected content body';
26}
27
28{
29 ok my $req = POST $c->uri_for_action('/test_nested_for'), [ 'nested.value' => 'expected' ];
30 ok my $response = request $req, 'got a response from a catalyst controller';
31 is $response->content, 'expected', 'expected content body';
32}
33
c63ec19d 34{
35 my $out;
36 local *STDERR;
37 open(STDERR, ">", \$out) or die "Can't open STDERR: $!";
38 ok my $req = POST $c->uri_for_action('/test_nested_for'), 'Content-Type' => 'multipart/form-data', Content => { die => "a horrible death" };
39 ok my $response = request $req;
40 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');
41}
e2aa4a21 42
43done_testing;