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';
33 my ($res, $c) = ctx_request($req);
35 ok !defined($c->req->query_keywords), 'query_keywords is not defined when no ?';
36 is_deeply $c->req->query_parameters, {}, 'query_parameters defined, but empty for no ?';
41 ok my $req = GET 'root/bar?';
43 my ($res, $c) = ctx_request($req);
45 ok !defined $c->req->query_keywords, 'query_keywords is not defined when ? with empty query string';
46 is_deeply $c->req->query_parameters, {}, 'query_parameters defined, but empty with empty query string';
51 ok my $req = GET 'root/bar?a=b';
53 my ($res, $c) = ctx_request($req);
55 ok !defined($c->req->query_keywords), 'query_keywords undefined when isindex not set';
56 is_deeply $c->req->query_parameters, { a => 'b' }, 'query_parameters defined for ?a=b';
61 ok my $req = GET 'root/bar?x';
63 my ($res, $c) = ctx_request($req);
65 is $c->req->query_keywords, 'x', 'query_keywords defined for ?x';
66 # The algorithm reads like 'x' should be treated as a value, not a name.
67 # Perl does not support undef as a hash key. I feel this would be the best
68 # alternative as isindex is moving towards complete deprecation.
69 is_deeply $c->req->query_parameters, { 'x' => undef }, 'query_parameters defined for ?x';
74 ok my $req = GET 'root/bar?x&a=b';
76 my ($res, $c) = ctx_request($req);
78 is $c->req->query_keywords, 'x', 'query_keywords defined for ?x&a=b';
79 # See comment above about the 'query_parameters defined for ?x' test case.
80 is_deeply $c->req->query_parameters, { 'x' => undef, a => 'b' }, 'query_parameters defined for ?x&a=b';