Skip to content

Commit

Permalink
Issue minkphp#816 - Add element attribute not exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
Murilo Pucci committed Dec 8, 2021
1 parent 8f86e44 commit 72f3d25
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/WebAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,32 @@ public function elementAttributeExists($selectorType, $selector, $attribute)
return $element;
}

/**
* Checks that an attribute does not exist in an element.
*
* @param string $selectorType
* @param string|array $selector
* @param string $attribute
*
* @return NodeElement
*
* @throws ElementHtmlException|ElementNotFoundException
*/
public function elementAttributeNotExists($selectorType, $selector, $attribute)
{
$element = $this->elementExists($selectorType, $selector);

$message = sprintf(
'The attribute "%s" was found in the %s.',
$attribute,
$this->getMatchingElementRepresentation($selectorType, $selector)
);

$this->assertElement(!$element->hasAttribute($attribute), $message, $element);

return $element;
}

/**
* Checks that an attribute of a specific elements contains text.
*
Expand Down
48 changes: 48 additions & 0 deletions tests/WebAssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,54 @@ public function testElementAttributeExists()
);
}

public function testElementAttributeNotExists()
{
$page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement')
->disableOriginalConstructor()
->getMock()
;

$element = $this->getMockBuilder('Behat\\Mink\\Element\\NodeElement')
->disableOriginalConstructor()
->getMock()
;

$this->session
->expects($this->exactly(2))
->method('getPage')
->will($this->returnValue($page))
;

$page
->expects($this->exactly(2))
->method('find')
->with('css', 'h2 > span')
->will($this->returnValue($element))
;

$element
->expects($this->at(0))
->method('hasAttribute')
->with('name')
->will($this->returnValue(false))
;

$element
->expects($this->at(1))
->method('hasAttribute')
->with('name')
->will($this->returnValue(true))
;

$this->assertCorrectAssertion('elementAttributeNotExists', array('css', 'h2 > span', 'name'));
$this->assertWrongAssertion(
'elementAttributeNotExists',
array('css', 'h2 > span', 'name'),
'Behat\\Mink\\Exception\\ElementHtmlException',
'The attribute "name" was found in the element matching css "h2 > span".'
);
}

public function testElementAttributeNotContains()
{
$page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement')
Expand Down

0 comments on commit 72f3d25

Please sign in to comment.