]> granicus.if.org Git - php/commitdiff
Testing variation on input parameters of http_build_query() function
authorAdam Gegotek <a.gegotek@ocom.com>
Sat, 23 Jun 2012 12:58:58 +0000 (14:58 +0200)
committerStanislav Malyshev <stas@php.net>
Sun, 15 Jul 2012 01:58:52 +0000 (18:58 -0700)
ext/standard/tests/strings/http_build_query_variation1.phpt [new file with mode: 0644]
ext/standard/tests/strings/http_build_query_variation2.phpt [new file with mode: 0644]
ext/standard/tests/strings/http_build_query_variation3.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/strings/http_build_query_variation1.phpt b/ext/standard/tests/strings/http_build_query_variation1.phpt
new file mode 100644 (file)
index 0000000..56d81c9
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Test http_build_query() function: usage variations - first arguments as object 
+--CREDITS--
+Adam Gegotek <adam [dot] gegotek [at] gmail [dot] com>
+--FILE--
+<?php
+/* Prototype  : string http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )
+ * Description: Generates a URL-encoded query string from the associative (or indexed) array provided. 
+ * Source code: ext/standard/http.c
+*/
+
+class UrlBuilder
+{
+  public $name = 'homepage';
+  public $page = 1;
+  protected $sort = 'desc,name';
+  private $access = 'admin';
+}
+
+$obj = new stdClass;
+$obj->name = 'homepage';
+$obj->page = 1;
+$obj->sort = 'desc,name';
+
+echo http_build_query($obj) . PHP_EOL;
+echo http_build_query(new UrlBuilder());
+?>
+--EXPECTF--
+name=homepage&page=1&sort=desc%2Cname
+name=homepage&page=1
diff --git a/ext/standard/tests/strings/http_build_query_variation2.phpt b/ext/standard/tests/strings/http_build_query_variation2.phpt
new file mode 100644 (file)
index 0000000..ca1d8f4
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+Test http_build_query() function: usage variations - first arguments as multidimensional array and second argument present/not present
+--CREDITS--
+Adam Gegotek <adam [dot] gegotek [at] gmail [dot] com>
+--FILE--
+<?php
+/* Prototype  : string http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )
+ * Description: Generates a URL-encoded query string from the associative (or indexed) array provided. 
+ * Source code: ext/standard/http.c
+*/
+
+$mDimensional = array(
+  20, 
+  5 => 13, 
+  "9" => array(
+    1 => "val1", 
+    3 => "val2", 
+    "string" => "string"
+  ),
+  "name" => "homepage", 
+  "page" => 10,
+  "sort" => array(
+    "desc", 
+    "admin" => array(
+      "admin1", 
+      "admin2" => array(
+        "who" => "admin2", 
+        2 => "test"
+      )
+    )
+  )
+);
+
+echo http_build_query($mDimensional) . PHP_EOL;
+echo http_build_query($mDimensional, 'prefix_');
+?>
+--EXPECTF--
+0=20&5=13&9%5B1%5D=val1&9%5B3%5D=val2&9%5Bstring%5D=string&name=homepage&page=10&sort%5B0%5D=desc&sort%5Badmin%5D%5B0%5D=admin1&sort%5Badmin%5D%5Badmin2%5D%5Bwho%5D=admin2&sort%5Badmin%5D%5Badmin2%5D%5B2%5D=test
+prefix_0=20&prefix_5=13&prefix_9%5B1%5D=val1&prefix_9%5B3%5D=val2&prefix_9%5Bstring%5D=string&name=homepage&page=10&sort%5B0%5D=desc&sort%5Badmin%5D%5B0%5D=admin1&sort%5Badmin%5D%5Badmin2%5D%5Bwho%5D=admin2&sort%5Badmin%5D%5Badmin2%5D%5B2%5D=test
diff --git a/ext/standard/tests/strings/http_build_query_variation3.phpt b/ext/standard/tests/strings/http_build_query_variation3.phpt
new file mode 100644 (file)
index 0000000..8cd616b
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Test http_build_query() function: usage variations - testing four parameter added in PHP 5.4.0
+--CREDITS--
+Adam Gegotek <adam [dot] gegotek [at] gmail [dot] com>
+--SKIPIF--
+<?php 
+  if (version_compare(PHP_VERSION, '5.4.0', '<')) die("skip this test if PHP_VERSION is less than 5.4.0");
+?>
+--FILE--
+<?php
+/* Prototype  : string http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )
+ * Description: Generates a URL-encoded query string from the associative (or indexed) array provided. 
+ * Source code: ext/standard/http.c
+*/
+
+$oDimensional = array(
+  "name" => "main page",
+  "sort" => "desc,admin",
+  "equation" => "10 + 10 - 5"
+);
+
+echo http_build_query($oDimensional, '', ini_get('arg_separator.output'), PHP_QUERY_RFC1738) . PHP_EOL;
+echo http_build_query($oDimensional, '', ini_get('arg_separator.output'), PHP_QUERY_RFC3986);
+--EXPECTF--
+name=main+page&sort=desc%2Cadmin&equation=10+%2B+10+-+5
+name=main%20page&sort=desc%2Cadmin&equation=10%20%2B%2010%20-%205