From 071bd0cb0d9c312ed518635331e1307d146ddb56 Mon Sep 17 00:00:00 2001 From: aljcalandra Date: Mon, 7 May 2018 09:47:59 -0500 Subject: [PATCH] MQE-884: Show warning on generation when leave out .url attribute for amOnPage - Added Warning Line and unit test for said warning/conditional --- .../Test/Objects/ActionObjectTest.php | 36 +++++++++++++++++++ .../Test/Objects/ActionObject.php | 7 ++++ 2 files changed, 43 insertions(+) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php index b5aa8c4b1..8e3a1d579 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php @@ -191,6 +191,8 @@ public function testTimeoutFromElement() /** * {{PageObject.url}} should be replaced with someUrl.html + * + * @throws /Exception */ public function testResolveUrl() { @@ -213,6 +215,40 @@ public function testResolveUrl() $this->assertEquals($expected, $actionObject->getCustomActionAttributes()); } + /** + * {{PageObject}} should not be replaced and should elicit a warning in console + * + * @throws /Exception + */ + public function testResolveUrlWithNoAttribute() + { + // Set up mocks + $actionObject = new ActionObject('merge123', 'amOnPage', [ + 'url' => '{{PageObject}}' + ]); + $pageObject = new PageObject('PageObject', '/replacement/url.html', 'Test', [], false, "test"); + $pageObjectList = ["PageObject" => $pageObject]; + $instance = AspectMock::double( + PageObjectHandler::class, + ['getObject' => $pageObject, 'getAllObjects' => $pageObjectList] + )->make(); // bypass the private constructor + AspectMock::double(PageObjectHandler::class, ['getInstance' => $instance]); + + // Expect this warning to get generated + $this->expectOutputString( + "WARNING: Page url attribute not found for {{PageObject}} and is required for amOnPage." . PHP_EOL + ); + + // Call the method under test + $actionObject->resolveReferences(); + + // Verify + $expected = [ + 'url' => '{{PageObject}}' + ]; + $this->assertEquals($expected, $actionObject->getCustomActionAttributes()); + } + /** * {{PageObject.url(param)}} should be replaced */ diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index 87b8d0a12..e2bd106d1 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -372,6 +372,13 @@ private function resolveUrlReference() $replacement = $this->findAndReplaceReferences(PageObjectHandler::getInstance(), $url); if ($replacement) { $this->resolvedCustomAttributes[ActionObject::ACTION_ATTRIBUTE_URL] = $replacement; + $allPages = PageObjectHandler::getInstance()->getAllObjects(); + if ( + $replacement === $url + && array_key_exists(trim($url, "{}"), $allPages) + ) { + echo("WARNING: Page url attribute not found for ${url} and is required for $this->type." . PHP_EOL); + } } }