Skip to content

Commit

Permalink
merged branch pborreli/browserkit (PR #5097)
Browse files Browse the repository at this point in the history
Commits
-------

910b60d [BrowserKit] Added some tests, removed dead code

Discussion
----------

[BrowserKit] Added some tests

Code coverage : 99.68%
  • Loading branch information
fabpot committed Jul 30, 2012
2 parents cbd03ec + 910b60d commit a172a81
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Expand Up @@ -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')) {
Expand Down
23 changes: 23 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/BrowserKit/Tests/CookieTest.php
Expand Up @@ -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\''),
);
}

Expand Down

0 comments on commit a172a81

Please sign in to comment.