diff --git a/src/Behat/Mink/Driver/GoutteDriver.php b/src/Behat/Mink/Driver/GoutteDriver.php index c33286be4..760beb0e9 100644 --- a/src/Behat/Mink/Driver/GoutteDriver.php +++ b/src/Behat/Mink/Driver/GoutteDriver.php @@ -200,7 +200,10 @@ public function getStatusCode() */ public function getContent() { - return $this->client->getResponse()->getContent(); + $content = $this->client->getResponse()->getContent(); + $content = preg_replace('/^.*\]*\>/is', '', $content); + + return $content; } /** diff --git a/src/Behat/Mink/Element/DocumentElement.php b/src/Behat/Mink/Element/DocumentElement.php index df446aa86..4a3f7a13c 100644 --- a/src/Behat/Mink/Element/DocumentElement.php +++ b/src/Behat/Mink/Element/DocumentElement.php @@ -32,7 +32,7 @@ public function getXpath() */ public function getContent() { - return $this->getSession()->getDriver()->getContent(); + return trim($this->getSession()->getDriver()->getContent()); } /** @@ -44,7 +44,7 @@ public function getContent() */ public function hasContent($content) { - return $this->hasSelector('named', array( + return $this->has('named', array( 'content', $this->getSession()->getSelectorsHandler()->xpathLiteral($content) )); } @@ -180,7 +180,7 @@ public function hasUncheckedField($locator) */ public function hasSelect($locator) { - return $this->hasSelector('named', array( + return $this->has('named', array( 'select', $this->getSession()->getSelectorsHandler()->xpathLiteral($locator) )); } @@ -194,7 +194,7 @@ public function hasSelect($locator) */ public function hasTable($locator) { - return $this->hasSelector('named', array( + return $this->has('named', array( 'table', $this->getSession()->getSelectorsHandler()->xpathLiteral($locator) )); } diff --git a/src/Behat/Mink/Element/Element.php b/src/Behat/Mink/Element/Element.php index 7f7bcaa49..6eff2b961 100644 --- a/src/Behat/Mink/Element/Element.php +++ b/src/Behat/Mink/Element/Element.php @@ -41,6 +41,14 @@ public function getSession() return $this->session; } + /** + * @see Behat\Mink\Element\ElementInterface::findAll() + */ + public function has($selector, $locator) + { + return null !== $this->find($selector, $locator); + } + /** * @see Behat\Mink\Element\ElementInterface::find() */ @@ -61,14 +69,6 @@ public function findAll($selector, $locator) ); } - /** - * @see Behat\Mink\Element\ElementInterface::findAll() - */ - public function hasSelector($selector, $locator) - { - return null !== $this->find($selector, $locator); - } - /** * Returns element text. * diff --git a/src/Behat/Mink/Element/ElementInterface.php b/src/Behat/Mink/Element/ElementInterface.php index 81815b180..56d7162c9 100644 --- a/src/Behat/Mink/Element/ElementInterface.php +++ b/src/Behat/Mink/Element/ElementInterface.php @@ -32,32 +32,32 @@ function getXpath(); function getSession(); /** - * Finds first element with specified selector. + * Checks whether element with specified selector exists. * * @param string $selector selector engine name * @param string $locator selector locator * - * @return Behat\Mink\Element\NodeElement|null + * @return Boolean */ - function find($selector, $locator); + function has($selector, $locator); /** - * Finds all elements with specified selector. + * Finds first element with specified selector. * * @param string $selector selector engine name * @param string $locator selector locator * - * @return array + * @return Behat\Mink\Element\NodeElement|null */ - function findAll($selector, $locator); + function find($selector, $locator); /** - * Checks whether element with specified selector exists. + * Finds all elements with specified selector. * * @param string $selector selector engine name * @param string $locator selector locator * - * @return Boolean + * @return array */ - function hasSelector($selector, $locator); + function findAll($selector, $locator); } diff --git a/src/Behat/Mink/Element/NodeElement.php b/src/Behat/Mink/Element/NodeElement.php index 016f317d5..0d321e552 100644 --- a/src/Behat/Mink/Element/NodeElement.php +++ b/src/Behat/Mink/Element/NodeElement.php @@ -51,7 +51,7 @@ public function getXpath() */ public function getText() { - return $this->getSession()->getDriver()->getText($this->getXpath()); + return trim($this->getSession()->getDriver()->getText($this->getXpath())); } /** diff --git a/tests/Behat/Mink/Driver/GeneralDriverTest.php b/tests/Behat/Mink/Driver/GeneralDriverTest.php index 3e27c8fc4..4ab374586 100644 --- a/tests/Behat/Mink/Driver/GeneralDriverTest.php +++ b/tests/Behat/Mink/Driver/GeneralDriverTest.php @@ -130,7 +130,7 @@ public function testPageControlls() $this->assertEquals(static::$host . '/randomizer.php', static::$session->getCurrentUrl()); } - public function testIndexPage() + public function testElementsTraversing() { static::$session->visit(static::$host . '/index.php'); @@ -155,6 +155,15 @@ public function testIndexPage() $this->assertEquals(3, count($strongs)); $this->assertEquals('Lorem', $strongs[0]->getText()); $this->assertEquals('pariatur', $strongs[2]->getText()); + + $element = $page->find('css', '#some-element'); + + $this->assertEquals('some interesting text', $element->getPlainText()); + $this->assertTrue($element->hasAttribute('data-href')); + $this->assertFalse($element->hasAttribute('data-url')); + $this->assertEquals('http://mink.behat.org', $element->getAttribute('data-href')); + $this->assertNull($element->getAttribute('data-url')); + $this->assertEquals('span', $element->getTagName()); } public function testLinks() @@ -277,7 +286,6 @@ public function testAdvancedForm() [agreement] => on ) 1 uploaded file - OUT , $page->getContent() ); diff --git a/tests/Behat/Mink/Driver/web-fixtures/advanced_form_post.php b/tests/Behat/Mink/Driver/web-fixtures/advanced_form_post.php index d29347a35..4e91701f5 100644 --- a/tests/Behat/Mink/Driver/web-fixtures/advanced_form_post.php +++ b/tests/Behat/Mink/Driver/web-fixtures/advanced_form_post.php @@ -2,7 +2,7 @@ Advanced form save - + Extremely useless page

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + + + some interesting text + +

diff --git a/tests/Behat/Mink/Element/DocumentElementTest.php b/tests/Behat/Mink/Element/DocumentElementTest.php index c26e62feb..f4c4e5a9e 100644 --- a/tests/Behat/Mink/Element/DocumentElementTest.php +++ b/tests/Behat/Mink/Element/DocumentElementTest.php @@ -138,8 +138,8 @@ public function testHasSelector() ->with($xpath = 'some xpath selector') ->will($this->onConsecutiveCalls(array('id2', 'id3'), array())); - $this->assertTrue($this->document->hasSelector('xpath', $xpath)); - $this->assertFalse($this->document->hasSelector('xpath', $xpath)); + $this->assertTrue($this->document->has('xpath', $xpath)); + $this->assertFalse($this->document->has('xpath', $xpath)); } public function testHasContent()