Skip to content

Commit a053dd0

Browse files
committed
MQE-421: Create Unit Tests for the object model
- Add a test for both selector and locatorFunction null
1 parent f3848f1 commit a053dd0

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Page/Objects/ElementObjectTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,21 @@ public function testTimeoutCastFromString()
4646
$this->assertInternalType('int', $timeout);
4747
}
4848

49-
5049
/**
5150
* An exception should be thrown if both a selector and locatorFunction are passed
5251
*/
5352
public function testBothSelectorAndLocatorFunction()
5453
{
5554
$this->expectException(XmlException::class);
56-
new ElementObject('name', 'type', 'selector', 'cantDoThis', 'helloString', true);
55+
new ElementObject('name', 'type', 'selector', 'cantHaveThisAndSelector', '-', false);
56+
}
57+
58+
/**
59+
* An exception should be thrown if neither a selector nor locatorFunction are passed
60+
*/
61+
public function testNeitherSelectorNorLocatorFunction()
62+
{
63+
$this->expectException(XmlException::class);
64+
new ElementObject('name', 'type', null, null, '-', false);
5765
}
5866
}

src/Magento/FunctionalTestingFramework/Page/Objects/ElementObject.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ class ElementObject
6868
*/
6969
public function __construct($name, $type, $selector, $locatorFunction, $timeout, $parameterized)
7070
{
71-
//Elements cannot have both a selector and a locatorFunction defined
7271
if ($selector != null && $locatorFunction != null) {
7372
throw new XmlException("Element '{$name}' cannot have both a selector and a locatorFunction.");
73+
} elseif ($selector == null && $locatorFunction == null) {
74+
throw new XmlException("Element '{$name}' must have either a selector or a locatorFunction.'");
7475
}
7576

7677
$this->name = $name;

0 commit comments

Comments
 (0)