Added XXX-results.yml
Christian Hansen [Sun, 4 Sep 2005 12:55:56 +0000 (12:55 +0000)]
14 files changed:
lib/HTTP/Body.pm
t/01use.t
t/data/multipart/001-results.yml [new file with mode: 0644]
t/data/multipart/002-results.yml [new file with mode: 0644]
t/data/multipart/003-results.yml [new file with mode: 0644]
t/data/multipart/004-results.yml [new file with mode: 0644]
t/data/multipart/005-results.yml [new file with mode: 0644]
t/data/multipart/006-results.yml [new file with mode: 0644]
t/data/multipart/007-results.yml [new file with mode: 0644]
t/data/multipart/008-results.yml [new file with mode: 0644]
t/data/multipart/009-results.yml [new file with mode: 0644]
t/data/multipart/010-results.yml [new file with mode: 0644]
t/data/multipart/011-results.yml [new file with mode: 0644]
t/data/urlencoded/001-results.yml [new file with mode: 0644]

index 083d6be..2e7000a 100644 (file)
@@ -49,7 +49,7 @@ sub new {
 
     my $self = {
         buffer         => '',
-        body           => '',
+        body           => undef,
         content_length => $content_length,
         content_type   => $content_type,
         length         => 0,
index 6072013..0fc29fe 100644 (file)
--- a/t/01use.t
+++ b/t/01use.t
@@ -8,23 +8,24 @@ use Path::Class;
 use Data::Dumper;
 
 for my $format (qw/multipart urlencoded/) {
+
     for my $match ( glob file( $FindBin::Bin, 'data', $format, '*.dat' ) ) {
         my $file = file($match);
         my $name = $file->basename;
         $name =~ /^(\d+)-.*/;
         my $num     = $1;
-        my $headers =
-          LoadFile(
-            file( $FindBin::Bin, 'data', $format, "$num-headers.yml" ) );
+        my $headers = LoadFile( file( $FindBin::Bin, 'data', $format, "$num-headers.yml" ) );
+        my $results = LoadFile( file( $FindBin::Bin, 'data', $format, "$num-results.yml" ) );
         my $content = $file->open('<');
-        my $body    = HTTP::Body->new( $headers->{'Content-Type'},
-            $headers->{'Content-Length'} );
-        binmode $content;
+        my $body    = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
+
+        binmode $content, ':raw';
 
         while ( $content->read( my $buffer, 1024 ) ) {
             $body->add($buffer);
         }
-        if ( $ENV{HTTP_Body_Debug} ) {
+
+        if ( $ENV{HTTP_BODY_DEBUG} ) {
             warn Dumper( $body->param );
             warn Dumper( $body->upload );
             warn Dumper( $body->body );
@@ -35,7 +36,20 @@ for my $format (qw/multipart urlencoded/) {
             warn "body length    : " . ( $body->body->stat )[7] if $body->body;
             warn "buffer         : " . $body->buffer if $body->buffer;
         }
-        ok( $body->state eq 'done' );
+        
+        for my $field ( keys %{ $body->upload } ) {
+
+            my $value = $body->upload->{$field};
+
+            for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) {
+                delete $_->{tempname};
+            }
+        }
+
+        is_deeply( $body->body, $results->{body}, "$num-$format body" );
+        is_deeply( $body->param, $results->{param}, "$num-$format param" );
+        is_deeply( $body->upload, $results->{upload}, "$num-$format upload" );
+        ok( $body->state eq 'done', "$num-$format state" );
     }
 }
 
diff --git a/t/data/multipart/001-results.yml b/t/data/multipart/001-results.yml
new file mode 100644 (file)
index 0000000..bd2e318
--- /dev/null
@@ -0,0 +1,29 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+upload:
+  upload:
+    - filename: hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="hello.pl"
+        Content-Type: application/octet-stream
+      name: upload
+      size: 71
+    - filename: hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="hello.pl"
+        Content-Type: application/octet-stream
+      name: upload
+      size: 71
+  upload2:
+    filename: hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="hello.pl"
+      Content-Type: application/octet-stream
+    name: upload2
+    size: 71
diff --git a/t/data/multipart/002-results.yml b/t/data/multipart/002-results.yml
new file mode 100644 (file)
index 0000000..580d006
--- /dev/null
@@ -0,0 +1,29 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa.\r\n"
+upload:
+  upload:
+    - filename: /Users/chansen/hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="/Users/chansen/hello.pl"
+        Content-Type: text/plain
+      name: upload
+      size: 71
+    - filename: /Users/chansen/hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="/Users/chansen/hello.pl"
+        Content-Type: text/plain
+      name: upload
+      size: 71
+  upload2:
+    filename: /Users/chansen/hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="/Users/chansen/hello.pl"
+      Content-Type: text/plain
+    name: upload2
+    size: 71
diff --git a/t/data/multipart/003-results.yml b/t/data/multipart/003-results.yml
new file mode 100644 (file)
index 0000000..f92a61c
--- /dev/null
@@ -0,0 +1,29 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: |-
+    Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.
+    
+    Molestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa.
+upload:
+  upload:
+    - filename: hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="hello.pl"
+      name: upload
+      size: 71
+    - filename: hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="hello.pl"
+      name: upload
+      size: 71
+  upload2:
+    filename: hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="hello.pl"
+    name: upload2
+    size: 71
diff --git a/t/data/multipart/004-results.yml b/t/data/multipart/004-results.yml
new file mode 100644 (file)
index 0000000..bd2e318
--- /dev/null
@@ -0,0 +1,29 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+upload:
+  upload:
+    - filename: hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="hello.pl"
+        Content-Type: application/octet-stream
+      name: upload
+      size: 71
+    - filename: hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="hello.pl"
+        Content-Type: application/octet-stream
+      name: upload
+      size: 71
+  upload2:
+    filename: hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="hello.pl"
+      Content-Type: application/octet-stream
+    name: upload2
+    size: 71
diff --git a/t/data/multipart/005-results.yml b/t/data/multipart/005-results.yml
new file mode 100644 (file)
index 0000000..701fe33
--- /dev/null
@@ -0,0 +1,29 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+upload:
+  upload:
+    - filename: hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="hello.pl"
+        Content-Type: text/plain
+      name: upload
+      size: 71
+    - filename: hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="hello.pl"
+        Content-Type: text/plain
+      name: upload
+      size: 71
+  upload2:
+    filename: hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="hello.pl"
+      Content-Type: text/plain
+    name: upload2
+    size: 71
diff --git a/t/data/multipart/006-results.yml b/t/data/multipart/006-results.yml
new file mode 100644 (file)
index 0000000..bd39105
--- /dev/null
@@ -0,0 +1,29 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+upload:
+  upload:
+    - filename: C:\WINDOWS\Skrivbord\hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="C:\WINDOWS\Skrivbord\hello.pl"
+        Content-Type: text/plain
+      name: upload
+      size: 71
+    - filename: C:\WINDOWS\Skrivbord\hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="C:\WINDOWS\Skrivbord\hello.pl"
+        Content-Type: text/plain
+      name: upload
+      size: 71
+  upload2:
+    filename: C:\WINDOWS\Skrivbord\hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="C:\WINDOWS\Skrivbord\hello.pl"
+      Content-Type: text/plain
+    name: upload2
+    size: 71
diff --git a/t/data/multipart/007-results.yml b/t/data/multipart/007-results.yml
new file mode 100644 (file)
index 0000000..bd2e318
--- /dev/null
@@ -0,0 +1,29 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+upload:
+  upload:
+    - filename: hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="hello.pl"
+        Content-Type: application/octet-stream
+      name: upload
+      size: 71
+    - filename: hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="hello.pl"
+        Content-Type: application/octet-stream
+      name: upload
+      size: 71
+  upload2:
+    filename: hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="hello.pl"
+      Content-Type: application/octet-stream
+    name: upload2
+    size: 71
diff --git a/t/data/multipart/008-results.yml b/t/data/multipart/008-results.yml
new file mode 100644 (file)
index 0000000..bd39105
--- /dev/null
@@ -0,0 +1,29 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+upload:
+  upload:
+    - filename: C:\WINDOWS\Skrivbord\hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="C:\WINDOWS\Skrivbord\hello.pl"
+        Content-Type: text/plain
+      name: upload
+      size: 71
+    - filename: C:\WINDOWS\Skrivbord\hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="C:\WINDOWS\Skrivbord\hello.pl"
+        Content-Type: text/plain
+      name: upload
+      size: 71
+  upload2:
+    filename: C:\WINDOWS\Skrivbord\hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="C:\WINDOWS\Skrivbord\hello.pl"
+      Content-Type: text/plain
+    name: upload2
+    size: 71
diff --git a/t/data/multipart/009-results.yml b/t/data/multipart/009-results.yml
new file mode 100644 (file)
index 0000000..33d5ecd
--- /dev/null
@@ -0,0 +1,29 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+upload:
+  upload:
+    - filename: C:\Documents and Settings\Administrator\Desktop\hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="C:\Documents and Settings\Administrator\Desktop\hello.pl"
+        Content-Type: text/plain
+      name: upload
+      size: 71
+    - filename: C:\Documents and Settings\Administrator\Desktop\hello.pl
+      headers:
+        Content-Disposition: form-data; name="upload"; filename="C:\Documents and Settings\Administrator\Desktop\hello.pl"
+        Content-Type: text/plain
+      name: upload
+      size: 71
+  upload2:
+    filename: C:\Documents and Settings\Administrator\Desktop\hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="C:\Documents and Settings\Administrator\Desktop\hello.pl"
+      Content-Type: text/plain
+    name: upload2
+    size: 71
diff --git a/t/data/multipart/010-results.yml b/t/data/multipart/010-results.yml
new file mode 100644 (file)
index 0000000..8e8552c
--- /dev/null
@@ -0,0 +1,30 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+upload:
+  upload:
+    filename: C:\Documents and Settings\Administrator\Desktop\hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload"; filename="C:\Documents and Settings\Administrator\Desktop\hello.pl"
+      Content-Type: text/plain
+    name: upload
+    size: 71
+  upload1:
+    filename: C:\Documents and Settings\Administrator\Desktop\hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload1"; filename="C:\Documents and Settings\Administrator\Desktop\hello.pl"
+      Content-Type: text/plain
+    name: upload1
+    size: 71
+  upload2:
+    filename: C:\Documents and Settings\Administrator\Desktop\hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="C:\Documents and Settings\Administrator\Desktop\hello.pl"
+      Content-Type: text/plain
+    name: upload2
+    size: 71
diff --git a/t/data/multipart/011-results.yml b/t/data/multipart/011-results.yml
new file mode 100644 (file)
index 0000000..8e8552c
--- /dev/null
@@ -0,0 +1,30 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+upload:
+  upload:
+    filename: C:\Documents and Settings\Administrator\Desktop\hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload"; filename="C:\Documents and Settings\Administrator\Desktop\hello.pl"
+      Content-Type: text/plain
+    name: upload
+    size: 71
+  upload1:
+    filename: C:\Documents and Settings\Administrator\Desktop\hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload1"; filename="C:\Documents and Settings\Administrator\Desktop\hello.pl"
+      Content-Type: text/plain
+    name: upload1
+    size: 71
+  upload2:
+    filename: C:\Documents and Settings\Administrator\Desktop\hello.pl
+    headers:
+      Content-Disposition: form-data; name="upload2"; filename="C:\Documents and Settings\Administrator\Desktop\hello.pl"
+      Content-Type: text/plain
+    name: upload2
+    size: 71
diff --git a/t/data/urlencoded/001-results.yml b/t/data/urlencoded/001-results.yml
new file mode 100644 (file)
index 0000000..430caf3
--- /dev/null
@@ -0,0 +1,10 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  text2: åäöåäö
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+upload: {}