even this change is appreciated.
[catagits/Catalyst-Runtime.git] / t / psgi_utils.t
index 9c05559..923defb 100644 (file)
@@ -43,6 +43,40 @@ my $psgi_app = sub {
       $psgi_app->($env));
   }
 
+  sub filehandle :Local {
+    my ($self, $c, $arg) = @_;
+    my $path = File::Spec->catfile('t', 'utf8.txt');
+    open(my $fh, '<', $path) || die "trouble: $!";
+    $c->res->from_psgi_response([200, ['Content-Type'=>'text/html'], $fh]);
+  }
+
+  sub direct :Local {
+    my ($self, $c, $arg) = @_;
+    $c->res->from_psgi_response([200, ['Content-Type'=>'text/html'], ["hello","world"]]);
+  }
+
+  sub streaming_body :Local {
+    my ($self, $c) = @_;
+    my $psgi_app = sub {
+        my $respond = shift;
+        my $writer = $respond->([200,["Content-Type" => "text/plain"]]);
+        $writer->write("body");
+        $writer->close;
+    };
+    $c->res->from_psgi_response($psgi_app);
+  }
+  sub streaming_body_with_charset :Local {
+    my ($self, $c) = @_;
+    my $psgi_app = sub {
+        my $respond = shift;
+        my $writer = $respond->([200,["Content-Type" => "text/plain; charset=utf-8"]]);
+        $writer->write("body");
+        $writer->close;
+    };
+    $c->clear_encoding;
+    $c->res->from_psgi_response($psgi_app);
+  }
+
   package MyApp::Controller::User;
   $INC{'MyApp/Controller/User.pm'} = __FILE__;
 
@@ -110,7 +144,7 @@ my $psgi_app = sub {
     $c->res->body("$uri");
   }
 
-  
+
   sub get_env {
     my ($self, $c) = @_;
     if($c->req->query_parameters->{path_prefix}) {
@@ -243,7 +277,7 @@ use Catalyst::Test 'MyApp';
 
 # END [/user/local_example_args1/***/]
 
-# BEGIN [/user/path-example] 
+# BEGIN [/user/path-example]
 
 {
   my ($res, $c) = ctx_request('/user/path-example');
@@ -383,4 +417,25 @@ use Catalyst::Test 'MyApp';
   is_deeply $c->req->args, [111];
 }
 
+{
+  use utf8;
+  use Encode;
+  my ($res, $c) = ctx_request('/docs/filehandle');
+  is Encode::decode_utf8($res->content), "<p>This is stream_body_fh action ♥</p>\n";
+}
+
+{
+  my ($res, $c) = ctx_request('/docs/direct');
+  is $res->content, "helloworld";
+}
+
+{
+  my ($res, $c) = ctx_request('/docs/streaming_body');
+  is $res->content, "body";
+}
+{
+  my ($res, $c) = ctx_request('/docs/streaming_body_with_charset');
+  is $res->content, "body";
+}
+
 done_testing();