Updated and expanded test suit
Christian Hansen [Sat, 16 Apr 2005 22:26:58 +0000 (22:26 +0000)]
t/TODO
t/engine/request/body.t
t/engine/request/parameters.t
t/engine/request/uploads.t
t/lib/TestApp.pm

diff --git a/t/TODO b/t/TODO
index 4ecce6f..ab8e998 100644 (file)
--- a/t/TODO
+++ b/t/TODO
@@ -1,3 +1,4 @@
+ [x] /engine/request/body.t
  [x] /engine/request/cookies.t
  [x] /engine/request/headers.t
  [ ] /engine/request/method/get.t
@@ -6,7 +7,7 @@
  [ ] /engine/request/method/post/urlencoded.t
  [x] /engine/request/parameters.t
  [ ] /engine/request/unicode.t
- [~] /engine/request/uploads.t
+ [x] /engine/request/uploads.t
 
  [x] /engine/response/cookies.t
  [x] /engine/response/errors.t
  [ ] /view/subclass.t
  [ ] /view/unicode.t
 
- [ ] /controller/action/absolute.t
- [ ] /controller/action/arguments.t
- [ ] /controller/action/begin.t
- [ ] /controller/action/default.t
- [ ] /controller/action/end.t
- [ ] /controller/action/forward.t
- [ ] /controller/action/inheritance.t
- [ ] /controller/acrion/private.t
- [ ] /controller/action/public.t
- [ ] /controller/action/regexp.t
- [ ] /controller/action/relative.t
+ [ ] /component/controller/action/arguments.t
+ [~] /component/controller/action/begin.t
+ [~] /component/controller/action/default.t
+ [~] /component/controller/action/end.t
+ [~] /component/controller/action/forward.t
+ [~] /component/controller/action/global.t
+ [~] /component/controller/action/inheritance.t
+ [~] /component/controller/action/local.t
+ [~] /component/controller/action/path.t
+ [~] /component/controller/acrion/private.t
+ [ ] /component/controller/action/public.t
+ [~] /component/controller/action/regexp.t
 
  [ ] /plugin/overload/finalize.t
  [ ] /plugin/overload/finalize_output.t
index 03e3b03..3bc28fd 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 use FindBin;
 use lib "$FindBin::Bin/../../lib";
 
-use Test::More tests => 10;
+use Test::More tests => 20;
 use Catalyst::Test 'TestApp';
 
 use Catalyst::Request;
@@ -37,3 +37,28 @@ use HTTP::Request::Common;
     is( $creq->content_length, $request->content_length, 'Catalyst::Request Content-Length' );
     is( $creq->body, $request->content, 'Catalyst::Request Content' );
 }
+
+{
+    my $creq;
+
+    my $request = POST( 'http://localhost/dump/request/',
+        'Content-Type' => 'text/plain',
+        'Content'      => 'x' x 100_000
+    );
+
+    ok( my $response = request($request), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->content_type, 'text/plain', 'Response Content-Type' );
+    like( $response->content, qr/^bless\( .* 'Catalyst::Request' \)$/s, 'Content is a serialized Catalyst::Request' );
+    
+    {
+        no strict 'refs';
+        ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
+    }
+
+    isa_ok( $creq, 'Catalyst::Request' );
+    is( $creq->method, 'POST', 'Catalyst::Request method' );
+    is( $creq->content_type, 'text/plain', 'Catalyst::Request Content-Type' );
+    is( $creq->content_length, $request->content_length, 'Catalyst::Request Content-Length' );
+    is( $creq->body, $request->content, 'Catalyst::Request Content' );
+}
\ No newline at end of file
index 254435b..6cf7da9 100644 (file)
@@ -29,10 +29,11 @@ use URI;
 
     # Query string. I'm not sure the order is consistent in all enviroments,
     # we need to test this with:
-    # [x] C::E::Test and C::E::Daemon
-    # [ ] MP1
-    # [ ] MP2
-    # [x] CGI::Simple
+    # [x] C::E::Test and C::E::HTTP
+    # [x] MP13
+    # [x] MP19
+    # [x] MP20
+    # [x] CGI
 
     unshift( @{ $parameters->{a} }, 1, 2, 3 );
     
index 5e82f84..adb43d2 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 use FindBin;
 use lib "$FindBin::Bin/../../lib";
 
-use Test::More tests => 18;
+use Test::More tests => 39;
 use Catalyst::Test 'TestApp';
 
 use Catalyst::Request;
@@ -55,3 +55,47 @@ use HTTP::Request::Common;
         is( $upload->size, length( $part->content ), 'Upload Content-Length' );
     }
 }
+
+{
+    my $creq;
+
+    my $request = POST( 'http://localhost/dump/request/',
+        'Content-Type' => 'multipart/form-data',
+        'Content'      => [
+            'testfile' => [ "$FindBin::Bin/cookies.t" ],
+            'testfile' => [ "$FindBin::Bin/headers.t" ],
+            'testfile' => [ "$FindBin::Bin/uploads.t" ],
+         ]
+    );
+
+    ok( my $response = request($request), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->content_type, 'text/plain', 'Response Content-Type' ); 
+    like( $response->content, qr/^bless\( .* 'Catalyst::Request' \)$/s, 'Content is a serialized Catalyst::Request' );
+    
+    {
+        no strict 'refs';
+        ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
+    }
+
+    isa_ok( $creq, 'Catalyst::Request' );
+    is( $creq->method, 'POST', 'Catalyst::Request method' );
+    is( $creq->content_type, 'multipart/form-data', 'Catalyst::Request Content-Type' );
+    is( $creq->content_length, $request->content_length, 'Catalyst::Request Content-Length' );
+    
+    my @parts = $request->parts;
+
+    for ( my $i = 0; $i < @parts; $i++ ) {
+    
+        my $part        = $parts[$i];
+        my $disposition = $part->header('Content-Disposition');
+        my %parameters  = @{ ( split_header_words($disposition) )[0] };
+        
+        my $upload = $creq->uploads->{ $parameters{name} }->[$i];
+        
+        isa_ok( $upload, 'Catalyst::Request::Upload' );
+        is( $upload->type, $part->content_type, 'Upload Content-Type' );
+        is( $upload->filename, $parameters{filename}, 'Upload filename' );
+        is( $upload->size, length( $part->content ), 'Upload Content-Length' );
+    }
+}
index acb4a64..c4f1649 100644 (file)
@@ -2,6 +2,7 @@ package TestApp;
 
 use strict;
 use Catalyst qw[Test::Errors Test::Headers];
+use Catalyst::Utils;
 
 our $VERSION = '0.01';
 
@@ -33,10 +34,11 @@ sub execute {
         $method = $1;
     }
 
-    my $executed = sprintf( "%s->%s", $class, $method )
-      if ( $class && $method );
-
-    $c->response->headers->push_header( 'X-Catalyst-Executed' => $executed );
+    if ( $class && $method ) {
+        my $executed = sprintf( "%s->%s", $class, $method );
+        $c->response->headers->push_header( 'X-Catalyst-Executed' => $executed );
+    }
+    
     return $c->SUPER::execute(@_);
 }