update for newer catalyst unicode changes
[catagits/Catalyst-View-TT.git] / t / utf8.t
diff --git a/t/utf8.t b/t/utf8.t
new file mode 100644 (file)
index 0000000..628a7e6
--- /dev/null
+++ b/t/utf8.t
@@ -0,0 +1,49 @@
+use utf8;
+use warnings;
+use strict;
+use Test::More;
+use Encode 2.21 'decode_utf8', 'encode_utf8';
+use HTTP::Request::Common;
+use File::Spec;
+
+{
+  package MyApp::Controller::Root;
+  $INC{'MyApp/Controller/Root.pm'} = __FILE__;
+
+  use base 'Catalyst::Controller';
+
+  sub heart :Path('♥') {
+    my ($self, $c) = @_;
+    $c->stash(hearts=>'♥♥♥');
+    $c->detach('View::HTML');
+  }
+  package MyApp::View::HTML;
+  $INC{'MyApp/View/HTML.pm'} = __FILE__;
+
+  use base 'Catalyst::View::TT';
+
+  MyApp::View::HTML->config(
+    ENCODING => 'UTF-8',
+    INCLUDE_PATH=> File::Spec->catfile('t'));
+
+  package MyApp;
+  use Catalyst;
+
+  MyApp->setup;
+}
+
+use Catalyst::Test 'MyApp';
+
+if(MyApp->can('encoding') and MyApp->can('clear_encoding') ) {
+  ok my $res = request GET '/root/♥', 'Accept-Encoding' => 'gzip';
+
+  is $res->code, 200, 'OK';
+  
+  is decode_utf8($res->content), "<p>This heart literal ♥</p><p>This is heart var ♥♥♥</p>\n", 'correct body';
+  is $res->content_charset, 'UTF-8';
+} else {
+  ok 1, 'Skipping the UTF8 Tests for older installed catalyst';
+}
+
+done_testing;
+