Skip to content

Commit 82f6beb

Browse files
committed
MQE-641: URL page should be dynamic and be able to retrieve information from .env file
- change the page object schema - update tests to reflect new object change
1 parent 2b5b2af commit 82f6beb

File tree

12 files changed

+94
-12
lines changed

12 files changed

+94
-12
lines changed

dev/tests/_bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
foreach ($TEST_ENVS as $key => $value) {
2727
$_ENV[$key] = $value;
28+
putenv("{$key}=${value}");
2829
}
2930

3031
// Add our test module to the whitelist

dev/tests/unit/Magento/FunctionalTestFramework/Page/Handlers/PageObjectHandlerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ public function testGetPageObject()
2424
"section" => [
2525
"someSection1" => [],
2626
"someSection2" => []
27-
]
27+
],
28+
"area" => "test"
2829
],
2930
"testPage2" => [
3031
"url" => "testURL2",
3132
"module" => "testModule2",
3233
"parameterized" => true,
3334
"section" => [
3435
"someSection1" => []
35-
]
36+
],
37+
"area" => "test"
3638
]];
3739
$this->setMockParserOutput($mockData);
3840

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class PageObjectTest extends TestCase
1919
*/
2020
public function testHasSection()
2121
{
22-
$page = new PageObject('name', 'urlPath', 'module', ['section1', 'section2'], false);
22+
$page = new PageObject('name', 'urlPath', 'module', ['section1', 'section2'], false, 'area');
2323
$this->assertTrue($page->hasSection('section1'));
2424
}
2525

@@ -28,7 +28,7 @@ public function testHasSection()
2828
*/
2929
public function testDoesntHaveSection()
3030
{
31-
$page = new PageObject('name', 'urlPath', 'module', ['section1', 'section2'], false);
31+
$page = new PageObject('name', 'urlPath', 'module', ['section1', 'section2'], false, 'area');
3232
$this->assertFalse($page->hasSection('section3'));
3333
}
3434
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function testResolveUrl()
198198
$actionObject = new ActionObject('merge123', 'amOnPage', [
199199
'url' => '{{PageObject.url}}'
200200
]);
201-
$pageObject = new PageObject('PageObject', '/replacement/url.html', 'Test', [], false);
201+
$pageObject = new PageObject('PageObject', '/replacement/url.html', 'Test', [], false, "test");
202202
$instance = AspectMock::double(PageObjectHandler::class, ['getObject' => $pageObject])
203203
->make(); // bypass the private constructor
204204
AspectMock::double(PageObjectHandler::class, ['getInstance' => $instance]);

dev/tests/verification/Resources/PageReplacementTest.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ class PageReplacementTestCest
3939
$I->amOnPage("/John/StringLiteral2.html");
4040
$I->amOnPage("/John/" . $datakey->getCreatedDataByName('firstname') . ".html");
4141
$I->amOnPage("/" . $datakey->getCreatedDataByName('firstname') . "/StringLiteral2.html");
42+
$I->amOnPage("/admin/backend");
43+
$I->amOnUrl("http://myFullUrl.com/");
4244
}
4345
}

dev/tests/verification/TestModule/Page/SamplePage.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88

99
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="../../../../../src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd">
11-
<page name="SamplePage" url="/{{var1}}/{{var2}}.html" module="SampleTests" parameterized="true">
11+
<page name="SamplePage" url="/{{var1}}/{{var2}}.html" area="storefront" module="SampleTests" parameterized="true">
1212
<section name="SampleSection"/>
1313
</page>
14-
<page name="NoParamPage" url="/page.html" module="SampleTests">
14+
<page name="NoParamPage" url="/page.html" area="storefront" module="SampleTests">
1515
<section name="SampleSection"/>
1616
</page>
17-
<page name="OneParamPage" url="/{{var1}}/page.html" module="SampleTests" parameterized="true">
17+
<page name="OneParamPage" url="/{{var1}}/page.html" area="storefront" module="SampleTests" parameterized="true">
1818
<section name="SampleSection"/>
1919
</page>
20-
<page name="TwoParamPage" url="/{{var1}}/{{var2}}.html" module="SampleTests" parameterized="true">
20+
<page name="TwoParamPage" url="/{{var1}}/{{var2}}.html" area="storefront" module="SampleTests" parameterized="true">
21+
<section name="SampleSection"/>
22+
</page>
23+
<page name="AdminPage" url="/backend" area="admin" module="SampleTests">
24+
<section name="SampleSection"/>
25+
</page>
26+
<page name="ExternalPage" url="http://myFullUrl.com/" area="external" module="SampleTests">
2127
<section name="SampleSection"/>
2228
</page>
2329
</pages>

