make this work with cat 5.90080+
John Napiorkowski [Fri, 26 Dec 2014 21:30:29 +0000 (15:30 -0600)]
t/lib/Catty/Controller/Root.pm
t/lib/ExternalCatty/Controller/Root.pm
t/utf8.t [new file with mode: 0644]

index 17498fd..735b1d0 100644 (file)
@@ -24,6 +24,10 @@ sub hello : Global {
     my $html = html( "Hello", "Hi there! $str" );
     $context->response->content_type("text/html; charset=utf-8");
     $context->response->output($html);
+
+    # Newer Catalyst auto encodes UTF8, but this test case is borked and expects
+    # broken utf8 behavior.  We'll make a real UTF8 Test case separately.
+    $context->clear_encoding if $context->can('clear_encoding'); # Compat with upcoming Catalyst 5.90080
 }
 
 # absolute redirect
index 0409a7a..83696fe 100644 (file)
@@ -10,6 +10,10 @@ sub default : Private {
     my ( $self, $c ) = @_;
     $c->response->content_type('text/html; charset=utf-8');
     $c->response->output( html( 'Root', 'Hello, test ☺!' ) );
+
+    # Newer Catalyst auto encodes UTF8, but this test case is borked and expects
+    # broken utf8 behavior.  We'll make a real UTF8 Test case separately.
+    $c->clear_encoding if $c->can('clear_encoding'); # Compat with upcoming Catalyst 5.90080
 }
 
 # redirect to a redirect
diff --git a/t/utf8.t b/t/utf8.t
new file mode 100644 (file)
index 0000000..08ddd2c
--- /dev/null
+++ b/t/utf8.t
@@ -0,0 +1,40 @@
+use utf8;
+use warnings;
+use strict;
+use Test::More;
+use Encode 2.21 'decode_utf8', 'encode_utf8';
+use lib 't/lib';
+
+{
+  package MyApp::Controller::Root;
+  $INC{'MyApp/Controller/Root.pm'} = __FILE__;
+
+  use base 'Catalyst::Controller';
+
+  sub heart :Path('♥') {
+    my ($self, $c) = @_;
+    $c->response->content_type('text/html');
+    $c->response->body("<p>This is path-heart action ♥</p>");
+  }
+
+  package MyApp;
+  use Catalyst;
+
+  MyApp->setup;
+}
+
+use Test::WWW::Mechanize::Catalyst 'MyApp';
+
+my $root = "http://localhost";
+my $m = Test::WWW::Mechanize::Catalyst->new( autocheck => 0 );
+
+if(MyApp->can('encoding') and MyApp->can('clear_encoding') and MyApp->encoding eq 'UTF-8') {
+  $m->get_ok("$root/root/♥", 'got page');
+  is( $m->ct, "text/html" );
+  $m->content_contains("This is path-heart action ♥", 'matched expected content');
+} else {
+  ok 1, 'Skipping the UTF8 Tests for older installed catalyst';
+}
+
+done_testing;
+