-
-
Save megclaypool/da2485541a765d12018f71fc29e07ecb to your computer and use it in GitHub Desktop.
Behat tests for checkout css properties
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 | |
/** | |
* @Given /^The element "(?P<selector>[^"]*)" should have a css property "(?P<property>[^"]*)" with a value of "(?P<value>[^"]*)"$/ | |
* | |
* @TODO Need to find a way to test for css styles on elements. | |
* Or possibly we should just be checking the markup, and not the styling... Research this more. | |
*/ | |
public function assertElementHasCssValue($selector, $property, $value) | |
{ | |
$page = $this->getSession()->getPage(); | |
$element = $page->find('css', $selector); | |
if (empty($element)) { | |
$message = sprintf('Could not find element using the selector "%s"', $selector); | |
throw new \Exception($message); | |
} | |
$style = $this->elementHasCSSValue($element, $property, $value); | |
if (empty($style)) { | |
$message = sprintf('The property "%s" for the selector "%s" is not "%s"', $property, $selector, $value); | |
throw new \Exception($message); | |
} | |
} | |
/** | |
* Determine if a Mink NodeElement contains a specific css rule attribute value. | |
* | |
* @param NodeElement $element | |
* NodeElement previously selected with $this->getSession()->getPage()->find(). | |
* @param string $property | |
* Name of the CSS property, such as "visibility". | |
* @param string $value | |
* Value of the specified rule, such as "hidden". | |
* | |
* @return NodeElement|bool | |
* The NodeElement selected if true, FALSE otherwise. | |
*/ | |
protected function elementHasCSSValue($element, $property, $value) | |
{ | |
$exists = FALSE; | |
$style = $element->getAttribute('style'); | |
if ($style) { | |
if (preg_match("/(^{$property}:|; {$property}:) ([a-z0-9]+);/i", $style, $matches)) { | |
$found = array_pop($matches); | |
if ($found == $value) { | |
$exists = $element; | |
} | |
} | |
} | |
return $exists; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment