fix unicode in chain and path parts + debug console
[catagits/Catalyst-Runtime.git] / t / utf_incoming.t
1 use utf8;
2 use warnings;
3 use strict;
4 use Test::More;
5
6 # Test cases for incoming utf8 
7
8 {
9   package MyApp::Controller::Root;
10   $INC{'MyApp/Controller/Root.pm'} = __FILE__;
11
12   use base 'Catalyst::Controller';
13
14   sub heart :Path('♥') {
15     my ($self, $c) = @_;
16     $c->response->content_type('text/html');
17     $c->response->body("<p>This is path-heart action ♥</p>");
18     # We let the content length middleware find the length...
19   }
20
21   sub hat :Path('^') {
22     my ($self, $c) = @_;
23     $c->response->content_type('text/html');
24     $c->response->body("<p>This is path-hat action ^</p>");
25   }
26
27   sub base :Chained('/') CaptureArgs(0) { }
28     sub link :Chained('base') PathPart('♥') Args(0) {
29       my ($self, $c) = @_;
30       $c->response->content_type('text/html');
31       $c->response->body("<p>This is base-link action ♥</p>");
32     }
33
34   package MyApp;
35   use Catalyst;
36
37   MyApp->config(encoding=>'UTF-8');
38
39   Test::More::ok(MyApp->setup, 'setup app');
40 }
41
42 ok my $psgi = MyApp->psgi_app, 'build psgi app';
43
44 use Catalyst::Test 'MyApp';
45 use Encode 2.21 'decode_utf8';
46
47 {
48   my $res = request "/root/♥";
49
50   is $res->code, 200, 'OK';
51   is decode_utf8($res->content), '<p>This is path-heart action ♥</p>', 'correct body';
52   is $res->content_length, 36, 'correct length';
53 }
54
55 {
56   my $res = request "/root/^";
57
58   is $res->code, 200, 'OK';
59   is decode_utf8($res->content), '<p>This is path-hat action ^</p>', 'correct body';
60   is $res->content_length, 32, 'correct length';
61 }
62
63 {
64   my $res = request "/base/♥";
65
66   is $res->code, 200, 'OK';
67   is decode_utf8($res->content), '<p>This is base-link action ♥</p>', 'correct body';
68   is $res->content_length, 35, 'correct length';
69 }
70
71 {
72   my $res = request "/base/♥?♥=♥♥";
73
74   is $res->code, 200, 'OK';
75   is decode_utf8($res->content), '<p>This is base-link action ♥</p>', 'correct body';
76   is $res->content_length, 35, 'correct length';
77 }
78
79
80 done_testing;