14 use PHPUnit\Framework\TestCase;
21 $bag =
new HeaderBag(array(
'foo' =>
'bar'));
22 $this->assertTrue($bag->has(
'foo'));
28 $this->assertEquals(
'', $bag->__toString());
33 $bag =
new HeaderBag(array(
'foo' =>
'bar'));
34 $this->assertEquals(
"Foo: bar\r\n", $bag->__toString());
39 $bag =
new HeaderBag(array(
'foo' =>
'bar'));
41 $this->assertEquals(
'foo', $keys[0]);
46 $bag =
new HeaderBag(array(
'foo' =>
'Tue, 4 Sep 2012 20:00:00 +0200'));
47 $headerDate = $bag->getDate(
'foo');
48 $this->assertInstanceOf(
'DateTime', $headerDate);
56 $bag =
new HeaderBag(array(
'foo' =>
'Tue'));
57 $headerDate = $bag->getDate(
'foo');
63 $bag->addCacheControlDirective(
'public',
'#a');
64 $this->assertTrue($bag->hasCacheControlDirective(
'public'));
65 $this->assertEquals(
'#a', $bag->getCacheControlDirective(
'public'));
70 $bag =
new HeaderBag(array(
'foo' =>
'bar'));
71 $this->assertEquals(array(
'foo' => array(
'bar')), $bag->all(),
'->all() gets all the input');
73 $bag =
new HeaderBag(array(
'FOO' =>
'BAR'));
74 $this->assertEquals(array(
'foo' => array(
'BAR')), $bag->all(),
'->all() gets all the input key are lower case');
79 $bag =
new HeaderBag(array(
'foo' =>
'bar'));
81 $bag->replace(array(
'NOPE' =>
'BAR'));
82 $this->assertEquals(array(
'nope' => array(
'BAR')), $bag->all(),
'->replace() replaces the input with the argument');
83 $this->assertFalse($bag->has(
'foo'),
'->replace() overrides previously set the input');
88 $bag =
new HeaderBag(array(
'foo' =>
'bar',
'fuzz' =>
'bizz'));
89 $this->assertEquals(
'bar', $bag->get(
'foo'),
'->get return current value');
90 $this->assertEquals(
'bar', $bag->get(
'FoO'),
'->get key in case insensitive');
91 $this->assertEquals(array(
'bar'), $bag->get(
'foo',
'nope',
false),
'->get return the value as array');
94 $this->assertNull($bag->get(
'none'),
'->get unknown values returns null');
95 $this->assertEquals(
'default', $bag->get(
'none',
'default'),
'->get unknown values returns default');
96 $this->assertEquals(array(
'default'), $bag->get(
'none',
'default',
false),
'->get unknown values returns default as array');
98 $bag->set(
'foo',
'bor',
false);
99 $this->assertEquals(
'bar', $bag->get(
'foo'),
'->get return first value');
100 $this->assertEquals(array(
'bar',
'bor'), $bag->get(
'foo',
'nope',
false),
'->get return all values as array');
106 $bag->set(
'foo', array(
'bad-assoc-index' =>
'value'));
107 $this->assertSame(
'value', $bag->get(
'foo'));
108 $this->assertEquals(array(
'value'), $bag->get(
'foo',
'nope',
false),
'assoc indices of multi-valued headers are ignored');
113 $bag =
new HeaderBag(array(
'foo' =>
'bar',
'fuzz' =>
'bizz'));
114 $this->assertTrue($bag->contains(
'foo',
'bar'),
'->contains first value');
115 $this->assertTrue($bag->contains(
'fuzz',
'bizz'),
'->contains second value');
116 $this->assertFalse($bag->contains(
'nope',
'nope'),
'->contains unknown value');
117 $this->assertFalse($bag->contains(
'foo',
'nope'),
'->contains unknown value');
120 $bag->set(
'foo',
'bor',
false);
121 $this->assertTrue($bag->contains(
'foo',
'bar'),
'->contains first value');
122 $this->assertTrue($bag->contains(
'foo',
'bor'),
'->contains second value');
123 $this->assertFalse($bag->contains(
'foo',
'nope'),
'->contains unknown value');
129 $bag->addCacheControlDirective(
'public');
131 $this->assertTrue($bag->hasCacheControlDirective(
'public'));
132 $this->assertTrue($bag->getCacheControlDirective(
'public'));
133 $this->assertEquals(
'public', $bag->get(
'cache-control'));
135 $bag->addCacheControlDirective(
'max-age', 10);
136 $this->assertTrue($bag->hasCacheControlDirective(
'max-age'));
137 $this->assertEquals(10, $bag->getCacheControlDirective(
'max-age'));
138 $this->assertEquals(
'max-age=10, public', $bag->get(
'cache-control'));
140 $bag->removeCacheControlDirective(
'max-age');
141 $this->assertFalse($bag->hasCacheControlDirective(
'max-age'));
146 $bag =
new HeaderBag(array(
'cache-control' =>
'public, max-age=10'));
147 $this->assertTrue($bag->hasCacheControlDirective(
'public'));
148 $this->assertTrue($bag->getCacheControlDirective(
'public'));
150 $this->assertTrue($bag->hasCacheControlDirective(
'max-age'));
151 $this->assertEquals(10, $bag->getCacheControlDirective(
'max-age'));
153 $bag->addCacheControlDirective(
's-maxage', 100);
154 $this->assertEquals(
'max-age=10, public, s-maxage=100', $bag->get(
'cache-control'));
159 $bag =
new HeaderBag(array(
'cache-control' =>
'max-age="0"'));
160 $this->assertTrue($bag->hasCacheControlDirective(
'max-age'));
161 $this->assertEquals(0, $bag->getCacheControlDirective(
'max-age'));
166 $bag =
new HeaderBag(array(
'cache-control' =>
'private, max-age=100'));
167 $bag->replace(array(
'cache-control' =>
'public, max-age=10'));
168 $this->assertTrue($bag->hasCacheControlDirective(
'public'));
169 $this->assertTrue($bag->getCacheControlDirective(
'public'));
171 $this->assertTrue($bag->hasCacheControlDirective(
'max-age'));
172 $this->assertEquals(10, $bag->getCacheControlDirective(
'max-age'));
177 $headers = array(
'foo' =>
'bar');
181 $this->assertEquals($bag1->all(), $bag2->all());
186 $headers = array(
'foo' =>
'bar',
'hello' =>
'world',
'third' =>
'charm');
190 foreach ($headerBag as $key => $val) {
192 $this->assertEquals(array($headers[$key]), $val);
195 $this->assertEquals(count($headers), $i);
200 $headers = array(
'foo' =>
'bar',
'HELLO' =>
'WORLD');
203 $this->assertEquals(count($headers), count($headerBag));