@@ -76,6 +76,29 @@ public function testToStringIncludesCookieHeaders()
7676 $ this ->assertContains ("Set-Cookie: foo=deleted; expires= " .gmdate ("D, d-M-Y H:i:s T " , time () - 31536001 )."; httponly " , explode ("\r\n" , $ bag ->__toString ()));
7777 }
7878
79+ public function testReplace ()
80+ {
81+ $ bag = new ResponseHeaderBag (array ());
82+ $ this ->assertEquals ('no-cache ' , $ bag ->get ('Cache-Control ' ));
83+ $ this ->assertTrue ($ bag ->hasCacheControlDirective ('no-cache ' ));
84+
85+ $ bag ->replace (array ('Cache-Control ' => 'public ' ));
86+ $ this ->assertEquals ('public ' , $ bag ->get ('Cache-Control ' ));
87+ $ this ->assertTrue ($ bag ->hasCacheControlDirective ('public ' ));
88+ }
89+
90+ public function testReplaceWithRemove ()
91+ {
92+ $ bag = new ResponseHeaderBag (array ());
93+ $ this ->assertEquals ('no-cache ' , $ bag ->get ('Cache-Control ' ));
94+ $ this ->assertTrue ($ bag ->hasCacheControlDirective ('no-cache ' ));
95+
96+ $ bag ->remove ('Cache-Control ' );
97+ $ bag ->replace (array ());
98+ $ this ->assertEquals ('no-cache ' , $ bag ->get ('Cache-Control ' ));
99+ $ this ->assertTrue ($ bag ->hasCacheControlDirective ('no-cache ' ));
100+ }
101+
79102 public function testCookiesWithSameNames ()
80103 {
81104 $ bag = new ResponseHeaderBag ();
@@ -119,6 +142,34 @@ public function testRemoveCookie()
119142 $ this ->assertFalse (isset ($ cookies ['foo.bar ' ]));
120143 }
121144
145+ public function testRemoveCookieWithNullRemove ()
146+ {
147+ $ bag = new ResponseHeaderBag ();
148+ $ bag ->setCookie (new Cookie ('foo ' , 'bar ' , 0 ));
149+ $ bag ->setCookie (new Cookie ('bar ' , 'foo ' , 0 ));
150+
151+ $ cookies = $ bag ->getCookies (ResponseHeaderBag::COOKIES_ARRAY );
152+ $ this ->assertTrue (isset ($ cookies ['' ]['/ ' ]));
153+
154+ $ bag ->removeCookie ('foo ' , null );
155+ $ cookies = $ bag ->getCookies (ResponseHeaderBag::COOKIES_ARRAY );
156+ $ this ->assertFalse (isset ($ cookies ['' ]['/ ' ]['foo ' ]));
157+
158+ $ bag ->removeCookie ('bar ' , null );
159+ $ cookies = $ bag ->getCookies (ResponseHeaderBag::COOKIES_ARRAY );
160+ $ this ->assertFalse (isset ($ cookies ['' ]['/ ' ]['bar ' ]));
161+ }
162+
163+ /**
164+ * @expectedException \InvalidArgumentException
165+ */
166+ public function testGetCookiesWithInvalidArgument ()
167+ {
168+ $ bag = new ResponseHeaderBag ();
169+
170+ $ cookies = $ bag ->getCookies ('invalid_argument ' );
171+ }
172+
122173 /**
123174 * @expectedException \InvalidArgumentException
124175 */
0 commit comments