/** * @covers Guzzle\Http\QueryString * @covers Guzzle\Http\QueryString::__toString * @covers Guzzle\Http\QueryString::useUrlEncoding * @covers Guzzle\Http\QueryString::replace * @covers Guzzle\Http\QueryString::setAggregateFunction * @covers Guzzle\Http\QueryString::urlEncode */ public function testToString() { // Check with no parameters $this->assertEquals('', $this->q->__toString()); $params = array('test' => 'value', 'test 2' => 'this is a test?', 'test3' => array('v1', 'v2', 'v3'), 'test4' => null); $this->q->replace($params); $this->assertEquals('?test=value&test%202=this%20is%20a%20test%3F&test3%5B0%5D=v1&test3%5B1%5D=v2&test3%5B2%5D=v3&test4=', $this->q->__toString()); $this->q->useUrlEncoding(false); $this->assertEquals('?test=value&test 2=this is a test?&test3[0]=v1&test3[1]=v2&test3[2]=v3&test4=', $this->q->__toString()); // Use an alternative aggregator $this->q->setAggregateFunction(array($this->q, 'aggregateUsingComma')); $this->assertEquals('?test=value&test 2=this is a test?&test3=v1,v2,v3&test4=', $this->q->__toString()); }
/** * @covers Guzzle\Http\QueryString::__toString * @covers Guzzle\Http\QueryString::aggregateUsingDuplicates */ public function testAllowsMultipleValuesPerKey() { $q = new QueryString(); $q->add('facet', 'size'); $q->add('facet', 'width'); $q->add('facet.field', 'foo'); // Use the duplicate aggregator $q->setAggregateFunction(array($this->q, 'aggregateUsingDuplicates')); $this->assertEquals('?facet=size&facet=width&facet.field=foo', $q->__toString()); }