svn: /pear/packages/Net_URL2/trunk/ URL2.php tests/URL2Test.php

From: Date: Sun, 13 Mar 2011 03:46:02 +0000
Subject: svn: /pear/packages/Net_URL2/trunk/ URL2.php tests/URL2Test.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-61426@lists.php.net to get a copy of this message
till Sun, 13 Mar 2011 03:46:02 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=309158 Log: * rebuild self::OPTION_USE_BRACKETS * added unit tests demonstrating either behavior * adjusted buildQuery() Changed paths: U pear/packages/Net_URL2/trunk/URL2.php U pear/packages/Net_URL2/trunk/tests/URL2Test.php Modified: pear/packages/Net_URL2/trunk/URL2.php =================================================================== --- pear/packages/Net_URL2/trunk/URL2.php 2011-03-13 03:36:43 UTC (rev 309157) +++ pear/packages/Net_URL2/trunk/URL2.php 2011-03-13 03:46:02 UTC (rev 309158) @@ -897,7 +897,11 @@ $name = rawurlencode($name); } if ($key !== null) { - $name = $key . '[' . $name . ']'; + if ($this->getOption(self::OPTION_USE_BRACKETS) === true) { + $name = $key . '[' . $name . ']'; + } else { + $name = $key; + } } if (is_array($value)) { $query[] = $this->buildQuery($value, $separator, $name); Modified: pear/packages/Net_URL2/trunk/tests/URL2Test.php =================================================================== --- pear/packages/Net_URL2/trunk/tests/URL2Test.php 2011-03-13 03:36:43 UTC (rev 309157) +++ pear/packages/Net_URL2/trunk/tests/URL2Test.php 2011-03-13 03:46:02 UTC (rev 309158) @@ -236,6 +236,29 @@ strval($url) ); } + + public function testUseBrackets() + { + $url = new Net_URL2('http://example.org/'); + $url->setQueryVariables(array('foo' => array('bar', 'foobar'))); + $this->assertEquals( + 'http://example.org/?foo[0]=bar&foo[1]=foobar', + strval($url) + ); + } + + public function testDontUseBrackets() + { + $url = new Net_URL2( + 'http://example.org/', + array(Net_URL2::OPTION_USE_BRACKETS => false) + ); + $url->setQueryVariables(array('foo' => array('bar', 'foobar'))); + $this->assertEquals( + 'http://example.org/?foo=bar&foo=foobar', + strval($url) + ); + } } // Call Net_URL2Test::main() if this source file is executed directly.

« previous php.pear.cvs (#61426) next »