Skip to content

Commit 1bedd14

Browse files
authored
MQE-884: Show warning on generation when leave out .url attribute for amOnPage (#127)
- Added Warning Line and unit test for said warning/conditional
1 parent 15d7407 commit 1bedd14

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ public function testTimeoutFromElement()
191191

192192
/**
193193
* {{PageObject.url}} should be replaced with someUrl.html
194+
*
195+
* @throws /Exception
194196
*/
195197
public function testResolveUrl()
196198
{
@@ -213,6 +215,40 @@ public function testResolveUrl()
213215
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
214216
}
215217

218+
/**
219+
* {{PageObject}} should not be replaced and should elicit a warning in console
220+
*
221+
* @throws /Exception
222+
*/
223+
public function testResolveUrlWithNoAttribute()
224+
{
225+
// Set up mocks
226+
$actionObject = new ActionObject('merge123', 'amOnPage', [
227+
'url' => '{{PageObject}}'
228+
]);
229+
$pageObject = new PageObject('PageObject', '/replacement/url.html', 'Test', [], false, "test");
230+
$pageObjectList = ["PageObject" => $pageObject];
231+
$instance = AspectMock::double(
232+
PageObjectHandler::class,
233+
['getObject' => $pageObject, 'getAllObjects' => $pageObjectList]
234+
)->make(); // bypass the private constructor
235+
AspectMock::double(PageObjectHandler::class, ['getInstance' => $instance]);
236+
237+
// Expect this warning to get generated
238+
$this->expectOutputString(
239+
"WARNING: Page url attribute not found for {{PageObject}} and is required for amOnPage." . PHP_EOL
240+
);
241+
242+
// Call the method under test
243+
$actionObject->resolveReferences();
244+
245+
// Verify
246+
$expected = [
247+
'url' => '{{PageObject}}'
248+
];
249+
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
250+
}
251+
216252
/**
217253
* {{PageObject.url(param)}} should be replaced
218254
*/

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,13 @@ private function resolveUrlReference()
372372
$replacement = $this->findAndReplaceReferences(PageObjectHandler::getInstance(), $url);
373373
if ($replacement) {
374374
$this->resolvedCustomAttributes[ActionObject::ACTION_ATTRIBUTE_URL] = $replacement;
375+
$allPages = PageObjectHandler::getInstance()->getAllObjects();
376+
if (
377+
$replacement === $url
378+
&& array_key_exists(trim($url, "{}"), $allPages)
379+
) {
380+
echo("WARNING: Page url attribute not found for ${url} and is required for $this->type." . PHP_EOL);
381+
}
375382
}
376383
}
377384

0 commit comments

Comments
 (0)