use inlined module hiding in tests
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_uri_for_multibytechar.t
1 use utf8;
2 use strict;
3 use warnings;
4 use FindBin;
5 use lib "$FindBin::Bin/../lib";
6
7 use Test::More;
8
9 use_ok('TestApp');
10
11 my $base = 'http://127.0.0.1';
12
13 my $request = Catalyst::Request->new({
14     _log => Catalyst::Log->new,
15     base => URI->new($base),
16     uri  => URI->new("$base/"),
17 });
18
19 my $context = TestApp->new({
20     request => $request,
21 });
22
23
24 my $uri_with_multibyte = URI->new($base);
25 $uri_with_multibyte->path('/');
26 $uri_with_multibyte->query_form(
27     name => '村瀬大輔',
28 );
29
30 # multibyte with utf8 bytes
31 is($context->uri_for('/', { name => '村瀬大輔' }), $uri_with_multibyte, 'uri_for with utf8 bytes query');
32 is($context->req->uri_with({ name => '村瀬大輔' }), $uri_with_multibyte, 'uri_with with utf8 bytes query');
33
34 # multibyte with utf8 string
35 is($context->uri_for('/', { name => "\x{6751}\x{702c}\x{5927}\x{8f14}" }), $uri_with_multibyte, 'uri_for with utf8 string query');
36 is($context->req->uri_with({ name => "\x{6751}\x{702c}\x{5927}\x{8f14}" }), $uri_with_multibyte, 'uri_with with utf8 string query');
37
38 # multibyte captures and args
39 my $action = $context->controller('Action::Chained')
40     ->action_for('roundtrip_urifor_end');
41
42 is($context->uri_for($action, ['hütte'], 'hütte', {
43     test => 'hütte'
44 }),
45 'http://127.0.0.1/chained/roundtrip_urifor/h%C3%BCtte/h%C3%BCtte?test=h%C3%BCtte',
46 'uri_for with utf8 captures and args');
47
48 is(
49   $context->uri_for($action, ['♥'], '♥', { '♥' => '♥'}),
50   'http://127.0.0.1/chained/roundtrip_urifor/' . '%E2%99%A5' . '/' . '%E2%99%A5' . '?' . '%E2%99%A5' . '=' . '%E2%99%A5',
51     'uri_for with utf8 captures and args');
52
53 # ^ the match string is purposefully broken up to aid viewing, please to 'fix' it.
54
55 done_testing;