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..47b797c1c --- /dev/null +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionGroupObjectExtractorTest.php @@ -0,0 +1,70 @@ +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 Action Group 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/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionObjectExtractorTest.php index 7872b3a02..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'] @@ -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/ActionGroupObjectExtractor.php b/src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php index fd8093358..04f739af6 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 Action Group " . $actionGroupData[self::FILENAME]); + } if (array_key_exists(self::ACTION_GROUP_ARGUMENTS, $actionGroupData)) { $arguments = $this->extractArguments($actionGroupData[self::ACTION_GROUP_ARGUMENTS]); 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)); }