- fix resetting post fields
authorMichael Wallner <mike@php.net>
Thu, 22 Dec 2005 19:07:36 +0000 (19:07 +0000)
committerMichael Wallner <mike@php.net>
Thu, 22 Dec 2005 19:07:36 +0000 (19:07 +0000)
- add test

http_request_object.c
tests/HttpRequest_004.phpt [new file with mode: 0644]

index 6b0d6b076bcefdb1db4504a07c7fd3d3e09085c6..bf271105162e66c6c2e5f4fe717977bf0740bb3a 100644 (file)
@@ -1196,7 +1196,7 @@ PHP_METHOD(HttpRequest, setPostFields)
 
        MAKE_STD_ZVAL(post);
        array_init(post);
-       if (post_data && (Z_TYPE_P(post_data) == IS_ARRAY)) {
+       if (post_data && zend_hash_num_elements(Z_ARRVAL_P(post_data))) {
                array_copy(post_data, post);
        }
        SET_PROP(obj, postFields, post);
diff --git a/tests/HttpRequest_004.phpt b/tests/HttpRequest_004.phpt
new file mode 100644 (file)
index 0000000..f6094bb
--- /dev/null
@@ -0,0 +1,166 @@
+--TEST--
+HttpRequest multiple posts
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkcls('HttpRequest');
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+$fields = array(
+       array('int' => 1, 'dbl' => M_PI),
+       array('str' => 'something', 'nil' => null)
+);
+
+echo "\nFirst Request\n";
+$r = new HttpRequest('http://dev.iworks.at/.print_request.php', HttpRequest::METH_POST);
+$r->setPostFields($fields[0]);
+$r->addPostFields($fields[1]);
+var_dump($r->send()->getBody());
+var_dump($fields);
+
+echo "\nSecond Request\n";
+$r->setPostFields($fields);
+var_dump($r->send()->getBody());
+var_dump($fields);
+
+echo "\nThird Request\n";
+$r->addPostFields(array('x' => 'X'));
+var_dump($r->send()->getBody());
+var_dump($fields);
+
+echo "\nFourth Request\n";
+$r->setPostFields(array());
+var_dump($r->send()->getBody());
+var_dump($fields);
+
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+
+First Request
+string(150) "Array
+(
+    [int] => 1
+    [dbl] => 3.1415926535898
+    [str] => something
+    [nil] => 
+)
+string(44) "int=1&dbl=3.1415926535898&str=something&nil="
+
+"
+array(2) {
+  [0]=>
+  array(2) {
+    ["int"]=>
+    int(1)
+    ["dbl"]=>
+    float(3.1415926535898)
+  }
+  [1]=>
+  array(2) {
+    ["str"]=>
+    string(9) "something"
+    ["nil"]=>
+    NULL
+  }
+}
+
+Second Request
+string(270) "Array
+(
+    [0] => Array
+        (
+            [int] => 1
+            [dbl] => 3.1415926535898
+        )
+
+    [1] => Array
+        (
+            [str] => something
+            [nil] => 
+        )
+
+)
+string(56) "0[int]=1&0[dbl]=3.1415926535898&1[str]=something&1[nil]="
+
+"
+array(2) {
+  [0]=>
+  array(2) {
+    ["int"]=>
+    int(1)
+    ["dbl"]=>
+    float(3.1415926535898)
+  }
+  [1]=>
+  array(2) {
+    ["str"]=>
+    string(9) "something"
+    ["nil"]=>
+    NULL
+  }
+}
+
+Third Request
+string(287) "Array
+(
+    [0] => Array
+        (
+            [int] => 1
+            [dbl] => 3.1415926535898
+        )
+
+    [1] => Array
+        (
+            [str] => something
+            [nil] => 
+        )
+
+    [x] => X
+)
+string(60) "0[int]=1&0[dbl]=3.1415926535898&1[str]=something&1[nil]=&x=X"
+
+"
+array(2) {
+  [0]=>
+  array(2) {
+    ["int"]=>
+    int(1)
+    ["dbl"]=>
+    float(3.1415926535898)
+  }
+  [1]=>
+  array(2) {
+    ["str"]=>
+    string(9) "something"
+    ["nil"]=>
+    NULL
+  }
+}
+
+Fourth Request
+string(14) "string(0) ""
+
+"
+array(2) {
+  [0]=>
+  array(2) {
+    ["int"]=>
+    int(1)
+    ["dbl"]=>
+    float(3.1415926535898)
+  }
+  [1]=>
+  array(2) {
+    ["str"]=>
+    string(9) "something"
+    ["nil"]=>
+    NULL
+  }
+}
+Done
+