Skip to content

Instantly share code, notes, and snippets.

@delphian
Created August 17, 2013 05:01
Show Gist options
  • Save delphian/6255353 to your computer and use it in GitHub Desktop.
Save delphian/6255353 to your computer and use it in GitHub Desktop.
Determine if a Mink NodeElement contains a specific css rule attribute value.
/**
* 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 $rule
* Name of the CSS rule, 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, $rule, $value)
{
$exists = FALSE;
$style = $element->getAttribute('style');
if ($style) {
if (preg_match("/(^{$rule}:|; {$rule}:) ([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