Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
implemented traversing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed Jul 16, 2011
1 parent 5ab151b commit ba976ed
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 28 deletions.
5 changes: 4 additions & 1 deletion src/Behat/Mink/Driver/GoutteDriver.php
Expand Up @@ -200,7 +200,10 @@ public function getStatusCode()
*/
public function getContent()
{
return $this->client->getResponse()->getContent();
$content = $this->client->getResponse()->getContent();
$content = preg_replace('/^.*\<html[^\>]*\>/is', '<html>', $content);

return $content;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Behat/Mink/Element/DocumentElement.php
Expand Up @@ -32,7 +32,7 @@ public function getXpath()
*/
public function getContent()
{
return $this->getSession()->getDriver()->getContent();
return trim($this->getSession()->getDriver()->getContent());
}

/**
Expand All @@ -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)
));
}
Expand Down Expand Up @@ -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)
));
}
Expand All @@ -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)
));
}
Expand Down
16 changes: 8 additions & 8 deletions src/Behat/Mink/Element/Element.php
Expand Up @@ -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()
*/
Expand All @@ -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.
*
Expand Down
18 changes: 9 additions & 9 deletions src/Behat/Mink/Element/ElementInterface.php
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/Behat/Mink/Element/NodeElement.php
Expand Up @@ -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()));
}

/**
Expand Down
12 changes: 10 additions & 2 deletions tests/Behat/Mink/Driver/GeneralDriverTest.php
Expand Up @@ -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');

Expand All @@ -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()
Expand Down Expand Up @@ -277,7 +286,6 @@ public function testAdvancedForm()
[agreement] => on
)
1 uploaded file
OUT
, $page->getContent()
);
Expand Down
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>Advanced form save</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
<?php
Expand Down
5 changes: 5 additions & 0 deletions tests/Behat/Mink/Driver/web-fixtures/index.php
Expand Up @@ -8,6 +8,11 @@
<h1>Extremely useless page</h1>
<p>
<strong>Lorem</strong> ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim <strong>veniam</strong>, 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 <strong class="super-duper">pariatur</strong>. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<span id="some-element" data-href="http://mink.behat.org">
some interesting text
</span>
</p>
</body>
</html>
4 changes: 2 additions & 2 deletions tests/Behat/Mink/Element/DocumentElementTest.php
Expand Up @@ -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()
Expand Down

0 comments on commit ba976ed

Please sign in to comment.