Skip to content

Submitting test from testFest #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions ext/standard/tests/strings/http_build_query_variation1.phpt
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions ext/standard/tests/strings/http_build_query_variation2.phpt
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions ext/standard/tests/strings/http_build_query_variation3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--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