Permalink
Browse files

[BrowserKit] Added some tests, removed dead code

  • Loading branch information...
1 parent ae69d90 commit a224ae56865fd63e4a63958275117168479c8e0f @pborreli pborreli committed Jul 28, 2012
Showing with 43 additions and 0 deletions.
  1. +19 −0 Tests/ClientTest.php
  2. +23 −0 Tests/CookieJarTest.php
  3. +1 −0 Tests/CookieTest.php
View
19 Tests/ClientTest.php
@@ -224,6 +224,25 @@ public function testClick()
$this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->click() clicks on links');
}
+ public function testClickForm()
+ {
+ if (!class_exists('Symfony\Component\DomCrawler\Crawler')) {
+ $this->markTestSkipped('The "DomCrawler" component is not available');
+ }
+
+ if (!class_exists('Symfony\Component\CssSelector\CssSelector')) {
+ $this->markTestSkipped('The "CssSelector" component is not available');
+ }
+
+ $client = new TestClient();
+ $client->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>'));
+ $crawler = $client->request('GET', 'http://www.example.com/foo/foobar');
+
+ $client->click($crawler->filter('input')->form());
+
+ $this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->click() Form submit forms');
+ }
+
public function testSubmit()
{
if (!class_exists('Symfony\Component\DomCrawler\Crawler')) {
View
23 Tests/CookieJarTest.php
@@ -144,6 +144,29 @@ public function testEncodedValues()
$this->assertEquals(array('foo' => 'bar%3Dbaz'), $cookieJar->allRawValues('/'));
}
+ public function testCookieExpireWithSameNameButDifferentPaths()
+ {
+ $cookieJar = new CookieJar();
+ $cookieJar->set($cookie1 = new Cookie('foo', 'bar1', null, '/foo'));
+ $cookieJar->set($cookie2 = new Cookie('foo', 'bar2', null, '/bar'));
+ $cookieJar->expire('foo', '/foo');
+
+ $this->assertNull($cookieJar->get('foo'), '->get() returns null if the cookie is expired');
+ $this->assertEquals(array(), array_keys($cookieJar->allValues('http://example.com/')));
+ $this->assertEquals(array(), $cookieJar->allValues('http://example.com/foo'));
+ $this->assertEquals(array('foo' => 'bar2'), $cookieJar->allValues('http://example.com/bar'));
+ }
+
+ public function testCookieExpireWithNullPaths()
+ {
+ $cookieJar = new CookieJar();
+ $cookieJar->set($cookie1 = new Cookie('foo', 'bar1', null, '/'));
+ $cookieJar->expire('foo', null);
+
+ $this->assertNull($cookieJar->get('foo'), '->get() returns null if the cookie is expired');
+ $this->assertEquals(array(), array_keys($cookieJar->allValues('http://example.com/')));
+ }
+
public function testCookieWithSameNameButDifferentPaths()
{
$cookieJar = new CookieJar();
View
1 Tests/CookieTest.php
@@ -58,6 +58,7 @@ public function getExpireCookieStrings()
array('foo=bar; expires=Fri, 31 Jul 2020 08:49:37 GMT'),
array('foo=bar; expires=Friday, 31-Jul-20 08:49:37 GMT'),
array('foo=bar; expires=Fri Jul 31 08:49:37 2020'),
+ array('foo=bar; expires=\'Fri Jul 31 08:49:37 2020\''),
);
}

0 comments on commit a224ae5

Please sign in to comment.