From ca4f32904fa734e4f748dd9c43f92b0c9d8d8b53 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Tue, 12 Jun 2018 12:59:11 -0500 Subject: [PATCH 1/4] MQE-1021: Empty Action StepKey Attribute Issues - Added check for empty stepkey and unit test --- .../Test/Util/ActionObjectExtractorTest.php | 9 +++++++++ .../Test/Util/ActionObjectExtractor.php | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php index 7872b3a02..e78038568 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php @@ -89,6 +89,15 @@ public function testAmbiguousMergeOrderReference() ); } + /** + * Tests basic action object extraction with an empty stepKey + */ + public function testEmptyStepKey() + { + $this->expectExceptionMessage("StepKeys cannot be empty. Action='sampleAction'"); + $this->testActionObjectExtractor->extractActions($this->createBasicActionObjectArray("")); + } + /** * Utility function to return mock parser output for testing extraction into ActionObjects. * diff --git a/src/Magento/FunctionalTestingFramework/Test/Util/ActionObjectExtractor.php b/src/Magento/FunctionalTestingFramework/Test/Util/ActionObjectExtractor.php index 4ffd70ecf..d157ca5d6 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Util/ActionObjectExtractor.php +++ b/src/Magento/FunctionalTestingFramework/Test/Util/ActionObjectExtractor.php @@ -27,6 +27,7 @@ class ActionObjectExtractor extends BaseObjectExtractor const ACTION_GROUP_ARG_VALUE = 'value'; const BEFORE_AFTER_ERROR_MSG = "Merge Error - Steps cannot have both before and after attributes.\tStepKey='%s'"; const STEP_KEY_BLACKLIST_ERROR_MSG = "StepKeys cannot contain non alphanumeric characters.\tStepKey='%s'"; + const STEP_KEY_EMPTY_ERROR_MSG = "StepKeys cannot be empty.\tAction='%s'"; const DATA_PERSISTENCE_CUSTOM_FIELD = 'field'; const DATA_PERSISTENCE_CUSTOM_FIELD_KEY = 'key'; const ACTION_OBJECT_PERSISTENCE_FIELDS = 'customFields'; @@ -59,6 +60,10 @@ public function extractActions($testActions, $testName = null) foreach ($testActions as $actionName => $actionData) { $stepKey = $actionData[self::TEST_STEP_MERGE_KEY]; + if (empty($stepKey)) { + throw new XmlException(sprintf(self::STEP_KEY_EMPTY_ERROR_MSG, $actionData['nodeName'])); + } + if (preg_match('/[^a-zA-Z0-9_]/', $stepKey)) { throw new XmlException(sprintf(self::STEP_KEY_BLACKLIST_ERROR_MSG, $actionName)); } From 1099c00724717e11ac0093d32815db9a73a913e8 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Tue, 12 Jun 2018 13:20:10 -0500 Subject: [PATCH 2/4] MQE-1021: Empty Action StepKey Attribute Issues - Fixes other unit test --- .../Test/Util/ActionObjectExtractorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php index e78038568..1d645ab62 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php @@ -50,7 +50,7 @@ public function testInvalidMergeOrderReference() } catch (\Exception $e) { TestLoggingUtil::getInstance()->validateMockLogStatement( 'error', - 'Line 103: Invalid ordering configuration in test', + 'Line 108: Invalid ordering configuration in test', [ 'test' => 'TestWithSelfReferencingStepKey', 'stepKey' => ['invalidTestAction1'] From 914ebe1c3bc012d344ba1aec0a85b9c0a1814770 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Wed, 13 Jun 2018 16:13:51 -0500 Subject: [PATCH 3/4] MQE-1021: Empty Action StepKey Attribute Issues - Added filename information for action groups actions as well --- .../Util/ActionGroupObjectExtractorTest.php | 68 +++++++++++++++++++ .../Test/Util/ActionGroupObjectExtractor.php | 6 +- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionGroupObjectExtractorTest.php diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionGroupObjectExtractorTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionGroupObjectExtractorTest.php new file mode 100644 index 000000000..25e53c570 --- /dev/null +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionGroupObjectExtractorTest.php @@ -0,0 +1,68 @@ +testActionGroupObjectExtractor = new ActionGroupObjectExtractor(); + TestLoggingUtil::getInstance()->setMockLoggingUtil(); + } + + /** + * Tests basic action object extraction with an empty stepKey + */ + public function testEmptyStepKey() + { + $this->expectExceptionMessage("StepKeys cannot be empty. Action='sampleAction' in filename.xml"); + $this->testActionGroupObjectExtractor->extractActionGroup($this->createBasicActionObjectArray("")); + } + + /** + * Utility function to return mock parser output for testing extraction into ActionObjects. + * + * @param string $stepKey + * @param string $actionGroup + * @param string $filename + * @return array + */ + private function createBasicActionObjectArray( + $stepKey = 'testAction1', + $actionGroup = "actionGroup", + $filename = "filename.xml" + ) { + $baseArray = [ + 'nodeName' => 'actionGroup', + 'name' => $actionGroup, + 'filename' => $filename, + $stepKey => [ + "nodeName" => "sampleAction", + "stepKey" => $stepKey, + "someAttribute" => "someAttributeValue" + ] + ]; + return $baseArray; + } + + /** + * clean up function runs after all tests + */ + public static function tearDownAfterClass() + { + TestLoggingUtil::getInstance()->clearMockLoggingUtil(); + } +} diff --git a/src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php b/src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php index fd8093358..bedd6575e 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php +++ b/src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php @@ -62,7 +62,11 @@ public function extractActionGroup($actionGroupData) ); // TODO filename is now available to the ActionGroupObject, integrate this into debug and error statements - $actions = $this->actionObjectExtractor->extractActions($actionData); + try { + $actions = $this->actionObjectExtractor->extractActions($actionData); + } catch (\Exception $error) { + throw new XmlException($error->getMessage() . " in " . $actionGroupData[self::FILENAME]); + } if (array_key_exists(self::ACTION_GROUP_ARGUMENTS, $actionGroupData)) { $arguments = $this->extractArguments($actionGroupData[self::ACTION_GROUP_ARGUMENTS]); From 35257580effb9801a23d2785be806dabf079eb40 Mon Sep 17 00:00:00 2001 From: Alex Calandra Date: Wed, 13 Jun 2018 16:17:11 -0500 Subject: [PATCH 4/4] MQE-1021: Empty Action StepKey Attribute Issues - Made error message slightly more specific --- .../Test/Util/ActionGroupObjectExtractorTest.php | 4 +++- .../Test/Util/ActionGroupObjectExtractor.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionGroupObjectExtractorTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionGroupObjectExtractorTest.php index 25e53c570..47b797c1c 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionGroupObjectExtractorTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionGroupObjectExtractorTest.php @@ -28,7 +28,9 @@ public function setUp() */ public function testEmptyStepKey() { - $this->expectExceptionMessage("StepKeys cannot be empty. Action='sampleAction' in filename.xml"); + $this->expectExceptionMessage( + "StepKeys cannot be empty. Action='sampleAction' in Action Group filename.xml" + ); $this->testActionGroupObjectExtractor->extractActionGroup($this->createBasicActionObjectArray("")); } diff --git a/src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php b/src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php index bedd6575e..04f739af6 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php +++ b/src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php @@ -65,7 +65,7 @@ public function extractActionGroup($actionGroupData) try { $actions = $this->actionObjectExtractor->extractActions($actionData); } catch (\Exception $error) { - throw new XmlException($error->getMessage() . " in " . $actionGroupData[self::FILENAME]); + throw new XmlException($error->getMessage() . " in Action Group " . $actionGroupData[self::FILENAME]); } if (array_key_exists(self::ACTION_GROUP_ARGUMENTS, $actionGroupData)) {