From 0261b481681790e6199802bf9d84e281f62bba5c Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Thu, 5 Nov 2015 18:24:12 +0100 Subject: [PATCH] improve BrowserKit test coverage p1 improve BrowserKit test coverage p2 improve BrowserKit test coverage p3 improve BrowserKit test coverage p4 improve BrowserKit test coverage p5 --- .../Component/BrowserKit/Tests/ClientTest.php | 20 +++++++++++++++++++ .../BrowserKit/Tests/CookieJarTest.php | 18 +++++++++++++++++ .../Component/BrowserKit/Tests/CookieTest.php | 9 +++++++++ 3 files changed, 47 insertions(+) diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index 36a0fbc6ee..fe00376385 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -624,4 +624,24 @@ class ClientTest extends \PHPUnit_Framework_TestCase $this->assertArrayHasKey('HTTPS', $server); $this->assertFalse($server['HTTPS']); } + + public function testInternalRequest() + { + $client = new TestClient(); + + $client->request('GET', 'https://www.example.com/https/www.example.com', array(), array(), array( + 'HTTP_HOST' => 'testhost', + 'HTTP_USER_AGENT' => 'testua', + 'HTTPS' => false, + 'NEW_SERVER_KEY' => 'new-server-key-value', + )); + + $this->assertInstanceOf('Symfony\Component\BrowserKit\Request', $client->getInternalRequest()); + } + + public function testInternalRequestNull() + { + $client = new TestClient(); + $this->assertNull($client->getInternalRequest()); + } } diff --git a/src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php b/src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php index 4da4404e24..54a84b43a4 100644 --- a/src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php @@ -174,6 +174,16 @@ class CookieJarTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array(), array_keys($cookieJar->allValues('http://example.com/'))); } + public function testCookieExpireWithDomain() + { + $cookieJar = new CookieJar(); + $cookieJar->set($cookie1 = new Cookie('foo', 'bar1', null, '/foo', 'http://example2.com/')); + $cookieJar->expire('foo', '/foo', 'http://example2.com/'); + + $this->assertNull($cookieJar->get('foo'), '->get() returns null if the cookie is expired'); + $this->assertEquals(array(), array_keys($cookieJar->allValues('http://example2.com/'))); + } + public function testCookieWithSameNameButDifferentPaths() { $cookieJar = new CookieJar(); @@ -207,6 +217,14 @@ class CookieJarTest extends \PHPUnit_Framework_TestCase $this->assertEquals($cookie2, $cookieJar->get('foo1', '/', 'test.example.com')); } + public function testCookieGetWithWrongSubdomain() + { + $cookieJar = new CookieJar(); + $cookieJar->set($cookie1 = new Cookie('foo1', 'bar', null, '/', 'test.example.com')); + + $this->assertNull($cookieJar->get('foo1', '/', 'foo.example.com')); + } + public function testCookieGetWithSubdirectory() { $cookieJar = new CookieJar(); diff --git a/src/Symfony/Component/BrowserKit/Tests/CookieTest.php b/src/Symfony/Component/BrowserKit/Tests/CookieTest.php index e1dd0df2c1..61b364e6d1 100644 --- a/src/Symfony/Component/BrowserKit/Tests/CookieTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/CookieTest.php @@ -176,4 +176,13 @@ class CookieTest extends \PHPUnit_Framework_TestCase $cookie = new Cookie('foo', 'bar', 0); $this->assertFalse($cookie->isExpired()); } + + /** + * @expectedException UnexpectedValueException + * @expectedExceptionMessage The cookie expiration time "string" is not valid. + */ + public function testConstructException() + { + $cookie = new Cookie('foo', 'bar', 'string'); + } }