5 # Test case for reported issue when an action consumes JSON but a
6 # POST sends nothing we get a hard error
9 package MyApp::Controller::Root;
10 $INC{'MyApp/Controller/Root.pm'} = __FILE__;
12 use base 'Catalyst::Controller';
14 sub bar :Local Args(0) GET {
23 use HTTP::Request::Common;
24 use Catalyst::Test 'MyApp';
26 # These tests assume that the decoding that occurs for the query string follows
27 # the payload decoding algorithm described here:
28 # https://www.w3.org/TR/html5/forms.html#url-encoded-form-data
31 ok my $req = GET 'root/bar',
32 'Content-Type' => 'application/x-www-form-urlencoded';
34 my ($res, $c) = ctx_request($req);
36 ok !defined($c->req->query_keywords), 'query_keywords is not defined when no ?';
37 is_deeply $c->req->query_parameters, {}, 'query_parameters defined, but empty for no ?';
42 ok my $req = GET 'root/bar?',
43 'Content-Type' => 'application/x-www-form-urlencoded';
45 my ($res, $c) = ctx_request($req);
47 is $c->req->query_keywords, '', 'query_keywords is not defined with empty query string';
48 is_deeply $c->req->query_parameters, {}, 'query_parameters defined, but empty with empty query string';
53 ok my $req = GET 'root/bar?a=b',
54 'Content-Type' => 'application/x-www-form-urlencoded';
56 my ($res, $c) = ctx_request($req);
58 ok !defined($c->req->query_keywords), 'query_keywords undefined when isindex not set';
59 is_deeply $c->req->query_parameters, { a => 'b' }, 'query_parameters defined for ?a=b';
64 ok my $req = GET 'root/bar?x',
65 'Content-Type' => 'application/x-www-form-urlencoded';
67 my ($res, $c) = ctx_request($req);
69 is $c->req->query_keywords, 'x', 'query_keywords defined for ?x';
70 # The algorithm reads like 'x' should be treated as a value, not a name.
71 # Perl does not support undef as a hash key. I feel this would be the best
72 # alternative as isindex is moving towards complete deprecation.
73 is_deeply $c->req->query_parameters, { 'x' => undef }, 'query_parameters defined for ?x';
78 ok my $req = GET 'root/bar?x&a=b',
79 'Content-Type' => 'application/x-www-form-urlencoded';
81 my ($res, $c) = ctx_request($req);
83 is $c->req->query_keywords, 'x', 'query_keywords defined for ?x&a=b';
84 # See comment above about the 'query_parameters defined for ?x' test case.
85 is_deeply $c->req->query_parameters, { 'x' => undef, a => 'b' }, 'query_parameters defined for ?x&a=b';