merged conflicts
[catagits/Catalyst-Runtime.git] / t / author / unicode_plugin_nested_params.t
CommitLineData
55046410 1use strict;
2use warnings;
3use Test::More;
4use utf8;
5
6# setup library path
7use FindBin qw($Bin);
465e85c1 8use lib "$Bin/../lib";
55046410 9
10BEGIN { eval { require Catalyst::Plugin::Params::Nested; 1; } ||
11 plan skip_all => 'Need Catalyst::Plugin::Params::Nested' }
12
13use Catalyst::Test 'TestApp2';
14use Encode;
15use HTTP::Request::Common;
16use URI::Escape qw/uri_escape_utf8/;
17use HTTP::Status 'is_server_error';
18
19my $encode_str = "\x{e3}\x{81}\x{82}"; # e38182 is japanese 'あ'
20my $decode_str = Encode::decode('utf-8' => $encode_str);
21my $escape_str = uri_escape_utf8($decode_str);
22
23BEGIN {
24 eval 'require Catalyst::Plugin::Params::Nested';
25 plan skip_all => 'Catalyst::Plugin::Params::Nested is required' if $@;
26}
27
28{
29 my ($res, $c) = ctx_request("/?foo.1=bar&foo.2=$escape_str");
30 is( $c->res->output, '<h1>It works</h1>', 'Content displayed' );
31
32 my $got = $c->request->parameters;
33 my $expected = {
34 'foo.1' => 'bar',
35 'foo.2' => $decode_str,
36 'foo' => [undef, 'bar', $decode_str],
37 };
38
39 is( $got->{foo}->[0], undef, '{foo}->[0] is undef' );
40 is( $got->{foo}->[1], 'bar', '{foo}->[1] is bar' );
41 ok( utf8::is_utf8( $got->{'foo.2'} ), '{foo.2} is utf8' );
42 ok( utf8::is_utf8( $got->{foo}->[2] ), '{foo}->[2] is utf8' );
43 is_deeply($got, $expected, 'nested params' );
44}
45
46{
47 my ($res, $c) = ctx_request("/?foo.1=bar&foo.2=$escape_str&bar.baz=$escape_str&baz.bar.foo=$escape_str&&arr.0.1=$escape_str");
48
49 my $got = $c->request->parameters;
50 my $expected = {
51 'foo.1' => 'bar',
52 'foo.2' => $decode_str,
53 'bar.baz' => $decode_str,
54 'baz.bar.foo' => $decode_str,
55 'arr.0.1' => $decode_str,
56 'arr' => [ [undef, $decode_str] ],
57 'foo' => [undef, 'bar', $decode_str],
58 'bar' => { baz => $decode_str },
59 'baz' => { bar => { foo => $decode_str } },
60 };
61
62 is( ref $got->{arr}->[0], 'ARRAY', '{arr}->[0] is ARRAY' );
63 ok( utf8::is_utf8( $got->{arr}->[0]->[1] ), '{arr}->[0]->[1] is utf8' );
64 ok( utf8::is_utf8( $got->{bar}{baz} ), '{bar}{baz} is utf8' );
65 ok( utf8::is_utf8( $got->{baz}{bar}{foo} ), '{baz}{bar}{foo} is utf8' );
66 is_deeply($got, $expected, 'nested params' );
67}
68
69done_testing();