Skip to content

Commit ef68e14

Browse files
committed
Revert "Merge pull request #546 from lbajsarowicz/bugfix/55-missing-url-attribute"
This reverts commit 81cfd36, reversing changes made to 4462b2c.
1 parent 81cfd36 commit ef68e14

File tree

2 files changed

+19
-65
lines changed

2 files changed

+19
-65
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*/
2525
class ActionObjectTest extends MagentoTestCase
2626
{
27-
const STUB_PAGE_URL_WITH_NO_ATTRIBUTE = '{{PageObject}}/some/path';
28-
2927
/**
3028
* Before test functionality
3129
* @return void
@@ -229,17 +227,16 @@ public function testResolveUrl()
229227
}
230228

231229
/**
232-
* {{PageObject}} should not be replaced and should throw an exception!
230+
* {{PageObject}} should not be replaced and should elicit a warning in console
233231
*
234232
* @throws /Exception
235233
*/
236234
public function testResolveUrlWithNoAttribute()
237235
{
238-
// Given
236+
// Set up mocks
239237
$actionObject = new ActionObject('merge123', 'amOnPage', [
240-
'url' => self::STUB_PAGE_URL_WITH_NO_ATTRIBUTE
238+
'url' => '{{PageObject}}'
241239
]);
242-
243240
$pageObject = new PageObject('PageObject', '/replacement/url.html', 'Test', [], false, "test");
244241
$pageObjectList = ["PageObject" => $pageObject];
245242
$instance = AspectMock::double(
@@ -248,14 +245,20 @@ public function testResolveUrlWithNoAttribute()
248245
)->make(); // bypass the private constructor
249246
AspectMock::double(PageObjectHandler::class, ['getInstance' => $instance]);
250247

251-
// Expect
252-
$this->expectExceptionMessage('Can not resolve replacements: "{{PageObject}}"');
248+
// Call the method under test
249+
$actionObject->resolveReferences();
250+
251+
// Expect this warning to get generated
252+
TestLoggingUtil::getInstance()->validateMockLogStatement(
253+
"warning",
254+
"page url attribute not found and is required",
255+
['action' => $actionObject->getType(), 'url' => '{{PageObject}}', 'stepKey' => $actionObject->getStepKey()]
256+
);
257+
258+
// Verify
253259
$expected = [
254-
'url' => self::STUB_PAGE_URL_WITH_NO_ATTRIBUTE
260+
'url' => '{{PageObject}}'
255261
];
256-
257-
// When
258-
$actionObject->resolveReferences();
259262
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
260263
}
261264

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ class ActionObject
7676
const ACTION_ATTRIBUTE_USERINPUT = 'userInput';
7777
const ACTION_TYPE_COMMENT = 'comment';
7878
const INVISIBLE_STEP_ACTIONS = ['retrieveEntityField', 'getSecret'];
79-
const REGEX_SINGLE_GROUP = '[\w]+';
80-
const REGEX_WITH_INDEX = '[\w]+\.[\w\[\]]+';
81-
const REGEX_WITH_PARAM = '[\w]+\.[\w]+\((?(?!}}).)+\)';
8279

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

420417
$replacement = $this->findAndReplaceReferences(PageObjectHandler::getInstance(), $url);
421-
422-
$missingReferences = $this->getMissingReferences($replacement);
423-
if (!empty($missingReferences)) {
424-
throw new TestReferenceException(
425-
sprintf('Can not resolve replacements: "%s"', implode('", "', $missingReferences))
426-
);
427-
}
428-
429418
if ($replacement) {
430419
$this->resolvedCustomAttributes[ActionObject::ACTION_ATTRIBUTE_URL] = $replacement;
431420
$allPages = PageObjectHandler::getInstance()->getAllObjects();
@@ -439,27 +428,6 @@ private function resolveUrlReference()
439428
}
440429
}
441430

442-
/**
443-
* Returns array of missing references
444-
*
445-
* @param string $replacement
446-
* @return array
447-
*/
448-
private function getMissingReferences($replacement): array
449-
{
450-
$matchPatterns = [
451-
self::REGEX_SINGLE_GROUP,
452-
self::REGEX_WITH_INDEX,
453-
self::REGEX_WITH_PARAM
454-
];
455-
456-
preg_match_all($this->getMustachePattern($matchPatterns), $replacement, $matches);
457-
458-
return array_filter($matches[1], function ($match) {
459-
return !empty($match) && false === strpos($match, '_ENV.');
460-
});
461-
}
462-
463431
/**
464432
* Look up the value for EntityDataObjectName.Key and set it as the corresponding attribute in the resolved custom
465433
* attributes.
@@ -553,12 +521,10 @@ private function stripAndReturnParameters($reference)
553521
*/
554522
private function findAndReplaceReferences($objectHandler, $inputString)
555523
{
556-
$matchPatterns = [
557-
self::REGEX_WITH_INDEX,
558-
self::REGEX_WITH_PARAM
559-
];
524+
//look for parameter area, if so use different regex
525+
$regex = ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN;
560526

561-
preg_match_all($this->getMustachePattern($matchPatterns), $inputString, $matches);
527+
preg_match_all($regex, $inputString, $matches);
562528

563529
$outputString = $inputString;
564530

@@ -756,11 +722,7 @@ private function resolveParameterization($isParameterized, $replacement, $match,
756722
*/
757723
private function matchParameterReferences($reference, $parameters)
758724
{
759-
$matchPatterns = [
760-
self::REGEX_SINGLE_GROUP
761-
];
762-
763-
preg_match_all($this->getMustachePattern($matchPatterns), $reference, $varMatches);
725+
preg_match_all('/{{[\w.]+}}/', $reference, $varMatches);
764726
$varMatches[0] = array_unique($varMatches[0]);
765727
$this->checkParameterCount($varMatches[0], $parameters, $reference);
766728

@@ -831,17 +793,6 @@ private function checkParameterCount($matches, $parameters, $reference)
831793
}
832794
}
833795

834-
/**
835-
* Returns Mustache regex pattern
836-
*
837-
* @param array|null $patterns
838-
* @return string
839-
*/
840-
private function getMustachePattern(array $patterns = []): string
841-
{
842-
return '/({{' .implode('}})|({{', $patterns).'}})/';
843-
}
844-
845796
/**
846797
* Returns array of deprecated usages in Action.
847798
*

0 commit comments

Comments
 (0)