Skip to content

MQE-1021: Empty Action StepKey Attribute Issues #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util;

use Magento\FunctionalTestingFramework\Test\Util\ActionGroupObjectExtractor;
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
use tests\unit\Util\TestLoggingUtil;

class ActionGroupObjectExtractorTest extends MagentoTestCase
{
/** @var ActionGroupObjectExtractor */
private $testActionGroupObjectExtractor;

/**
* Setup method
*/
public function setUp()
{
$this->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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
}
Expand Down