From 05976ee2b1864c9eb4f3273401429a0d8c73eaf3 Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Thu, 6 Mar 2014 10:35:57 -0800 Subject: [PATCH] Adding some missing cookie jar tests --- tests/Cookie/CookieJarTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/Cookie/CookieJarTest.php b/tests/Cookie/CookieJarTest.php index d101f96a..79519463 100644 --- a/tests/Cookie/CookieJarTest.php +++ b/tests/Cookie/CookieJarTest.php @@ -29,6 +29,12 @@ class CookieJarTest extends \PHPUnit_Framework_TestCase ]; } + public function testQuotesBadCookieValues() + { + $this->assertEquals('foo', CookieJar::getCookieValue('foo')); + $this->assertEquals('"foo,bar"', CookieJar::getCookieValue('foo,bar')); + } + public function testCreatesFromArray() { $jar = CookieJar::fromArray([ @@ -293,4 +299,27 @@ class CookieJarTest extends \PHPUnit_Framework_TestCase $a = new CookieJar(true); $a->setCookie(new SetCookie(['Name' => "abc\n", 'Value' => 'foo', 'Domain' => 'bar'])); } + + public function testDeletesCookiesByName() + { + $cookies = $this->getTestCookies(); + $cookies[] = new SetCookie([ + 'Name' => 'other', + 'Value' => '123', + 'Domain' => 'bar.com', + 'Path' => '/boo', + 'Expires' => time() + 1000 + ]); + $jar = new CookieJar(); + foreach ($cookies as $cookie) { + $jar->setCookie($cookie); + } + $this->assertCount(4, $jar); + $jar->clear('bar.com', '/boo', 'other'); + $this->assertCount(3, $jar); + $names = array_map(function (SetCookie $c) { + return $c->getName(); + }, $jar->getIterator()->getArrayCopy()); + $this->assertEquals(['foo', 'test', 'you'], $names); + } }