convert test checking encoding set in config to checking encoding set by plugin
[catagits/Catalyst-Runtime.git] / t / query_keywords_and_parameters.t
1 use warnings;
2 use strict;
3 use Test::More;
4
5 # Test case for reported issue when an action consumes JSON but a
6 # POST sends nothing we get a hard error
7
8 {
9   package MyApp::Controller::Root;
10   $INC{'MyApp/Controller/Root.pm'} = __FILE__;
11
12   use base 'Catalyst::Controller';
13
14   sub bar :Local Args(0) GET {
15     my( $self, $c ) = @_;
16   }
17
18   package MyApp;
19   use Catalyst;
20   MyApp->setup;
21 }
22
23 use HTTP::Request::Common;
24 use Catalyst::Test 'MyApp';
25
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
29
30 {
31   ok my $req = GET 'root/bar';
32
33   my ($res, $c) = ctx_request($req);
34
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 ?';
37 }
38
39
40 {
41   ok my $req = GET 'root/bar?';
42
43   my ($res, $c) = ctx_request($req);
44
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';
47 }
48
49
50 {
51   ok my $req = GET 'root/bar?a=b';
52
53   my ($res, $c) = ctx_request($req);
54
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';
57 }
58
59
60 {
61   ok my $req = GET 'root/bar?x';
62
63   my ($res, $c) = ctx_request($req);
64
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';
70 }
71
72
73 {
74   ok my $req = GET 'root/bar?x&a=b';
75
76   my ($res, $c) = ctx_request($req);
77
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';
81 }
82
83
84 done_testing();