Changeset View
Changeset View
Standalone View
Standalone View
src/parser/__tests__/PhutilURITestCase.php
Show First 20 Lines • Show All 269 Lines • ▼ Show 20 Lines | try { | ||||
$uri->setType(PhutilURI::TYPE_URI); | $uri->setType(PhutilURI::TYPE_URI); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$caught = $ex; | $caught = $ex; | ||||
} | } | ||||
$this->assertTrue($caught instanceof Exception); | $this->assertTrue($caught instanceof Exception); | ||||
} | } | ||||
public function testDuplicateKeys() { | |||||
$uri = new PhutilURI('http://www.example.com/?x=1&x=2'); | |||||
$this->assertEqual( | |||||
'http://www.example.com/?x=1&x=2', | |||||
(string)$uri); | |||||
$uri->appendQueryParam('x', '3'); | |||||
$this->assertEqual( | |||||
'http://www.example.com/?x=1&x=2&x=3', | |||||
(string)$uri); | |||||
$uri->setQueryParam('x', '4'); | |||||
$this->assertEqual( | |||||
'http://www.example.com/?x=4', | |||||
(string)$uri); | |||||
$uri->setQueryParam('x', null); | |||||
$this->assertEqual( | |||||
'http://www.example.com/', | |||||
(string)$uri); | |||||
$uri->appendQueryParam('a', 'a'); | |||||
$uri->appendQueryParam('b', 'b'); | |||||
$uri->appendQueryParam('c', 'c'); | |||||
$uri->appendQueryParam('b', 'd'); | |||||
$this->assertEqual( | |||||
'http://www.example.com/?a=a&b=b&c=c&b=d', | |||||
(string)$uri); | |||||
$uri->setQueryParam('b', 'e'); | |||||
$this->assertEqual( | |||||
'http://www.example.com/?a=a&b=e&c=c', | |||||
(string)$uri, | |||||
pht( | |||||
'Replacing a parameter should retain position and overwrite other '. | |||||
'instances of the key.')); | |||||
} | |||||
public function testBadHTTPParameters() { | |||||
$uri = new PhutilURI('http://www.example.com/'); | |||||
$caught = null; | |||||
try { | |||||
$uri->setQueryParam(array(), 'x'); | |||||
} catch (Exception $ex) { | |||||
$caught = $ex; | |||||
} | |||||
$this->assertTrue( | |||||
(bool)$caught, | |||||
pht('Nonscalar HTTP keys should throw.')); | |||||
$caught = null; | |||||
try { | |||||
$uri->setQueryParam('x', array()); | |||||
} catch (Exception $ex) { | |||||
$caught = $ex; | |||||
} | |||||
$this->assertTrue( | |||||
(bool)$caught, | |||||
pht('Nonscalar HTTP values should throw.')); | |||||
} | |||||
public function testHTTPParameterTypes() { | |||||
// Whether you pass an integer or string, "0" should always be the same | |||||
// query parameter. | |||||
$uri = new PhutilURI('http://www.example.com/'); | |||||
$uri->appendQueryParam(0, 'a'); | |||||
$uri->appendQueryParam('0', 'b'); | |||||
$this->assertEqual( | |||||
'http://www.example.com/?0=a&0=b', | |||||
(string)$uri); | |||||
$uri->setQueryParam(0, 'c'); | |||||
$this->assertEqual( | |||||
'http://www.example.com/?0=c', | |||||
(string)$uri); | |||||
$uri->setQueryParam(0, 'a'); | |||||
$uri->appendQueryParam('0', 'b'); | |||||
$this->assertEqual( | |||||
'http://www.example.com/?0=a&0=b', | |||||
(string)$uri); | |||||
$uri->setQueryParam('0', 'c'); | |||||
$this->assertEqual( | |||||
'http://www.example.com/?0=c', | |||||
(string)$uri); | |||||
} | |||||
} | } |