dev/tests/verification/TestModule/Test/PageReplacementTest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@
1818
<amOnPage stepKey="twoParamPageStringData" url="{{TwoParamPage.url(simpleData.firstname, 'StringLiteral2')}}"/>
1919
<amOnPage stepKey="twoParamPageDataPersist" url="{{TwoParamPage.url(simpleData.firstname, $datakey.firstname$)}}"/>
2020
<amOnPage stepKey="twoParamPagePersistString" url="{{TwoParamPage.url($datakey.firstname$, 'StringLiteral2')}}"/>
21+
<amOnPage stepKey="onAdminPage" url="{{AdminPage.url}}"/>
22+
<amOnUrl stepKey="onExternalPage" url="{{ExternalPage.url}}"/>
23+
</test>
24+
<test name="ExternalPageTestBadReference">
25+
<amOnPage stepKey="onExternalPage" url="{{ExternalPage.url}}"/>
2126
</test>
2227
</tests>

dev/tests/verification/Tests/ReferenceReplacementGenerationTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
*/
66
namespace tests\verification\Tests;
77

8+
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
89
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
910
use Magento\FunctionalTestingFramework\Util\TestGenerator;
1011
use PHPUnit\Framework\TestCase;
11-
use tests\verification\Util\FileDiffUtil;
1212

1313
class ReferenceReplacementGenerationTest extends TestCase
1414
{
1515
const DATA_REPLACEMENT_TEST = 'DataReplacementTest';
1616
const PERSISTED_REPLACEMENT_TEST = 'PersistedReplacementTest';
1717
const PAGE_REPLACEMENT_TEST = 'PageReplacementTest';
18+
const ADMIN_PAGE_TEST = 'AdminPageTest';
1819
const SECTION_REPLACEMENT_TEST = 'SectionReplacementTest';
1920
const RESOURCES_PATH = __DIR__ . '/../Resources';
2021

@@ -51,6 +52,15 @@ public function testPageReferenceReplacementCest()
5152
$this->runComparisonTest(self::PAGE_REPLACEMENT_TEST);
5253
}
5354

55+
/**
56+
* Tests replacement of {{page.url}} reference for external page and incompatible action
57+
*/
58+
public function testExternalPageBadReference()
59+
{
60+
$this->expectException(TestReferenceException::class);
61+
$this->runComparisonTest("ExternalPageTestBadReference");
62+
}
63+
5464
/**
5565
* Tests replacement of {{Section.Element}} references. Includes parameterized elements.
5666
*

src/Magento/FunctionalTestingFramework/Page/Handlers/PageObjectHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class PageObjectHandler implements ObjectHandlerInterface
1818
const URL = 'url';
1919
const MODULE = 'module';
2020
const PARAMETERIZED = 'parameterized';
21+
const AREA = 'area';
2122

2223
/**
2324
* The singleton instance of this class
@@ -52,7 +53,9 @@ private function __construct()
5253
$module = $pageData[self::MODULE];
5354
$sectionNames = array_keys($pageData[self::SECTION]);
5455
$parameterized = $pageData[self::PARAMETERIZED] ?? false;
55-
$this->pageObjects[$pageName] = new PageObject($pageName, $url, $module, $sectionNames, $parameterized);
56+
$area = $pageData[self::AREA];
57+
$this->pageObjects[$pageName] =
58+
new PageObject($pageName, $url, $module, $sectionNames, $parameterized, $area);
5659
}
5760
}
5861

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
class PageObject
1616
{
17+
const ADMIN_AREA = 'admin';
18+
1719
/**
1820
* Page name
1921
*
@@ -49,21 +51,30 @@ class PageObject
4951
*/
5052
private $sectionNames = [];
5153

