1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137:
<?php
namespace Guzzle\Tests\Http\Message;
use Guzzle\Http\Message\Header;
use Guzzle\Http\Message\Request;
use Guzzle\Common\Collection;
class AbstractMessageTest extends \Guzzle\Tests\GuzzleTestCase
{
private $request;
private $mock;
public function setUp()
{
parent::setUp();
$this->mock = $this->getMockForAbstractClass('Guzzle\Http\Message\AbstractMessage');
}
public function tearDown()
{
$this->mock = $this->request = null;
}
public function testGetParams()
{
$request = new Request('GET', 'http://example.com');
$this->assertInstanceOf('Guzzle\\Common\\Collection', $request->getParams());
}
public function testAddHeaders()
{
$this->mock->setHeader('A', 'B');
$this->assertEquals($this->mock, $this->mock->addHeaders(array(
'X-Data' => '123'
)));
$this->assertTrue($this->mock->hasHeader('X-Data') !== false);
$this->assertTrue($this->mock->hasHeader('A') !== false);
}
public function testAllowsHeaderToSetAsHeader()
{
$h = new Header('A', 'B');
$this->mock->setHeader('A', $h);
$this->assertSame($h, $this->mock->getHeader('A'));
}
public function testGetHeader()
{
$this->mock->setHeader('Test', '123');
$this->assertEquals('123', $this->mock->getHeader('Test'));
}
public function testGetHeaders()
{
$this->assertSame($this->mock, $this->mock->setHeaders(array('a' => 'b', 'c' => 'd')));
$h = $this->mock->getHeaders();
$this->assertArrayHasKey('a', $h->toArray());
$this->assertArrayHasKey('c', $h->toArray());
$this->assertInstanceOf('Guzzle\Http\Message\Header\HeaderInterface', $h->get('a'));
$this->assertInstanceOf('Guzzle\Http\Message\Header\HeaderInterface', $h->get('c'));
}
public function testGetHeaderLinesUsesGlue()
{
$this->mock->setHeaders(array('a' => 'b', 'c' => 'd'));
$this->mock->addHeader('a', 'e');
$this->mock->getHeader('a')->setGlue('!');
$this->assertEquals(array(
'a: b! e',
'c: d'
), $this->mock->getHeaderLines());
}
public function testHasHeader()
{
$this->assertFalse($this->mock->hasHeader('Foo'));
$this->mock->setHeader('Foo', 'Bar');
$this->assertEquals(true, $this->mock->hasHeader('Foo'));
$this->mock->setHeader('foo', 'yoo');
$this->assertEquals(true, $this->mock->hasHeader('Foo'));
$this->assertEquals(true, $this->mock->hasHeader('foo'));
$this->assertEquals(false, $this->mock->hasHeader('bar'));
}
public function testRemoveHeader()
{
$this->mock->setHeader('Foo', 'Bar');
$this->assertEquals(true, $this->mock->hasHeader('Foo'));
$this->mock->removeHeader('Foo');
$this->assertFalse($this->mock->hasHeader('Foo'));
}
public function testReturnsNullWhenHeaderIsNotFound()
{
$this->assertNull($this->mock->getHeader('foo'));
}
public function testAddingHeadersPreservesOriginalHeaderCase()
{
$this->mock->addHeaders(array(
'test' => '123',
'Test' => 'abc'
));
$this->mock->addHeader('test', '456');
$this->mock->addHeader('test', '789');
$header = $this->mock->getHeader('test');
$this->assertContains('123', $header->toArray());
$this->assertContains('456', $header->toArray());
$this->assertContains('789', $header->toArray());
$this->assertContains('abc', $header->toArray());
}
public function testCanStoreEmptyHeaders()
{
$this->mock->setHeader('Content-Length', 0);
$this->assertTrue($this->mock->hasHeader('Content-Length'));
$this->assertEquals(0, (string) $this->mock->getHeader('Content-Length'));
}
public function testCanSetCustomHeaderFactory()
{
$f = new Header\HeaderFactory();
$this->mock->setHeaderFactory($f);
$this->assertSame($f, $this->readAttribute($this->mock, 'headerFactory'));
}
}