X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fbehat%2Fmink-browserkit-driver%2Ftests%2FCustom%2FErrorHandlingTest.php;fp=vendor%2Fbehat%2Fmink-browserkit-driver%2Ftests%2FCustom%2FErrorHandlingTest.php;h=9e2643c143d90b6c201ac04d93a53ecb5c12b3bf;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/behat/mink-browserkit-driver/tests/Custom/ErrorHandlingTest.php b/vendor/behat/mink-browserkit-driver/tests/Custom/ErrorHandlingTest.php new file mode 100644 index 000000000..9e2643c14 --- /dev/null +++ b/vendor/behat/mink-browserkit-driver/tests/Custom/ErrorHandlingTest.php @@ -0,0 +1,181 @@ +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; + + $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; + + $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; + + $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 submit or reset buttons only. But "div" provided + */ + public function testClickOnUnsupportedElement() + { + $html = <<<'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; + } +}