54+
/**
55+
* String identifying the area the page belongs to
56+
*
57+
* @var string
58+
*/
59+
private $area;
60+
5261
/**
5362
* PageObject constructor.
5463
* @param string $name
5564
* @param string $url
5665
* @param string $module
5766
* @param array $sections
5867
* @param bool $parameterized
68+
* @param string $area
5969
*/
60-
public function __construct($name, $url, $module, $sections, $parameterized)
70+
public function __construct($name, $url, $module, $sections, $parameterized, $area)
6171
{
6272
$this->name = $name;
6373
$this->url = $url;
6474
$this->module = $module;
6575
$this->sectionNames = $sections;
6676
$this->parameterized = $parameterized;
77+
$this->area = $area;
6778
}
6879

6980
/**
@@ -83,6 +94,11 @@ public function getName()
8394
*/
8495
public function getUrl()
8596
{
97+
if ($this->getArea() == self::ADMIN_AREA) {
98+
$url = ltrim($this->url, '/');
99+
return "/" . getenv('MAGENTO_BACKEND_NAME') . "/{$url}";
100+
}
101+
86102
return $this->url;
87103
}
88104

@@ -96,6 +112,16 @@ public function getModule()
96112
return $this->module;
97113
}
98114

115+
/**
116+
* Getter for Page Area
117+
*
118+
* @return string
119+
*/
120+
public function getArea()
121+
{
122+
return $this->area;
123+
}
124+
99125
/**
100126
* Getter for Section Names
101127
*

src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
</xs:annotation>
6464
</xs:attribute>
6565
<xs:attribute type="xs:boolean" name="parameterized" use="optional"/>
66+
<xs:attribute type="pageArea" name="area" use="required"/>
6667
<xs:attributeGroup ref="removeAttribute"/>
6768
</xs:complexType>
6869
</xs:element>
@@ -95,4 +96,12 @@
9596
</xs:annotation>
9697
</xs:attribute>
9798
</xs:attributeGroup>
99+
100+
<xs:simpleType name="pageArea" final="restriction" >
101+
<xs:restriction base="xs:string">
102+
<xs:enumeration value="admin" />
103+
<xs:enumeration value="storefront" />
104+
<xs:enumeration value="external" />
105+
</xs:restriction>
106+
</xs:simpleType>
98107
</xs:schema>

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ActionObject
2121
{
2222
const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray"];
2323
const SELECTOR_ENABLED_ATTRIBUTES = ['selector', 'dependentSelector', "selector1", "selector2", "function"];
24+
const EXTERNAL_URL_AREA_INVALID_ACTIONS = ['amOnPage'];
2425
const MERGE_ACTION_ORDER_AFTER = 'after';
2526
const MERGE_ACTION_ORDER_BEFORE = 'before';
2627
const ACTION_ATTRIBUTE_URL = 'url';
@@ -332,6 +333,7 @@ private function findAndReplaceReferences($objectHandler, $inputString)
332333
// specify behavior depending on field
333334
switch (get_class($obj)) {
334335
case PageObject::class:
336+
$this->validateUrlAreaAgainstActionType($obj);
335337
$replacement = $obj->getUrl();
336338
$parameterized = $obj->isParameterized();
337339
break;
@@ -361,6 +363,22 @@ private function findAndReplaceReferences($objectHandler, $inputString)
361363
return $outputString;
362364
}
363365

366+
/**
367+
* Validates the page objects area 'external' against a list of known incompatible types
368+
*
369+
* @param PageObject $obj
370+
* @throws TestReferenceException
371+
*/
372+
private function validateUrlAreaAgainstActionType($obj)
373+
{
374+
if ($obj->getArea() == 'external' &&
375+
in_array($this->getType(), self::EXTERNAL_URL_AREA_INVALID_ACTIONS)) {
376+
throw new TestReferenceException(
377+
"Page of type 'external' is not compatible with action type '{$this->getType()}'"
378+
);
379+
}
380+
}
381+
364382
/**
365383
* Determines whether the given $inputString has (params), and returns the appropriate regex for use in matching.
366384
* @param string $inputString

0 commit comments

Comments
 (0)