Skip to content

Commit 34c0ae0

Browse files
authored
Merge pull request #817 from murilohpucci/feature/element-attribute-not-exists
Add element attribute not exists
2 parents 8f86e44 + a27946b commit 34c0ae0

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

src/WebAssert.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,32 @@ public function elementAttributeExists($selectorType, $selector, $attribute)
565565
return $element;
566566
}
567567

568+
/**
569+
* Checks that an attribute does not exist in an element.
570+
*
571+
* @param string $selectorType
572+
* @param string|array $selector
573+
* @param string $attribute
574+
*
575+
* @return NodeElement
576+
*
577+
* @throws ElementHtmlException
578+
*/
579+
public function elementAttributeNotExists($selectorType, $selector, $attribute)
580+
{
581+
$element = $this->elementExists($selectorType, $selector);
582+
583+
$message = sprintf(
584+
'The attribute "%s" was found in the %s.',
585+
$attribute,
586+
$this->getMatchingElementRepresentation($selectorType, $selector)
587+
);
588+
589+
$this->assertElement(!$element->hasAttribute($attribute), $message, $element);
590+
591+
return $element;
592+
}
593+
568594
/**
569595
* Checks that an attribute of a specific elements contains text.
570596
*

tests/WebAssertTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,54 @@ public function testElementAttributeExists()
10871087
);
10881088
}
10891089

1090+
public function testElementAttributeNotExists()
1091+
{
1092+
$page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement')
1093+
->disableOriginalConstructor()
1094+
->getMock()
1095+
;
1096+
1097+
$element = $this->getMockBuilder('Behat\\Mink\\Element\\NodeElement')
1098+
->disableOriginalConstructor()
1099+
->getMock()
1100+
;
1101+
1102+
$this->session
1103+
->expects($this->exactly(2))
1104+
->method('getPage')
1105+
->will($this->returnValue($page))
1106+
;
1107+
1108+
$page
1109+
->expects($this->exactly(2))
1110+
->method('find')
1111+
->with('css', 'h2 > span')
1112+
->will($this->returnValue($element))
1113+
;
1114+
1115+
$element
1116+
->expects($this->at(0))
1117+
->method('hasAttribute')
1118+
->with('name')
1119+
->will($this->returnValue(false))
1120+
;
1121+
1122+
$element
1123+
->expects($this->at(1))
1124+
->method('hasAttribute')
1125+
->with('name')
1126+
->will($this->returnValue(true))
1127+
;
1128+
1129+
$this->assertCorrectAssertion('elementAttributeNotExists', array('css', 'h2 > span', 'name'));
1130+
$this->assertWrongAssertion(
1131+
'elementAttributeNotExists',
1132+
array('css', 'h2 > span', 'name'),
1133+
'Behat\\Mink\\Exception\\ElementHtmlException',
1134+
'The attribute "name" was found in the element matching css "h2 > span".'
1135+
);
1136+
}
1137+
10901138
public function testElementAttributeNotContains()
10911139
{
10921140
$page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement')

0 commit comments

Comments
 (0)