Skip to content

Commit 33823bc

Browse files
committed
Merge remote-tracking branch 'origin/MQE-187-XML_to_PHP_prototype' into develop
# Conflicts: # etc/di.xml
2 parents d8fdf10 + 7be7497 commit 33823bc

File tree

12 files changed

+1107
-5
lines changed

12 files changed

+1107
-5
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MAGENTO_ADMIN_USERNAME=admin
2+
MAGENTO_ADMIN_PASSWORD=test123
3+
TESTS_BP=/Users/dev/somepath/magento2ce-acceptance-tests
4+
FW_BP=/Users/dev/somepath/magento2-acceptance-test-framework

etc/di.xml

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@
6767
</argument>
6868
</arguments>
6969
</type>
70-
<type name="Magento\AcceptanceTestFramework\DataProfileSchemaParser">
71-
<arguments>
72-
<argument name="dataProfiles" xsi:type="object">Magento\AcceptanceTestFramework\DataProfile\Config\Data</argument>
73-
</arguments>
74-
</type>
7570
<type name="Magento\AcceptanceTestFramework\Dummy">
7671
<arguments>
7772
<argument name="pageObjects" xsi:type="object">Magento\AcceptanceTestFramework\Page\Config\Data</argument>
@@ -134,6 +129,14 @@
134129
<argument name="reader" xsi:type="object">Magento\AcceptanceTestFramework\Config\Reader\Block</argument>
135130
</arguments>
136131
</virtualType>
132+
133+
<!-- Configuration for Data.xml -->
134+
135+
<type name="Magento\AcceptanceTestFramework\DataProfileSchemaParser">
136+
<arguments>
137+
<argument name="dataProfiles" xsi:type="object">Magento\AcceptanceTestFramework\DataProfile\Config\Data</argument>
138+
</arguments>
139+
</type>
137140
<virtualType name="Magento\AcceptanceTestFramework\DataProfile\Config\Data" type="Magento\AcceptanceTestFramework\Config\Data">
138141
<arguments>
139142
<argument name="reader" xsi:type="object">Magento\AcceptanceTestFramework\Config\Reader\DataProfile</argument>
@@ -158,4 +161,47 @@
158161
<argument name="defaultScope" xsi:type="string">Data</argument>
159162
</arguments>
160163
</virtualType>
164+
165+
166+
<!-- Configuration for TestData -->
167+
168+
<virtualType name="Magento\AcceptanceTestFramework\Config\SchemaLocator\TestData" type="Magento\AcceptanceTestFramework\Config\SchemaLocator">
169+
<arguments>
170+
<argument name="schemaPath" xsi:type="string">Magento/AcceptanceTestFramework/Test/etc/testSchema.xsd</argument>
171+
</arguments>
172+
</virtualType>
173+
<virtualType name="Magento\AcceptanceTestFramework\Config\Reader\TestData" type="Magento\AcceptanceTestFramework\Config\Reader\Filesystem">
174+
<arguments>
175+
<argument name="fileResolver" xsi:type="object">Magento\AcceptanceTestFramework\Config\FileResolver\Module</argument>
176+
<argument name="converter" xsi:type="object">Magento\AcceptanceTestFramework\Config\Converter</argument>
177+
<argument name="schemaLocator" xsi:type="object">Magento\AcceptanceTestFramework\Config\SchemaLocator\TestData</argument>
178+
<argument name="idAttributes" xsi:type="array">
179+
<item name="/config/cest" xsi:type="string">name</item>
180+
<item name="/config/cest/test" xsi:type="string">name</item>
181+
<item name="/config/cest/annotations/features" xsi:type="string">value</item>
182+
<item name="/config/cest/annotations/stories" xsi:type="string">value</item>
183+
<item name="/config/cest/annotations/title" xsi:type="string">value</item>
184+
<item name="/config/cest/annotations/description" xsi:type="string">value</item>
185+
<item name="/config/cest/annotations/severity" xsi:type="string">value</item>
186+
<item name="/config/cest/annotations/testCaseId" xsi:type="string">value</item>
187+
<item name="/config/cest/annotations/group" xsi:type="string">value</item>
188+
<item name="/config/cest/annotations/env" xsi:type="string">value</item>
189+
<item name="/config/cest/annotations/return" xsi:type="string">value</item>
190+
<item name="/config/cest/test/action" xsi:type="string">name</item>
191+
</argument>
192+
<argument name="fileName" xsi:type="string">*Cest.xml</argument>
193+
<argument name="defaultScope" xsi:type="string">Cest</argument>
194+
</arguments>
195+
</virtualType>
196+
197+
<type name="Magento\AcceptanceTestFramework\Test\TestDataParser">
198+
<arguments>
199+
<argument name="testData" xsi:type="object">Magento\AcceptanceTestFramework\Test\Config\Data</argument>
200+
</arguments>
201+
</type>
202+
<virtualType name="Magento\AcceptanceTestFramework\Test\Config\Data" type="Magento\AcceptanceTestFramework\Config\Data">
203+
<arguments>
204+
<argument name="reader" xsi:type="object">Magento\AcceptanceTestFramework\Config\Reader\TestData</argument>
205+
</arguments>
206+
</virtualType>
161207
</config>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Magento\AcceptanceTestFramework\Test;
4+
5+
class ActionObject
6+
{
7+
private $name;
8+
private $actor;
9+
private $function;
10+
private $parameter;
11+
private $selector;
12+
private $linkedAction;
13+
private $returnVariable;
14+
private $userInput;
15+
private $orderOffset = 0;
16+
17+
public function __construct($name, $actor, $function, $selector, $parameter, $order, $linkedAction, $returnVariable, $userInput)
18+
{
19+
$this->name = $name;
20+
$this->actor = $actor;
21+
$this->function = $function;
22+
$this->selector = $selector;
23+
$this->parameter = $parameter;
24+
$this->linkedAction = $linkedAction;
25+
$this->returnVariable = $returnVariable;
26+
$this->userInput = $userInput;
27+
28+
if ($order == 'after') {
29+
$this->orderOffset = 1;
30+
}
31+
}
32+
33+
public function getName()
34+
{
35+
return $this->name;
36+
}
37+
38+
public function getActor()
39+
{
40+
return $this->actor;
41+
}
42+
43+
public function getFunction()
44+
{
45+
return $this->function;
46+
}
47+
48+
public function getParameter()
49+
{
50+
return $this->parameter;
51+
}
52+
53+
public function getSelector()
54+
{
55+
return $this->selector;
56+
}
57+
58+
public function getLinkedAction()
59+
{
60+
return $this->linkedAction;
61+
}
62+
63+
public function getReturnVariable()
64+
{
65+
return $this->returnVariable;
66+
}
67+
68+
public function getUserInput()
69+
{
70+
return $this->userInput;
71+
}
72+
73+
public function getOrderOffset()
74+
{
75+
return $this->orderOffset;
76+
}
77+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Magento\AcceptanceTestFramework\Test;
4+
5+
class CestDataConstants
6+
{
7+
const CEST_ROOT = 'cest';
8+
const CEST_ANNOTATIONS = 'annotations';
9+
10+
const CEST_BEFORE_HOOK = 'before';
11+
const CEST_AFTER_HOOK = 'after';
12+
13+
const CEST_USE_STATEMENTS = 'use';
14+
const CEST_USE_PATH = 'path';
15+
const CEST_TEST_TAG = 'test';
16+
17+
const TEST_ANNOTATIONS = 'annotations';
18+
const TEST_DEPENDENCY = 'dependency';
19+
const TEST_DEPENDENCY_ACTOR = 'actor';
20+
21+
const TEST_ACTION = 'action';
22+
const TEST_ACTION_FUNCTION = 'function';
23+
const TEST_ACTION_ACTOR = 'actor';
24+
const TEST_ACTION_PARAMETER = 'parameter';
25+
const TEST_ACTION_SELECTOR = 'selector';
26+
const TEST_ACTION_ORDER = 'order';
27+
const TEST_ACTION_LINK = 'linkedAction';
28+
const TEST_ACTION_USER_INPUT = 'userInput';
29+
const TEST_ACTION_RETURN_VARIABLE = 'returnVariable';
30+
31+
const ANNOTATION_VALUE = 'value';
32+
33+
}
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
<?php
2+
3+
namespace Magento\AcceptanceTestFramework\Test;
4+
5+
use Magento\AcceptanceTestFramework\ObjectManagerFactory;
6+
7+
class CestDataManager
8+
{
9+
public static function getCestData()
10+
{
11+
$cestDataParser = ObjectManagerFactory::getObjectManager()->create(TestDataParser::class);
12+
return self::transform($cestDataParser->readTestData());
13+
}
14+
15+
private static function transform($parsedArray)
16+
{
17+
$cests = [];
18+
19+
foreach ($parsedArray[CestDataConstants::CEST_ROOT] as $cestName => $cestData) {
20+
$hooks = [];
21+
22+
if (array_key_exists(CestDataConstants::CEST_BEFORE_HOOK, $cestData)) {
23+
$hooks[CestDataConstants::CEST_BEFORE_HOOK] = self::extractHook(
24+
CestDataConstants::CEST_BEFORE_HOOK,
25+
$cestData[CestDataConstants::CEST_BEFORE_HOOK]
26+
);
27+
}
28+
29+
if (array_key_exists(CestDataConstants::CEST_AFTER_HOOK, $cestData)) {
30+
$hooks[CestDataConstants::CEST_AFTER_HOOK] = self::extractHook(
31+
CestDataConstants::CEST_AFTER_HOOK,
32+
$cestData[CestDataConstants::CEST_AFTER_HOOK]
33+
);
34+
}
35+
36+
$cests[] = new CestObject(
37+
$cestName,
38+
self::extractAnnotations($cestData[CestDataConstants::CEST_ANNOTATIONS]),
39+
self::extractCestUseStatements($cestData[CestDataConstants::CEST_USE_STATEMENTS]),
40+
self::extractTestData($cestData[CestDataConstants::CEST_TEST_TAG]),
41+
$hooks
42+
);
43+
}
44+
45+
return $cests;
46+
}
47+
48+
private static function extractHook($hookType, $cestHook)
49+
{
50+
$hooks = [];
51+
52+
foreach ($cestHook as $cestHookData) {
53+
$hooks[] = new CestHookObject(
54+
$hookType,
55+
self::extractTestDependencies($cestHookData[CestDataConstants::TEST_DEPENDENCY]),
56+
self::extractTestActions($cestHookData[CestDataConstants::TEST_ACTION])
57+
);
58+
}
59+
60+
return $hooks;
61+
}
62+
63+
private static function extractAnnotations($cestAnnotations)
64+
{
65+
$annotations = [];
66+
67+
// parse the Cest annotations
68+
foreach ($cestAnnotations as $annotationData) {
69+
foreach ($annotationData as $annotationKey => $annotationValue) {
70+
$annotationValues = [];
71+
72+
foreach ($annotationValue as $annotationValueKey => $annotation) {
73+
$annotationValues[] = $annotation[CestDataConstants::ANNOTATION_VALUE];
74+
}
75+
76+
$annotations[$annotationKey] = $annotationValues;
77+
}
78+
}
79+
80+
return $annotations;
81+
}
82+
83+
private static function extractCestUseStatements($cestUseStatements)
84+
{
85+
$useStatements = [];
86+
87+
// parse any use statements
88+
foreach ($cestUseStatements as $cestUseStatement) {
89+
$useStatements[] = $cestUseStatement[CestDataConstants::CEST_USE_PATH];
90+
}
91+
92+
return $useStatements;
93+
}
94+
95+
private static function extractTestData($cestTestData)
96+
{
97+
$tests = [];
98+
99+
// parse the tests
100+
foreach ($cestTestData as $testName => $testData) {
101+
$testAnnotations = [];
102+
103+
if (array_key_exists(CestDataConstants::TEST_ANNOTATIONS, $testData)) {
104+
$testAnnotations = self::extractAnnotations($testData[CestDataConstants::TEST_ANNOTATIONS]);
105+
}
106+
107+
$tests[] = new TestObject(
108+
$testName,
109+
self::extractTestDependencies($testData[CestDataConstants::TEST_DEPENDENCY]),
110+
self::extractTestActions($testData[CestDataConstants::TEST_ACTION]),
111+
$testAnnotations
112+
);
113+
}
114+
115+
return $tests;
116+
}
117+
118+
private static function extractTestDependencies($testDependencies)
119+
{
120+
$dependencies = [];
121+
122+
foreach ($testDependencies as $dependencyName => $dependencyData) {
123+
$dependencies[$dependencyName] = $dependencyData[CestDataConstants::TEST_DEPENDENCY_ACTOR];
124+
}
125+
126+
return $dependencies;
127+
}
128+
129+
private static function extractTestActions($testActions)
130+
{
131+
$actions = [];
132+
133+
foreach ($testActions as $actionName => $actionData) {
134+
$function = $actionData[CestDataConstants::TEST_ACTION_FUNCTION];
135+
$actor = null;
136+
$parameter = null;
137+
$selector = null;
138+
$linkedAction = null;
139+
$userInput = null;
140+
$returnVariable = null;
141+
$order = null;
142+
143+
if (array_key_exists(CestDataConstants::TEST_ACTION_ACTOR, $actionData)) {
144+
$actor = $actionData[CestDataConstants::TEST_ACTION_ACTOR];
145+
}
146+
147+
if (array_key_exists(CestDataConstants::TEST_ACTION_PARAMETER, $actionData)) {
148+
$parameter = $actionData[CestDataConstants::TEST_ACTION_PARAMETER];
149+
} elseif (array_key_exists(CestDataConstants::TEST_ACTION_SELECTOR, $actionData)) {
150+
$selector = $actionData[CestDataConstants::TEST_ACTION_SELECTOR];
151+
}
152+
153+
if (array_key_exists(CestDataConstants::TEST_ACTION_LINK, $actionData)) {
154+
$linkedAction = $actionData[CestDataConstants::TEST_ACTION_LINK];
155+
$order = $actionData [CestDataConstants::TEST_ACTION_ORDER];
156+
}
157+
158+
if (array_key_exists(CestDataConstants::TEST_ACTION_USER_INPUT, $actionData)) {
159+
$userInput = $actionData[CestDataConstants::TEST_ACTION_USER_INPUT];
160+
}
161+
162+
if (array_key_exists(CestDataConstants::TEST_ACTION_RETURN_VARIABLE, $actionData)) {
163+
$returnVariable = $actionData[CestDataConstants::TEST_ACTION_RETURN_VARIABLE];
164+
}
165+
166+
$actions[] = new ActionObject(
167+
$actionName,
168+
$actor,
169+
$function,
170+
$selector,
171+
$parameter,
172+
$order,
173+
$linkedAction,
174+
$returnVariable,
175+
$userInput
176+
);
177+
}
178+
179+
return $actions;
180+
}
181+
}

0 commit comments

Comments
 (0)