Skip to content

Commit d210dcd

Browse files
committed
#55 Throw Exception when cannot resolve URL attribute
1 parent 231e58d commit d210dcd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,14 @@ private function resolveUrlReference()
404404
$url = $this->actionAttributes[ActionObject::ACTION_ATTRIBUTE_URL];
405405

406406
$replacement = $this->findAndReplaceReferences(PageObjectHandler::getInstance(), $url);
407+
408+
$missingReferences = $this->getMissingReferences($replacement);
409+
if (!empty($missingReferences)) {
410+
throw new TestReferenceException(
411+
sprintf('Can not resolve replacements: "%s"', implode('", "', $missingReferences))
412+
);
413+
}
414+
407415
if ($replacement) {
408416
$this->resolvedCustomAttributes[ActionObject::ACTION_ATTRIBUTE_URL] = $replacement;
409417
$allPages = PageObjectHandler::getInstance()->getAllObjects();
@@ -417,6 +425,20 @@ private function resolveUrlReference()
417425
}
418426
}
419427

428+
/**
429+
* Returns array of missing references
430+
*
431+
* @param $replacement
432+
* @return array
433+
*/
434+
private function getMissingReferences($replacement): array
435+
{
436+
$mustachePattern = '/({{[\w]+}})|({{[\w]+\.[\w\[\]]+}})|({{[\w]+\.[\w]+\((?(?!}}).)+\)}})/';
437+
preg_match_all($mustachePattern, $replacement, $matches);
438+
439+
return array_filter($matches[1], function($match) { return false === strpos($match, '_ENV.'); });
440+
}
441+
420442
/**
421443
* Look up the value for EntityDataObjectName.Key and set it as the corresponding attribute in the resolved custom
422444
* attributes.

0 commit comments

Comments
 (0)