Skip to content

Revert "Merge pull request #546 from lbajsarowicz/bugfix/55-missing-url-attribute" #615

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 1 commit into from
Mar 5, 2020
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
Expand Up @@ -24,8 +24,6 @@
*/
class ActionObjectTest extends MagentoTestCase
{
const STUB_PAGE_URL_WITH_NO_ATTRIBUTE = '{{PageObject}}/some/path';

/**
* Before test functionality
* @return void
Expand Down Expand Up @@ -229,17 +227,16 @@ public function testResolveUrl()
}

/**
* {{PageObject}} should not be replaced and should throw an exception!
* {{PageObject}} should not be replaced and should elicit a warning in console
*
* @throws /Exception
*/
public function testResolveUrlWithNoAttribute()
{
// Given
// Set up mocks
$actionObject = new ActionObject('merge123', 'amOnPage', [
'url' => self::STUB_PAGE_URL_WITH_NO_ATTRIBUTE
'url' => '{{PageObject}}'
]);

$pageObject = new PageObject('PageObject', '/replacement/url.html', 'Test', [], false, "test");
$pageObjectList = ["PageObject" => $pageObject];
$instance = AspectMock::double(
Expand All @@ -248,14 +245,20 @@ public function testResolveUrlWithNoAttribute()
)->make(); // bypass the private constructor
AspectMock::double(PageObjectHandler::class, ['getInstance' => $instance]);

// Expect
$this->expectExceptionMessage('Can not resolve replacements: "{{PageObject}}"');
// Call the method under test
$actionObject->resolveReferences();

// Expect this warning to get generated
TestLoggingUtil::getInstance()->validateMockLogStatement(
"warning",
"page url attribute not found and is required",
['action' => $actionObject->getType(), 'url' => '{{PageObject}}', 'stepKey' => $actionObject->getStepKey()]
);

// Verify
$expected = [
'url' => self::STUB_PAGE_URL_WITH_NO_ATTRIBUTE
'url' => '{{PageObject}}'
];

// When
$actionObject->resolveReferences();
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ class ActionObject
const ACTION_ATTRIBUTE_USERINPUT = 'userInput';
const ACTION_TYPE_COMMENT = 'comment';
const INVISIBLE_STEP_ACTIONS = ['retrieveEntityField', 'getSecret'];
const REGEX_SINGLE_GROUP = '[\w]+';
const REGEX_WITH_INDEX = '[\w]+\.[\w\[\]]+';
const REGEX_WITH_PARAM = '[\w]+\.[\w]+\((?(?!}}).)+\)';

/**
* The unique identifier for the action
Expand Down Expand Up @@ -418,14 +415,6 @@ private function resolveUrlReference()
$url = $this->actionAttributes[ActionObject::ACTION_ATTRIBUTE_URL];

$replacement = $this->findAndReplaceReferences(PageObjectHandler::getInstance(), $url);

$missingReferences = $this->getMissingReferences($replacement);
if (!empty($missingReferences)) {
throw new TestReferenceException(
sprintf('Can not resolve replacements: "%s"', implode('", "', $missingReferences))
);
}

if ($replacement) {
$this->resolvedCustomAttributes[ActionObject::ACTION_ATTRIBUTE_URL] = $replacement;
$allPages = PageObjectHandler::getInstance()->getAllObjects();
Expand All @@ -439,27 +428,6 @@ private function resolveUrlReference()
}
}

/**
* Returns array of missing references
*
* @param string $replacement
* @return array
*/
private function getMissingReferences($replacement): array
{
$matchPatterns = [
self::REGEX_SINGLE_GROUP,
self::REGEX_WITH_INDEX,
self::REGEX_WITH_PARAM
];

preg_match_all($this->getMustachePattern($matchPatterns), $replacement, $matches);

return array_filter($matches[1], function ($match) {
return !empty($match) && false === strpos($match, '_ENV.');
});
}

/**
* Look up the value for EntityDataObjectName.Key and set it as the corresponding attribute in the resolved custom
* attributes.
Expand Down Expand Up @@ -553,12 +521,10 @@ private function stripAndReturnParameters($reference)
*/
private function findAndReplaceReferences($objectHandler, $inputString)
{
$matchPatterns = [
self::REGEX_WITH_INDEX,
self::REGEX_WITH_PARAM
];
//look for parameter area, if so use different regex
$regex = ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN;

preg_match_all($this->getMustachePattern($matchPatterns), $inputString, $matches);
preg_match_all($regex, $inputString, $matches);

$outputString = $inputString;

Expand Down Expand Up @@ -756,11 +722,7 @@ private function resolveParameterization($isParameterized, $replacement, $match,
*/
private function matchParameterReferences($reference, $parameters)
{
$matchPatterns = [
self::REGEX_SINGLE_GROUP
];

preg_match_all($this->getMustachePattern($matchPatterns), $reference, $varMatches);
preg_match_all('/{{[\w.]+}}/', $reference, $varMatches);
$varMatches[0] = array_unique($varMatches[0]);
$this->checkParameterCount($varMatches[0], $parameters, $reference);

Expand Down Expand Up @@ -831,17 +793,6 @@ private function checkParameterCount($matches, $parameters, $reference)
}
}

/**
* Returns Mustache regex pattern
*
* @param array|null $patterns
* @return string
*/
private function getMustachePattern(array $patterns = []): string
{
return '/({{' .implode('}})|({{', $patterns).'}})/';
}

/**
* Returns array of deprecated usages in Action.
*
Expand Down