Skip to content

Commit b2ee898

Browse files
authored
Merge pull request magento#149 from magento/MQE-1021
MQE-1021: Empty Action StepKey Attribute Issues
2 parents 98a3a7d + 45e82e8 commit b2ee898

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util;
7+
8+
use Magento\FunctionalTestingFramework\Test\Util\ActionGroupObjectExtractor;
9+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
10+
use tests\unit\Util\TestLoggingUtil;
11+
12+
class ActionGroupObjectExtractorTest extends MagentoTestCase
13+
{
14+
/** @var ActionGroupObjectExtractor */
15+
private $testActionGroupObjectExtractor;
16+
17+
/**
18+
* Setup method
19+
*/
20+
public function setUp()
21+
{
22+
$this->testActionGroupObjectExtractor = new ActionGroupObjectExtractor();
23+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
24+
}
25+
26+
/**
27+
* Tests basic action object extraction with an empty stepKey
28+
*/
29+
public function testEmptyStepKey()
30+
{
31+
$this->expectExceptionMessage(
32+
"StepKeys cannot be empty. Action='sampleAction' in Action Group filename.xml"
33+
);
34+
$this->testActionGroupObjectExtractor->extractActionGroup($this->createBasicActionObjectArray(""));
35+
}
36+
37+
/**
38+
* Utility function to return mock parser output for testing extraction into ActionObjects.
39+
*
40+
* @param string $stepKey
41+
* @param string $actionGroup
42+
* @param string $filename
43+
* @return array
44+
*/
45+
private function createBasicActionObjectArray(
46+
$stepKey = 'testAction1',
47+
$actionGroup = "actionGroup",
48+
$filename = "filename.xml"
49+
) {
50+
$baseArray = [
51+
'nodeName' => 'actionGroup',
52+
'name' => $actionGroup,
53+
'filename' => $filename,
54+
$stepKey => [
55+
"nodeName" => "sampleAction",
56+
"stepKey" => $stepKey,
57+
"someAttribute" => "someAttributeValue"
58+
]
59+
];
60+
return $baseArray;
61+
}
62+
63+
/**
64+
* clean up function runs after all tests
65+
*/
66+
public static function tearDownAfterClass()
67+
{
68+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
69+
}
70+
}

dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testInvalidMergeOrderReference()
5050
} catch (\Exception $e) {
5151
TestLoggingUtil::getInstance()->validateMockLogStatement(
5252
'error',
53-
'Line 103: Invalid ordering configuration in test',
53+
'Line 108: Invalid ordering configuration in test',
5454
[
5555
'test' => 'TestWithSelfReferencingStepKey',
5656
'stepKey' => ['invalidTestAction1']
@@ -89,6 +89,15 @@ public function testAmbiguousMergeOrderReference()
8989
);
9090
}
9191

92+
/**
93+
* Tests basic action object extraction with an empty stepKey
94+
*/
95+
public function testEmptyStepKey()
96+
{
97+
$this->expectExceptionMessage("StepKeys cannot be empty. Action='sampleAction'");
98+
$this->testActionObjectExtractor->extractActions($this->createBasicActionObjectArray(""));
99+
}
100+
92101
/**
93102
* Utility function to return mock parser output for testing extraction into ActionObjects.
94103
*

src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ public function extractActionGroup($actionGroupData)
6262
);
6363

6464
// TODO filename is now available to the ActionGroupObject, integrate this into debug and error statements
65-
$actions = $this->actionObjectExtractor->extractActions($actionData);
65+
try {
66+
$actions = $this->actionObjectExtractor->extractActions($actionData);
67+
} catch (\Exception $error) {
68+
throw new XmlException($error->getMessage() . " in Action Group " . $actionGroupData[self::FILENAME]);
69+
}
6670

6771
if (array_key_exists(self::ACTION_GROUP_ARGUMENTS, $actionGroupData)) {
6872
$arguments = $this->extractArguments($actionGroupData[self::ACTION_GROUP_ARGUMENTS]);

src/Magento/FunctionalTestingFramework/Test/Util/ActionObjectExtractor.php

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ActionObjectExtractor extends BaseObjectExtractor
2727
const ACTION_GROUP_ARG_VALUE = 'value';
2828
const BEFORE_AFTER_ERROR_MSG = "Merge Error - Steps cannot have both before and after attributes.\tStepKey='%s'";
2929
const STEP_KEY_BLACKLIST_ERROR_MSG = "StepKeys cannot contain non alphanumeric characters.\tStepKey='%s'";
30+
const STEP_KEY_EMPTY_ERROR_MSG = "StepKeys cannot be empty.\tAction='%s'";
3031
const DATA_PERSISTENCE_CUSTOM_FIELD = 'field';
3132
const DATA_PERSISTENCE_CUSTOM_FIELD_KEY = 'key';
3233
const ACTION_OBJECT_PERSISTENCE_FIELDS = 'customFields';
@@ -59,6 +60,10 @@ public function extractActions($testActions, $testName = null)
5960
foreach ($testActions as $actionName => $actionData) {
6061
$stepKey = $actionData[self::TEST_STEP_MERGE_KEY];
6162

63+
if (empty($stepKey)) {
64+
throw new XmlException(sprintf(self::STEP_KEY_EMPTY_ERROR_MSG, $actionData['nodeName']));
65+
}
66+
6267
if (preg_match('/[^a-zA-Z0-9_]/', $stepKey)) {
6368
throw new XmlException(sprintf(self::STEP_KEY_BLACKLIST_ERROR_MSG, $actionName));
6469
}

0 commit comments

Comments
 (0)