-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added extra unit tests in the driver #68
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<?php | ||
|
||
namespace Tests\Behat\Mink\Driver; | ||
|
||
use Behat\Mink\Driver\BrowserKitDriver; | ||
use Symfony\Component\BrowserKit\Client; | ||
use Symfony\Component\BrowserKit\Response; | ||
|
||
class ExtraDriverTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var TestClient | ||
*/ | ||
private $client; | ||
|
||
protected function setUp() | ||
{ | ||
$this->client = new TestClient(); | ||
} | ||
|
||
public function testGetClient() | ||
{ | ||
$this->assertSame($this->client, $this->getDriver()->getClient()); | ||
} | ||
|
||
/** | ||
* @expectedException \Behat\Mink\Exception\DriverException | ||
* @expectedExceptionMessage Unable to access the response before visiting a page | ||
*/ | ||
public function testGetResponseHeaderWithoutVisit() | ||
{ | ||
$this->getDriver()->getResponseHeaders(); | ||
} | ||
|
||
/** | ||
* @expectedException \Behat\Mink\Exception\DriverException | ||
* @expectedExceptionMessage Unable to access the response content before visiting a page | ||
*/ | ||
public function testFindWithoutVisit() | ||
{ | ||
$this->getDriver()->find('//html'); | ||
} | ||
|
||
/** | ||
* @expectedException \Behat\Mink\Exception\DriverException | ||
* @expectedExceptionMessage Unable to access the request before visiting a page | ||
*/ | ||
public function testGetCurrentUrlWithoutVisit() | ||
{ | ||
$this->getDriver()->getCurrentUrl(); | ||
} | ||
|
||
/** | ||
* @expectedException \Behat\Mink\Exception\DriverException | ||
* @expectedExceptionMessage The selected node has an invalid form attribute (foo) | ||
*/ | ||
public function testNotMatchingHtml5FormId() | ||
{ | ||
$html = <<<'HTML' | ||
<html> | ||
<body> | ||
<form id="test"> | ||
<input name="test" value="foo" form="foo"> | ||
<input type="submit"> | ||
</form> | ||
</body> | ||
</html> | ||
HTML; | ||
|
||
$this->client->setNextResponse(new Response($html)); | ||
|
||
$driver = $this->getDriver(); | ||
$driver->visit('/index.php'); | ||
$driver->setValue('//input[./@name="test"]', 'bar'); | ||
} | ||
|
||
/** | ||
* @expectedException \Behat\Mink\Exception\DriverException | ||
* @expectedExceptionMessage The selected node has an invalid form attribute (foo) | ||
*/ | ||
public function testInvalidHtml5FormId() | ||
{ | ||
$html = <<<'HTML' | ||
<html> | ||
<body> | ||
<form id="test"> | ||
<input name="test" value="foo" form="foo"> | ||
<input type="submit"> | ||
</form> | ||
<div id="foo"></div> | ||
</body> | ||
</html> | ||
HTML; | ||
|
||
$this->client->setNextResponse(new Response($html)); | ||
|
||
$driver = $this->getDriver(); | ||
$driver->visit('/index.php'); | ||
$driver->setValue('//input[./@name="test"]', 'bar'); | ||
} | ||
|
||
/** | ||
* @expectedException \Behat\Mink\Exception\DriverException | ||
* @expectedExceptionMessage The selected node does not have a form ancestor. | ||
*/ | ||
public function testManipulateInputWithoutForm() | ||
{ | ||
$html = <<<'HTML' | ||
<html> | ||
<body> | ||
<form id="test"> | ||
<input type="submit"> | ||
</form> | ||
<div id="foo"> | ||
<input name="test" value="foo"> | ||
</div> | ||
</body> | ||
</html> | ||
HTML; | ||
|
||
$this->client->setNextResponse(new Response($html)); | ||
|
||
$driver = $this->getDriver(); | ||
$driver->visit('/index.php'); | ||
$driver->setValue('//input[./@name="test"]', 'bar'); | ||
} | ||
|
||
/** | ||
* @expectedException \Behat\Mink\Exception\DriverException | ||
* @expectedExceptionMessage Behat\Mink\Driver\BrowserKitDriver supports clicking on links and buttons only. But "div" provided | ||
*/ | ||
public function testClickOnUnsupportedElement() | ||
{ | ||
$html = <<<'HTML' | ||
<html> | ||
<body> | ||
<div></div> | ||
</body> | ||
</html> | ||
HTML; | ||
|
||
$this->client->setNextResponse(new Response($html)); | ||
|
||
$driver = $this->getDriver(); | ||
$driver->visit('/index.php'); | ||
$driver->click('//div'); | ||
} | ||
|
||
private function getDriver() | ||
{ | ||
return new BrowserKitDriver($this->client); | ||
} | ||
} | ||
|
||
class TestClient extends Client | ||
{ | ||
protected $nextResponse = null; | ||
protected $nextScript = null; | ||
|
||
public function setNextResponse(Response $response) | ||
{ | ||
$this->nextResponse = $response; | ||
} | ||
|
||
public function setNextScript($script) | ||
{ | ||
$this->nextScript = $script; | ||
} | ||
|
||
protected function doRequest($request) | ||
{ | ||
if (null === $this->nextResponse) { | ||
return new Response(); | ||
} | ||
|
||
$response = $this->nextResponse; | ||
$this->nextResponse = null; | ||
|
||
return $response; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw you did the opposite change for the
MinkGoutteDriver
. Technically all drivers tests are functional ones, but all Mink tests are unit tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. I did exactly the same change: https://github.com/Behat/MinkGoutteDriver/blob/master/tests/Behat/Mink/Driver/GoutteDriverTest.php#L8
Having a different group per driver is a left-over from Mink 1.3 when the drivers were in the main repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.