Last active
December 20, 2015 08:59
-
-
Save crisu83/6104577 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace Codeception\Module; | |
class CodeHelper extends \Codeception\Module | |
{ | |
/** | |
* @param \Symfony\Component\DomCrawler\Crawler $node | |
* @param string $text | |
*/ | |
public function seeNodeText($node, $text) | |
{ | |
$this->assertTrue(strpos($node->text(), $text) !== false); | |
} | |
/** | |
* @param \Symfony\Component\DomCrawler\Crawler $node | |
* @param mixed $cssClass | |
*/ | |
public function seeNodeCssClass($node, $cssClass) | |
{ | |
if (is_string($cssClass)) { | |
$cssClass = explode(' ', $cssClass); | |
} | |
foreach ($cssClass as $className) { | |
$this->assertTrue(in_array($className, explode(' ', $node->attr('class')))); | |
} | |
} | |
/** | |
* @param \Symfony\Component\DomCrawler\Crawler $node | |
* @param string $name | |
* @param string $value | |
*/ | |
public function seeNodeAttribute($node, $name, $value = null) | |
{ | |
$attr = $node->attr($name); | |
$this->assertNotEquals(null, $attr); | |
if ($value !== null) { | |
$this->assertEquals($value, $attr); | |
} | |
} | |
/** | |
* @param \Symfony\Component\DomCrawler\Crawler $node | |
* @param array $attributes | |
*/ | |
public function seeNodeAttributes($node, array $attributes) | |
{ | |
foreach ($attributes as $name => $value) { | |
$this->seeNodeAttribute($node, $name, $value); | |
} | |
} | |
/** | |
* @param \Symfony\Component\DomCrawler\Crawler $node | |
* @param array $elements | |
*/ | |
public function seeNodeChildren($node, array $elements) | |
{ | |
foreach ($node->children() as $i => $child) { | |
$this->assertEquals($elements[$i], $child->tagName); | |
} | |
} | |
/** | |
* @param string $content | |
* @param string $selector | |
* @return \Symfony\Component\DomCrawler\Crawler | |
*/ | |
public function createNode($content, $selector = null) | |
{ | |
$crawler = new \Symfony\Component\DomCrawler\\Crawler; | |
$crawler->addContent($content); | |
if ($selector !== null) { | |
$node = $crawler->filter($selector); | |
$this->assertNotEquals(null, $node); | |
return $node; | |
} | |
return $crawler; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment