Open Monograph Press  3.3.0
HeaderTest.php
1 <?php
2 
4 
7 
12 {
13  protected $test = array(
14  'zoo' => array('foo', 'Foo'),
15  'Zoo' => 'bar',
16  );
17 
18  public function testStoresHeaderName()
19  {
20  $i = new Header('Zoo', $this->test);
21  $this->assertEquals('Zoo', $i->getName());
22  }
23 
24  public function testConvertsToString()
25  {
26  $i = new Header('Zoo', $this->test);
27  $this->assertEquals('foo, Foo, bar', (string) $i);
28  $i->setGlue(';');
29  $this->assertEquals('foo; Foo; bar', (string) $i);
30  }
31 
32  public function testNormalizesGluedHeaders()
33  {
34  $h = new Header('Zoo', array('foo, Faz', 'bar'));
35  $result = $h->normalize(true)->toArray();
36  natsort($result);
37  $this->assertEquals(array('bar', 'foo', 'Faz'), $result);
38  }
39 
40  public function testCanSearchForValues()
41  {
42  $h = new Header('Zoo', $this->test);
43  $this->assertTrue($h->hasValue('foo'));
44  $this->assertTrue($h->hasValue('Foo'));
45  $this->assertTrue($h->hasValue('bar'));
46  $this->assertFalse($h->hasValue('moo'));
47  $this->assertFalse($h->hasValue('FoO'));
48  }
49 
50  public function testIsCountable()
51  {
52  $h = new Header('Zoo', $this->test);
53  $this->assertEquals(3, count($h));
54  }
55 
56  public function testCanBeIterated()
57  {
58  $h = new Header('Zoo', $this->test);
59  $results = array();
60  foreach ($h as $key => $value) {
61  $results[$key] = $value;
62  }
63  $this->assertEquals(array(
64  'foo', 'Foo', 'bar'
65  ), $results);
66  }
67 
68  public function testAllowsFalseyValues()
69  {
70  // Allows 0
71  $h = new Header('Foo', 0, ';');
72  $this->assertEquals('0', (string) $h);
73  $this->assertEquals(1, count($h));
74  $this->assertEquals(';', $h->getGlue());
75 
76  // Does not add a null header by default
77  $h = new Header('Foo');
78  $this->assertEquals('', (string) $h);
79  $this->assertEquals(0, count($h));
80 
81  // Allows null array for a single null header
82  $h = new Header('Foo', array(null));
83  $this->assertEquals('', (string) $h);
84 
85  // Allows empty string
86  $h = new Header('Foo', '');
87  $this->assertEquals('', (string) $h);
88  $this->assertEquals(1, count($h));
89  $this->assertEquals(1, count($h->normalize()->toArray()));
90  }
91 
92  public function testCanRemoveValues()
93  {
94  $h = new Header('Foo', array('Foo', 'baz', 'bar'));
95  $h->removeValue('bar');
96  $this->assertTrue($h->hasValue('Foo'));
97  $this->assertFalse($h->hasValue('bar'));
98  $this->assertTrue($h->hasValue('baz'));
99  }
100 
102  {
103  $h = new Header('Foo', array('Testing', '123', 'Foo=baz'));
104  $this->assertEquals(array('Testing', '123', 'Foo=baz'), $h->toArray());
105  }
106 
107  public function parseParamsProvider()
108  {
109  $res1 = array(
110  array(
111  '<http:/.../front.jpeg>' => '',
112  'rel' => 'front',
113  'type' => 'image/jpeg',
114  ),
115  array(
116  '<http://.../back.jpeg>' => '',
117  'rel' => 'back',
118  'type' => 'image/jpeg',
119  ),
120  );
121 
122  return array(
123  array(
124  '<http:/.../front.jpeg>; rel="front"; type="image/jpeg", <http://.../back.jpeg>; rel=back; type="image/jpeg"',
125  $res1
126  ),
127  array(
128  '<http:/.../front.jpeg>; rel="front"; type="image/jpeg",<http://.../back.jpeg>; rel=back; type="image/jpeg"',
129  $res1
130  ),
131  array(
132  'foo="baz"; bar=123, boo, test="123", foobar="foo;bar"',
133  array(
134  array('foo' => 'baz', 'bar' => '123'),
135  array('boo' => ''),
136  array('test' => '123'),
137  array('foobar' => 'foo;bar')
138  )
139  ),
140  array(
141  '<http://.../side.jpeg?test=1>; rel="side"; type="image/jpeg",<http://.../side.jpeg?test=2>; rel=side; type="image/jpeg"',
142  array(
143  array('<http://.../side.jpeg?test=1>' => '', 'rel' => 'side', 'type' => 'image/jpeg'),
144  array('<http://.../side.jpeg?test=2>' => '', 'rel' => 'side', 'type' => 'image/jpeg')
145  )
146  ),
147  array(
148  '',
149  array()
150  )
151  );
152  }
153 
157  public function testParseParams($header, $result)
158  {
159  $response = new Response(200, array('Link' => $header));
160  $this->assertEquals($result, $response->getHeader('Link')->parseParams());
161  }
162 }
Guzzle\Http\Message\Header
Definition: CacheControl.php:3
Guzzle\Http\Message\Header
Definition: Header.php:11
Guzzle\Tests\Http\Message\HeaderTest\testCanBeIterated
testCanBeIterated()
Definition: HeaderTest.php:56
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Http\Message\Response
Definition: paymethod/paypal/lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:17
Guzzle\Tests\Http\Message\HeaderTest\testAllowsArrayInConstructor
testAllowsArrayInConstructor()
Definition: HeaderTest.php:101
Guzzle\Tests\Http\Message\HeaderTest\testNormalizesGluedHeaders
testNormalizesGluedHeaders()
Definition: HeaderTest.php:32
Guzzle\Tests\Http\Message\HeaderTest\testCanSearchForValues
testCanSearchForValues()
Definition: HeaderTest.php:40
Guzzle\Tests\Http\Message\HeaderTest
Definition: HeaderTest.php:11
Guzzle\Tests\Http\Message\HeaderTest\parseParamsProvider
parseParamsProvider()
Definition: HeaderTest.php:107
Guzzle\Tests\Http\Message\HeaderTest\testIsCountable
testIsCountable()
Definition: HeaderTest.php:50
Guzzle\Tests\Http\Message\HeaderTest\testCanRemoveValues
testCanRemoveValues()
Definition: HeaderTest.php:92
Guzzle\Tests\Http\Message\HeaderTest\testAllowsFalseyValues
testAllowsFalseyValues()
Definition: HeaderTest.php:68
Guzzle\Tests\Http\Message\HeaderTest\testStoresHeaderName
testStoresHeaderName()
Definition: HeaderTest.php:18
Guzzle\Tests\Http\Message\HeaderTest\$test
$test
Definition: HeaderTest.php:13
Guzzle\Tests\Http\Message\HeaderTest\testParseParams
testParseParams($header, $result)
Definition: HeaderTest.php:157
Guzzle\Tests\Http\Message
Definition: AbstractMessageTest.php:3
Guzzle\Tests\Http\Message\HeaderTest\testConvertsToString
testConvertsToString()
Definition: HeaderTest.php:24