Merge branch 'topic/debug_warnings'
[catagits/Catalyst-Runtime.git] / t / utf_incoming.t
index 2adccb4..21683cf 100644 (file)
@@ -139,6 +139,26 @@ use Scalar::Util ();
     $c->response->body($decoded_text);
   }
 
+  sub file_upload_utf8_param :POST  Consumes(Multipart) Local {
+    my ($self, $c) = @_;
+
+    Test::More::is $c->req->body_parameters->{'♥'}, '♥♥';
+    Test::More::ok my $upload = $c->req->uploads->{'♥'};
+    Test::More::is $upload->charset, 'UTF-8';
+
+    my $text = $upload->slurp;
+    Test::More::is Encode::decode_utf8($text), "<p>This is stream_body_fh action ♥</p>\n";
+
+    my $decoded_text = $upload->decoded_slurp;
+    Test::More::is $decoded_text, "<p>This is stream_body_fh action ♥</p>\n";
+
+    Test::More::is $upload->filename, '♥ttachment.txt';
+    Test::More::is $upload->raw_basename, '♥ttachment.txt';
+
+    $c->response->content_type('text/html');
+    $c->response->body($decoded_text);
+  }
+
   sub json :POST Consumes(JSON) Local {
     my ($self, $c) = @_;
     my $post = $c->req->body_data;
@@ -323,7 +343,7 @@ use Catalyst::Test 'MyApp';
   is $res->code, 200, 'OK';
   is decode_utf8($res->content), "$url", 'correct body'; #should do nothing
   is $res->content, "$url", 'correct body';
-  is $res->content_length, 102, 'correct length';
+  is $res->content_length, 104, 'correct length';
   is $res->content_charset, 'UTF-8';
 
   {
@@ -392,6 +412,16 @@ use Catalyst::Test 'MyApp';
 }
 
 {
+  ok my $path = File::Spec->catfile('t', 'utf8.txt');
+  ok my $req = POST '/root/file_upload_utf8_param',
+    Content_Type => 'form-data',
+    Content =>  [encode_utf8('♥')=>encode_utf8('♥♥'), encode_utf8('♥')=>["$path", encode_utf8('♥ttachment.txt'), 'Content-Type' =>'text/html; charset=UTF-8', ]];
+
+  ok my $res = request $req;
+  is decode_utf8($res->content), "<p>This is stream_body_fh action ♥</p>\n";
+}
+
+{
   ok my $req = POST '/root/json',
      Content_Type => 'application/json',
      Content => encode_json +{'♥'=>'♥♥'}; # Note: JSON does the UTF* encoding for us