Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 48 |
CRAP | |
0.00% |
0 / 315 |
Mink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 48 |
9702 | |
0.00% |
0 / 315 |
_initialize() | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 10 |
|||
_before(\Codeception\TestCase $test) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
_after(\Codeception\TestCase $test) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
_getUrl() | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
|||
_setHeader($header, $value) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
_setCookie($cookie, $value) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
_getResponseHeader($header) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
|||
_getResponseCode() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
_sendRequest($url) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
amOnPage($page) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
dontSee($text, $selector = null) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
see($text, $selector = null) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
proceedSee($text, $selector = null) | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 17 |
|||
seeLink($text, $url = null) | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 20 |
|||
dontSeeLink($text, $url = null) | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 18 |
|||
click($link, $context = null) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 8 |
|||
seeElement($selector) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
dontSeeElement($selector) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 9 |
|||
findEl($selector) | |
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 15 |
|||
findLinkByContent($link) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
findClickable($link, $context = null) | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 14 |
|||
reloadPage() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
moveBack() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
moveForward() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
fillField($field, $value) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
selectOption($select, $option) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
checkOption($option) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
uncheckOption($option) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
findField($selector) | |
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 13 |
|||
_getCurrentUri() | |
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 11 |
|||
seeInCurrentUrl($uri) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
dontSeeInCurrentUrl($uri) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
seeCurrentUrlEquals($uri) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
dontSeeCurrentUrlEquals($uri) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
seeCurrentUrlMatches($uri) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
dontSeeCurrentUrlMatches($uri) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
grabFromCurrentUrl($uri = null) | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 9 |
|||
attachFile($field, $filename) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
|||
seeOptionIsSelected($select, $option) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
dontSeeOptionIsSelected($select, $option) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
seeCheckboxIsChecked($checkbox) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 5 |
|||
dontSeeCheckboxIsChecked($checkbox) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 5 |
|||
seeInField($field, $value) | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 5 |
|||
dontSeeInField($field, $value) | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 5 |
|||
grabTextFrom($cssOrXPathOrRegex) | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 13 |
|||
grabValueFrom($field) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 7 |
|||
grabAttribute() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
escape($string) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
<?php | |
namespace Codeception\Util; | |
abstract class Mink extends \Codeception\Module implements RemoteInterface, WebInterface | |
{ | |
/** | |
* @var \Behat\Mink\Session | |
*/ | |
public $session = null; | |
public function _initialize() { | |
if (!$this->session) throw new \Codeception\Exception\Module(__CLASS__, "Module is not initialized. Mink session is not started in _initialize method of module.");; | |
try { | |
$this->session->start(); | |
$this->session->visit($this->config['url'].'/'); | |
$this->session->stop(); | |
} catch (\Exception $e) { | |
throw new \Codeception\Exception\ModuleConfig(__CLASS__, "Provided URL can't be accessed by this driver." . $e->getMessage()); | |
} | |
} | |
public function _before(\Codeception\TestCase $test) | |
{ | |
if ($this->session) $this->session->start(); | |
} | |
public function _after(\Codeception\TestCase $test) { | |
if ($this->session) $this->session->stop(); | |
} | |
public function _getUrl() | |
{ | |
if (!isset($this->config['url'])) | |
throw new \Codeception\Exception\ModuleConfig(__CLASS__, "Module connection failure. The URL for client can't bre retrieved"); | |
return $this->config['url']; | |
} | |
public function _setHeader($header, $value) | |
{ | |
$this->session->setRequestHeader($header, $value); | |
} | |
public function _setCookie($cookie, $value) | |
{ | |
$this->session->setCookie($cookie, $value); | |
} | |
public function _getResponseHeader($header) | |
{ | |
$headers = $this->session->getResponseHeaders(); | |
if (!isset($headers[$header])) return false; | |
return $headers[$header]; | |
} | |
public function _getResponseCode() | |
{ | |
return $this->session->getStatusCode(); | |
} | |
public function _sendRequest($url) | |
{ | |
$this->session->visit($url); | |
return $this->session->getDriver()->getContent(); | |
} | |
/** | |
* Opens the page. | |
* | |
* @param $page | |
*/ | |
public function amOnPage($page) | |
{ | |
$this->session->visit($this->config['url'].$page); | |
} | |
public function dontSee($text, $selector = null) { | |
$res = $this->proceedSee($text, $selector); | |
$this->assertNot($res); | |
} | |
public function see($text, $selector = null) { | |
$res = $this->proceedSee($text, $selector); | |
$this->assert($res); | |
} | |
protected function proceedSee($text, $selector = null) { | |
if ($selector) { | |
try { | |
$nodes = $this->session->getPage()->findAll('css', $selector); | |
} catch (\Symfony\Component\CssSelector\Exception\ParseException $e) { | |
$nodes = $this->session->getPage()->findAll('xpath', $selector); | |
} | |
$values = ''; | |
foreach ($nodes as $node) { | |
$values .= '<!-- Merged Output -->'.$node->getText(); | |
} | |
return array('pageContains', $this->escape($text), $values, "'$selector' selector."); | |
} | |
$response = $this->session->getPage()->getText(); | |
$output = Framework::formatResponse($response); | |
return array('pageContains', $this->escape($text), $response, "'$text' in ".$output.'.'); | |
} | |
public function seeLink($text, $url = null) | |
{ | |
$text = $this->escape($text); | |
$nodes = $this->session->getPage()->findAll( | |
'named', array( | |
'link', $this->session->getSelectorsHandler()->xpathLiteral($text) | |
) | |
); | |
if (!$url) { | |
return \PHPUnit_Framework_Assert::assertNotEmpty($nodes); | |
} | |
foreach ($nodes as $node) { | |
if (false !== strpos($node->getAttribute('href'), $url)) { | |
return \PHPUnit_Framework_Assert::assertContains( | |
$text, $node->getHtml(), "with url '{$url}'" | |
); | |
} | |
} | |
return \PHPUnit_Framework_Assert::fail("with url '{$url}'"); | |
} | |
public function dontSeeLink($text, $url = null) | |
{ | |
if (!$url) { | |
return $this->dontSee($text, 'a'); | |
} | |
$text = $this->escape($text); | |
$nodes = $this->session->getPage()->findAll( | |
'named', array( | |
'link', $this->session->getSelectorsHandler()->xpathLiteral($text) | |
) | |
); | |
foreach ($nodes as $node) { | |
if (false !== strpos($node->getAttribute('href'), $url)) { | |
return \PHPUnit_Framework_Assert::fail("with url '$url'"); | |
} | |
} | |
return \PHPUnit_Framework_Assert::assertTrue(true, "with url '$url'"); | |
} | |
public function click($link, $context = null) { | |
$url = $this->session->getCurrentUrl(); | |
$el = $this->findClickable($link, $context); | |
$el->click(); | |
if ($this->session->getCurrentUrl() != $url) { | |
$this->debug('moved to page '. $this->session->getCurrentUrl()); | |
} | |
} | |
public function seeElement($selector) | |
{ | |
$el = $this->findEl($selector); | |
$this->assertNotEmpty($el); | |
} | |
public function dontSeeElement($selector) | |
{ | |
$el = array(); | |
try{ | |
$el = $this->findEl($selector); | |
} catch (\PHPUnit_Framework_AssertionFailedError $e) { | |
} | |
$this->assertEmpty($el); | |
} | |
/** | |
* @param $selector | |
* @return \Behat\Mink\Element\NodeElement | |
*/ | |
protected function findEl($selector) | |
{ | |
$page = $this->session->getPage(); | |
$el = null; | |
try { | |
\Symfony\Component\CssSelector\CssSelector::toXPath($selector); | |
$el = $page->find('css', $selector); | |
} catch (\Symfony\Component\CssSelector\Exception\ParseException $e) {} | |
try { | |
if (!$el) $el = @$page->find('xpath',$selector); | |
} catch (\Exception $e) { | |
} | |
if (!$el) \PHPUnit_Framework_Assert::fail("CSS or XPath for '$selector' not found'"); | |
return $el; | |
} | |
protected function findLinkByContent($link) | |
{ | |
$literal = $this->session->getSelectorsHandler()->xpathLiteral($link); | |
return $this->session->getPage()->find('xpath','.//a[.='.$literal.']'); // search by strict match | |
} | |
protected function findClickable($link, $context = null) | |
{ | |
$page = $context | |
? $this->findEl($context) | |
: $this->session->getPage(); | |
if (!$page) { | |
$this->fail("Context element $context not found"); | |
} | |
$el = $this->findLinkByContent($link); | |
if (!$el) $el = $page->findLink($link); | |
if (!$el) $el = $page->findButton($link); | |
if (!$el) $el = $this->findEl($link); | |
return $el; | |
} | |
/** | |
* Reloads current page | |
*/ | |
public function reloadPage() { | |
$this->session->reload(); | |
} | |
/** | |
* Moves back in history | |
*/ | |
public function moveBack() { | |
$this->session->back(); | |
$this->debug($this->session->getCurrentUrl()); | |
} | |
/** | |
* Moves forward in history | |
*/ | |
public function moveForward() { | |
$this->session->forward(); | |
$this->debug($this->session->getCurrentUrl()); | |
} | |
public function fillField($field, $value) | |
{ | |
$field = $this->findField($field); | |
$field->setValue($value); | |
} | |
public function selectOption($select, $option) | |
{ | |
$field = $this->findField($select); | |
$field->selectOption($option); | |
} | |
public function checkOption($option) | |
{ | |
$field = $this->findField($option); | |
$field->check(); | |
} | |
public function uncheckOption($option) | |
{ | |
$field = $this->findField($option); | |
$field->uncheck(); | |
} | |
/** | |
* @param $selector | |
* @return \Behat\Mink\Element\NodeElement | |
*/ | |
protected function findField($selector) | |
{ | |
$page = $this->session->getPage(); | |
$field = $page->find('named', array( | |
'field', $this->session->getSelectorsHandler()->xpathLiteral($selector) | |
)); | |
try { | |
if (!$field) $field = $page->find('css', $selector); | |
} catch (\Symfony\Component\CssSelector\Exception\ParseException $e) {} | |
if (!$field) $field = @$page->find('xpath', $selector); | |
if (!$field) \PHPUnit_Framework_Assert::fail("Field matching id|name|label|value or css or xpath selector does not exist"); | |
return $field; | |
} | |
public function _getCurrentUri() | |
{ | |
$url = $this->session->getCurrentUrl(); | |
$parts = parse_url($url); | |
if (!$parts) $this->fail("URL couldn't be parsed"); | |
$uri = ""; | |
if (isset($parts['path'])) $uri .= $parts['path']; | |
if (isset($parts['query'])) $uri .= "?".$parts['query']; | |
if (isset($parts['fragment'])) $uri .= "#".$parts['fragment']; | |
return $uri; | |
} | |
public function seeInCurrentUrl($uri) { | |
\PHPUnit_Framework_Assert::assertContains($uri, $this->_getCurrentUri()); | |
} | |
public function dontSeeInCurrentUrl($uri) | |
{ | |
\PHPUnit_Framework_Assert::assertNotContains($uri, $this->_getCurrentUri()); | |
} | |
public function seeCurrentUrlEquals($uri) | |
{ | |
\PHPUnit_Framework_Assert::assertEquals($uri, $this->_getCurrentUri()); | |
} | |
public function dontSeeCurrentUrlEquals($uri) | |
{ | |
\PHPUnit_Framework_Assert::assertNotEquals($uri, $this->_getCurrentUri()); | |
} | |
public function seeCurrentUrlMatches($uri) | |
{ | |
\PHPUnit_Framework_Assert::assertRegExp($uri, $this->_getCurrentUri()); | |
} | |
public function dontSeeCurrentUrlMatches($uri) | |
{ | |
\PHPUnit_Framework_Assert::assertNotRegExp($uri, $this->_getCurrentUri()); | |
} | |
public function grabFromCurrentUrl($uri = null) | |
{ | |
if (!$uri) return $this->session->getCurrentUrl(); | |
$matches = array(); | |
$res = preg_match($uri, $this->session->getCurrentUrl(), $matches); | |
if (!$res) $this->fail("Couldn't match $uri in ".$this->session->getCurrentUrl()); | |
if (!isset($matches[1])) $this->fail("Nothing to grab. A regex parameter required. Ex: '/user/(\\d+)'"); | |
return $matches[1]; | |
} | |
public function attachFile($field, $filename) { | |
$field = $this->findField($field); | |
$path = \Codeception\Configuration::dataDir().$filename; | |
if (!file_exists($path)) \PHPUnit_Framework_Assert::fail("file $filename not found in Codeception data path. Only files stored in data path accepted"); | |
$field->attachFile($path); | |
} | |
public function seeOptionIsSelected($select, $option) | |
{ | |
$this->see($option, "$select option[selected]"); | |
} | |
public function dontSeeOptionIsSelected($select, $option) | |
{ | |
$this->dontSee($option, "$select option[selected]"); | |
} | |
public function seeCheckboxIsChecked($checkbox) { | |
$node = $this->findField($checkbox); | |
if (!$node) return \PHPUnit_Framework_Assert::fail(", checkbox not found"); | |
\PHPUnit_Framework_Assert::assertTrue($node->isChecked()); | |
} | |
public function dontSeeCheckboxIsChecked($checkbox) { | |
$node = $this->findField($checkbox); | |
if (!$node) return \PHPUnit_Framework_Assert::fail(", checkbox not found"); | |
\PHPUnit_Framework_Assert::assertFalse($node->isChecked()); | |
} | |
public function seeInField($field, $value) { | |
$node = $this->findField($field); | |
if (!$node) return \PHPUnit_Framework_Assert::fail(", field not found"); | |
$this->assertEquals($value, $node->getTagName() == 'textarea' ? $node->getText() : $node->getAttribute('value')); | |
} | |
public function dontSeeInField($field, $value) { | |
$node = $this->findField($field); | |
if (!$node) return \PHPUnit_Framework_Assert::fail(", field not found"); | |
$this->assertNotEquals($value, $node->getTagName() == 'textarea' ? $node->getText() : $node->getAttribute('value')); | |
} | |
public function grabTextFrom($cssOrXPathOrRegex) { | |
$el = null; | |
try { | |
$el = $this->session->getPage()->find('css', $cssOrXPathOrRegex); | |
} catch (\Symfony\Component\CssSelector\Exception\ParseException $e) {} | |
if ($el) return $el->getText(); | |
if (!$el) $el = @$this->session->getPage()->find('xpath', $cssOrXPathOrRegex); | |
if ($el) return $el->getText(); | |
if (@preg_match($cssOrXPathOrRegex, $this->session->getPage()->getContent(), $matches)) { | |
return $matches[1]; | |
} | |
$this->fail("Element that matches '$cssOrXPathOrRegex' not found"); | |
} | |
public function grabValueFrom($field) { | |
$el = $this->findField($field); | |
if ($el) { | |
return $el->getValue(); | |
} | |
$this->fail("Element '$field' not found"); | |
} | |
public function grabAttribute() { | |
} | |
protected function escape($string) | |
{ | |
return $string; | |
} | |
} |