1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-26 19:15:10 +01:00
guzzle/tests/Guzzle/Tests/Http/Message/HeaderTest.php
Michael Dowling 614e4d1666 [Http] Refactoring cookie implementation
* Guzzle\Http\Cookie is now used to manage Set-Cookie data, not Cookie
data
* Moving almost all cookie logic out of the CookiePlugin and into the
Cookie or CookieJar implementations
* Array cookie jar now returns matching cookies for a request and adds
cookies from responses
* Renaming methods in the CookieJarInterface
* Removing old references to deleted classes
* Guzzle\Http\Message\Request no longer needs an internal Cookie object
* Making the default glue for HTTP headers ';' instead of ','
* Adding a removeValue to Guzzle\Http\Message\Header
* Adding getCookies() to request interface.
* Removing unused AUTH_BASIC and AUTH_DIGEST constants from
* Guzzle\Http\Message\RequestInterface
* Lots of cleanup in the Guzzle\Http\Parser\Cookie\CookieParser
* Cleaning up Cookie related tests
2012-06-02 21:38:05 -07:00

127 lines
3.4 KiB
PHP

<?php
namespace Guzzle\Tests\Http\Message;
use Guzzle\Http\Message\Header;
/**
* @covers Guzzle\Http\Message\Header
*/
class HeaderTest extends \Guzzle\Tests\GuzzleTestCase
{
protected $test = array(
'zoo' => array('foo', 'Foo'),
'Zoo' => 'bar',
);
public function testRawReturnsRawArray()
{
$i = new Header('Zoo', $this->test);
$this->assertEquals(array(
'zoo' => array('foo', 'Foo'),
'Zoo' => array('bar')
), $i->raw());
}
public function testStoresHeaderName()
{
$i = new Header('Zoo', $this->test);
$this->assertEquals('Zoo', $i->getName());
}
public function testConvertsToString()
{
$i = new Header('Zoo', $this->test);
$this->assertEquals('foo; Foo; bar', (string) $i);
$i->setGlue(', ');
$this->assertEquals('foo, Foo, bar', (string) $i);
}
public function testNormalizesCases()
{
$h = new Header('Zoo', $this->test);
$h->normalize();
$this->assertEquals(array(
'Zoo' => array('foo', 'Foo', 'bar')
), $h->raw());
}
public function testCanSearchForValues()
{
$h = new Header('Zoo', $this->test);
$this->assertTrue($h->hasValue('foo'));
$this->assertTrue($h->hasValue('Foo'));
$this->assertTrue($h->hasValue('bar'));
$this->assertFalse($h->hasValue('moo'));
$this->assertFalse($h->hasValue('FoO'));
$this->assertTrue($h->hasValue('FoO', true));
}
public function testIsCountable()
{
$h = new Header('Zoo', $this->test);
$this->assertEquals(3, count($h));
}
public function testCanBeIterated()
{
$h = new Header('Zoo', $this->test);
$results = array();
foreach ($h as $key => $value) {
$results[$key] = $value;
}
$this->assertEquals(array(
'foo', 'Foo', 'bar'
), $results);
}
public function testAllowsFalseyValues()
{
// Allows 0
$h = new Header('Foo', 0, ';');
$this->assertEquals('0', (string) $h);
$this->assertEquals(1, count($h));
$this->assertEquals(';', $h->getGlue());
// Does not add a null header by default
$h = new Header('Foo');
$this->assertEquals('', (string) $h);
$this->assertEquals(0, count($h));
// Allows null array for a single null header
$h = new Header('Foo', array(null));
$this->assertEquals('', (string) $h);
$this->assertEquals(1, count($h));
// Allows empty string
$h = new Header('Foo', '');
$this->assertEquals('', (string) $h);
$this->assertEquals(1, count($h));
}
public function testUsesHeaderNameWhenNoneIsSupplied()
{
$h = new Header('Foo', 'bar', ';');
$h->add('baz');
$this->assertEquals(array('Foo'), array_keys($h->raw()));
}
public function testCanCheckForExactHeaderValues()
{
$h = new Header('Foo', 'bar', ';');
$this->assertTrue($h->hasExactHeader('Foo'));
$this->assertFalse($h->hasExactHeader('foo'));
}
public function testCanRemoveValues()
{
$h = new Header('Foo', array('Foo', 'baz', 'bar'));
$h->removeValue('bar');
$this->assertTrue($h->hasValue('Foo'));
$this->assertFalse($h->hasValue('bar'));
$this->assertTrue($h->hasValue('baz'));
}
}