Unicode - fix decoding process for uploads
[catagits/Catalyst-Runtime.git] / t / unicode_plugin_no_encoding.t
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use utf8;
7
8 # setup library path
9 use FindBin qw($Bin);
10 use lib "$Bin/lib";
11
12 use Catalyst::Test 'TestAppWithoutUnicode';
13 use Encode;
14 use HTTP::Request::Common;
15 use URI::Escape qw/uri_escape_utf8/;
16 use HTTP::Status 'is_server_error';
17
18 my $encode_str = "\x{e3}\x{81}\x{82}"; # e38182 is japanese 'あ'
19 my $decode_str = Encode::decode('utf-8' => $encode_str);
20 my $escape_str = uri_escape_utf8($decode_str);
21
22 check_parameter(GET "/?myparam=$escape_str");
23 check_parameter(POST '/',
24     Content_Type => 'form-data',
25     Content => [
26         'myparam' => [
27             "$Bin/unicode_plugin_no_encoding.t",
28             "$Bin/unicode_plugin_request_decode.t",
29         ]
30     ],
31 );
32
33 sub check_parameter {
34     my ( undef, $c ) = ctx_request(shift);
35
36     my $myparam = $c->req->param('myparam');
37     ok !utf8::is_utf8($myparam);
38     unless ( $c->request->method eq 'POST' ) {
39         is $c->res->output => $encode_str;
40         is $myparam => $encode_str;
41     }
42
43     is scalar(@TestLogger::ELOGS), 2
44         or diag Dumper(\@TestLogger::ELOGS);
45     like $TestLogger::ELOGS[0], qr/method \"decode\"/;
46 }
47
48 done_testing;