Skip to content

Commit 8016574

Browse files
authored
Merge branch 'develop' into MQE-1782
2 parents 9cb452b + c3f7c05 commit 8016574

File tree

10 files changed

+457
-122
lines changed

10 files changed

+457
-122
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Persist/OperationDataArrayResolverTest.php

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
1010
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\OperationDefinitionObjectHandler;
1111
use Magento\FunctionalTestingFramework\DataGenerator\Persist\OperationDataArrayResolver;
12+
use Magento\FunctionalTestingFramework\Util\Iterator\AbstractIterator;
1213
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
1314
use tests\unit\Util\EntityDataObjectBuilder;
1415
use tests\unit\Util\OperationDefinitionBuilder;
@@ -355,6 +356,127 @@ public function testNestedMetadataArrayOfValue()
355356
$this->assertEquals(self::NESTED_METADATA_ARRAY_RESULT, $result);
356357
}
357358

359+
public function testNestedMetadataArrayOfDiverseObjects()
360+
{
361+
362+
$entityDataObjBuilder = new EntityDataObjectBuilder();
363+
$parentDataObject = $entityDataObjBuilder
364+
->withName("parentObject")
365+
->withType("parentType")
366+
->withLinkedEntities(['child1Object' => 'childType1','child2Object' => 'childType2'])
367+
->build();
368+
369+
$child1DataObject = $entityDataObjBuilder
370+
->withName('child1Object')
371+
->withType('childType1')
372+
->withDataFields(['city' => 'Testcity','zip' => 12345])
373+
->build();
374+
375+
$child2DataObject = $entityDataObjBuilder
376+
->withName('child2Object')
377+
->withType('childType2')
378+
->withDataFields(['city' => 'Testcity 2','zip' => 54321,'state' => 'Teststate'])
379+
->build();
380+
381+
$mockDOHInstance = AspectMock::double(
382+
DataObjectHandler::class,
383+
[
384+
'getObject' => function ($name) use ($child1DataObject, $child2DataObject) {
385+
switch ($name) {
386+
case 'child1Object':
387+
return $child1DataObject;
388+
case 'child2Object':
389+
return $child2DataObject;
390+
}
391+
}
392+
]
393+
)->make();
394+
AspectMock::double(DataObjectHandler::class, [
395+
'getInstance' => $mockDOHInstance
396+
]);
397+
398+
$operationDefinitionBuilder = new OperationDefinitionBuilder();
399+
$child1OperationDefinition = $operationDefinitionBuilder
400+
->withName('createchildType1')
401+
->withOperation('create')
402+
->withType('childType1')
403+
->withMetadata([
404+
'city' => 'string',
405+
'zip' => 'integer'
406+
])->build();
407+
408+
$child2OperationDefinition = $operationDefinitionBuilder
409+
->withName('createchildType2')
410+
->withOperation('create')
411+
->withType('childType2')
412+
->withMetadata([
413+
'city' => 'string',
414+
'zip' => 'integer',
415+
'state' => 'string'
416+
])->build();
417+
418+
$mockODOHInstance = AspectMock::double(
419+
OperationDefinitionObjectHandler::class,
420+
[
421+
'getObject' => function ($name) use ($child1OperationDefinition, $child2OperationDefinition) {
422+
switch ($name) {
423+
case 'createchildType1':
424+
return $child1OperationDefinition;
425+
case 'createchildType2':
426+
return $child2OperationDefinition;
427+
}
428+
}
429+
]
430+
)->make();
431+
AspectMock::double(
432+
OperationDefinitionObjectHandler::class,
433+
[
434+
'getInstance' => $mockODOHInstance
435+
]
436+
);
437+
438+
$arrayObElementBuilder = new OperationElementBuilder();
439+
$arrayElement = $arrayObElementBuilder
440+
->withKey('address')
441+
->withType(['childType1','childType2'])
442+
->withFields([])
443+
->withElementType(OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY)
444+
//->withNestedElements(['childType1' => $child1Element, 'childType2' => $child2Element])
445+
->build();
446+
447+
$parentOpElementBuilder = new OperationElementBuilder();
448+
$parentElement = $parentOpElementBuilder
449+
->withKey('parentType')
450+
->withType('parentType')
451+
->addElements(['address' => $arrayElement])
452+
->build();
453+
454+
$operationResolver = new OperationDataArrayResolver();
455+
$result = $operationResolver->resolveOperationDataArray($parentDataObject, [$parentElement], 'create', false);
456+
457+
$expectedResult = [
458+
'parentType' => [
459+
'address' => [
460+
[
461+
'city' => 'Testcity',
462+
'zip' => '12345'
463+
],
464+
[
465+
'city' => 'Testcity 2',
466+
'zip' => '54321',
467+
'state' => 'Teststate'
468+
]
469+
],
470+
'name' => 'Hopper',
471+
'gpa' => '3.5678',
472+
'phone' => '5555555',
473+
'isPrimary' => '1'
474+
]
475+
];
476+
477+
$this->assertEquals($expectedResult, $result);
478+
}
479+
358480
/**
359481
* After class functionality
360482
* @return void
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\Extension;
8+
9+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
10+
use Magento\FunctionalTestingFramework\Extension\BrowserLogUtil;
11+
12+
class BrowserLogUtilTest extends MagentoTestCase
13+
{
14+
public function testGetLogsOfType()
15+
{
16+
$entryOne = [
17+
"level" => "WARNING",
18+
"message" => "warningMessage",
19+
"source" => "console-api",
20+
"timestamp" => 1234567890
21+
];
22+
$entryTwo = [
23+
"level" => "ERROR",
24+
"message" => "errorMessage",
25+
"source" => "other",
26+
"timestamp" => 1234567890
27+
];
28+
$entryThree = [
29+
"level" => "LOG",
30+
"message" => "logMessage",
31+
"source" => "javascript",
32+
"timestamp" => 1234567890
33+
];
34+
$log = [
35+
$entryOne,
36+
$entryTwo,
37+
$entryThree
38+
];
39+
40+
$actual = BrowserLogUtil::getLogsOfType($log, 'console-api');
41+
42+
self::assertEquals($entryOne, $actual[0]);
43+
}
44+
45+
public function testFilterLogsOfType()
46+
{
47+
$entryOne = [
48+
"level" => "WARNING",
49+
"message" => "warningMessage",
50+
"source" => "console-api",
51+
"timestamp" => 1234567890
52+
];
53+
$entryTwo = [
54+
"level" => "ERROR",
55+
"message" => "errorMessage",
56+
"source" => "other",
57+
"timestamp" => 1234567890
58+
];
59+
$entryThree = [
60+
"level" => "LOG",
61+
"message" => "logMessage",
62+
"source" => "javascript",
63+
"timestamp" => 1234567890
64+
];
65+
$log = [
66+
$entryOne,
67+
$entryTwo,
68+
$entryThree
69+
];
70+
71+
$actual = BrowserLogUtil::filterLogsOfType($log, 'console-api');
72+
73+
self::assertEquals($entryTwo, $actual[0]);
74+
self::assertEquals($entryThree, $actual[1]);
75+
}
76+
}

docs/configuration.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,24 @@ Example:
277277
CREDENTIAL_VAULT_SECRET_BASE_PATH=secret
278278
```
279279

280+
### ENABLE_BROWSER_LOG
281+
282+
Enables addition of browser logs to Allure steps
283+
284+
```conf
285+
ENABLE_BROWSER_LOG=true
286+
```
287+
288+
### BROWSER_LOG_BLACKLIST
289+
290+
Blacklists types of browser log entries from appearing in Allure steps.
291+
292+
Denoted in browser log entry as `"SOURCE": "type"`.
293+
294+
```conf
295+
BROWSER_LOG_BLACKLIST=other,console-api
296+
```
297+
280298
<!-- Link definitions -->
281299

282300
[`MAGENTO_CLI_COMMAND_PATH`]: #magento_cli_command_path

etc/config/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,9 @@ MODULE_WHITELIST=Magento_Framework,ConfigurableProductWishlist,ConfigurableProdu
5454

5555
#*** Default timeout for wait actions
5656
#WAIT_TIMEOUT=10
57+
58+
#*** Uncomment and set to enable browser log entries on actions in Allure. Blacklist is used to filter logs of a specific "source"
59+
#ENABLE_BROWSER_LOG=true
60+
#BROWSER_LOG_BLACKLIST=other
61+
5762
#*** End of .env ***#

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/OperationDataArrayResolver.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function __construct($dependentEntities = null)
6767
* @param boolean $fromArray
6868
* @return array
6969
* @throws \Exception
70+
*
71+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
72+
* I suppressed this warning because I was in a hurry to deliver a community PR. That PR modified this function and
73+
* introduced a new conditional, bumping the complexity to 11.
7074
*/
7175
public function resolveOperationDataArray($entityObject, $operationMetadata, $operation, $fromArray = false)
7276
{
@@ -109,6 +113,26 @@ public function resolveOperationDataArray($entityObject, $operationMetadata, $op
109113
$operationElementType,
110114
$operationDataArray
111115
);
116+
} elseif (is_array($operationElementType)) {
117+
foreach ($operationElementType as $currentElementType) {
118+
if (in_array($currentElementType, self::PRIMITIVE_TYPES)) {
119+
$this->resolvePrimitiveReferenceElement(
120+
$entityObject,
121+
$operationElement,
122+
$currentElementType,
123+
$operationDataArray
124+
);
125+
} else {
126+
$this->resolveNonPrimitiveReferenceElement(
127+
$entityObject,
128+
$operation,
129+
$fromArray,
130+
$currentElementType,
131+
$operationElement,
132+
$operationDataArray
133+
);
134+
}
135+
}
112136
} else {
113137
$this->resolveNonPrimitiveReferenceElement(
114138
$entityObject,
@@ -248,7 +272,8 @@ private function resolveNonPrimitiveElement($entityName, $operationElement, $ope
248272
$linkedEntityObj = $this->resolveLinkedEntityObject($entityName);
249273

250274
// in array case
251-
if (!empty($operationElement->getNestedOperationElement($operationElement->getValue()))
275+
if (!is_array($operationElement->getValue())
276+
&& !empty($operationElement->getNestedOperationElement($operationElement->getValue()))
252277
&& $operationElement->getType() == OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY
253278
) {
254279
$operationSubArray = $this->resolveOperationDataArray(

src/Magento/FunctionalTestingFramework/DataGenerator/Util/OperationElementExtractor.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,18 @@ private function extractOperationField(&$operationElements, $operationFieldArray
112112
private function extractOperationArray(&$operationArrayData, $operationArrayArray)
113113
{
114114
foreach ($operationArrayArray as $operationFieldType) {
115-
$operationElementValue =
116-
$operationFieldType[OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY_VALUE][0]
117-
[OperationElementExtractor::OPERATION_OBJECT_ARRAY_VALUE] ?? null;
115+
$operationElementValue = [];
116+
if (isset($operationFieldType[OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY_VALUE])) {
117+
foreach ($operationFieldType[OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY_VALUE] as
118+
$operationFieldValue) {
119+
$operationElementValue[] =
120+
$operationFieldValue[OperationElementExtractor::OPERATION_OBJECT_ARRAY_VALUE] ?? null;
121+
}
122+
}
123+
124+
if (count($operationElementValue) === 1) {
125+
$operationElementValue = array_pop($operationElementValue);
126+
}
118127

119128
$nestedOperationElements = [];
120129
if (array_key_exists(OperationElementExtractor::OPERATION_OBJECT_OBJ_NAME, $operationFieldType)) {

0 commit comments

Comments
 (0)