Skip to content

MQE-2212: Fix invalid behaviour MAGENTO_BACKEND_BASE_URL #780

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 5 commits into from
Aug 11, 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
4 changes: 2 additions & 2 deletions dev/tests/verification/Resources/PageReplacementTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class PageReplacementTestCest
$I->amOnPage("/John/StringLiteral2.html"); // stepKey: twoParamPageStringData
$I->amOnPage("/John/" . $I->retrieveEntityField('datakey', 'firstname', 'test') . ".html"); // stepKey: twoParamPageDataPersist
$I->amOnPage("/" . $I->retrieveEntityField('datakey', 'firstname', 'test') . "/StringLiteral2.html"); // stepKey: twoParamPagePersistString
$I->amOnPage("/" . getenv("MAGENTO_BACKEND_NAME") . "/backend"); // stepKey: onAdminPage
$I->amOnPage("/" . getenv("MAGENTO_BACKEND_NAME") . "/StringLiteral/page.html"); // stepKey: oneParamAdminPageString
$I->amOnPage((getenv("MAGENTO_BACKEND_BASE_URL") ? rtrim(getenv("MAGENTO_BACKEND_BASE_URL"), "/") : "") . "/" . getenv("MAGENTO_BACKEND_NAME") . "/backend"); // stepKey: onAdminPage
$I->amOnPage((getenv("MAGENTO_BACKEND_BASE_URL") ? rtrim(getenv("MAGENTO_BACKEND_BASE_URL"), "/") : "") . "/" . getenv("MAGENTO_BACKEND_NAME") . "/StringLiteral/page.html"); // stepKey: oneParamAdminPageString
$I->amOnUrl("http://myFullUrl.com/"); // stepKey: onExternalPage
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ public function saveScreenshot()
*/
public function amOnPage($page)
{
parent::amOnPage($page);
(0 === strpos($page, 'http')) ? parent::amOnUrl($page) : parent::amOnPage($page);
$this->waitForPageLoad();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,12 @@ private function resolveParameterization($isParameterized, $replacement, $match,
$resolvedReplacement = $replacement;
}
if (get_class($object) == PageObject::class && $object->getArea() == PageObject::ADMIN_AREA) {
$resolvedReplacement = "/{{_ENV.MAGENTO_BACKEND_NAME}}/" . $resolvedReplacement;
$urlSegments = [
'{{_ENV.MAGENTO_BACKEND_BASE_URL}}',
'{{_ENV.MAGENTO_BACKEND_NAME}}',
$resolvedReplacement
];
$resolvedReplacement = implode('/', $urlSegments);
}
return $resolvedReplacement;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Magento/FunctionalTestingFramework/Util/MftfGlobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ public static function getBackendBaseUrl($withTrailingSeparator = true)
{
if (!self::$backendBaseUrl) {
try {
$backendName = getenv('MAGENTO_BACKEND_NAME');
$bUrl = getenv('MAGENTO_BACKEND_BASE_URL');
if ($bUrl) {
self::$backendBaseUrl = UrlFormatter::format($bUrl, false);
if ($bUrl && $backendName) {
self::$backendBaseUrl = UrlFormatter::format(
UrlFormatter::format($bUrl) . $backendName,
false
);
} else {
$baseUrl = getenv('MAGENTO_BASE_URL');
$backendName = getenv('MAGENTO_BACKEND_NAME');
if ($baseUrl && $backendName) {
self::$backendBaseUrl = UrlFormatter::format(
UrlFormatter::format($baseUrl) . $backendName,
Expand Down
32 changes: 25 additions & 7 deletions src/Magento/FunctionalTestingFramework/Util/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2030,18 +2030,20 @@ private function resolveRuntimeReference($args, $regex, $func)
$newArgs = [];

foreach ($args as $key => $arg) {
$newArgs[$key] = $arg;
preg_match_all($regex, $arg, $matches);
if (!empty($matches[0])) {
$fullMatch = $matches[0][0];
$refVariable = $matches[1][0];
unset($matches);
$replacement = "{$func}(\"{$refVariable}\")";
foreach ($matches[0] as $matchKey => $fullMatch) {
$refVariable = $matches[1][$matchKey];

$outputArg = $this->processQuoteBreaks($fullMatch, $arg, $replacement);
$newArgs[$key] = $outputArg;
$replacement = $this->getReplacement($func, $refVariable);

$outputArg = $this->processQuoteBreaks($fullMatch, $newArgs[$key], $replacement);
$newArgs[$key] = $outputArg;
}
unset($matches);
continue;
}
$newArgs[$key] = $arg;
}

// override passed in args for use later.
Expand Down Expand Up @@ -2313,4 +2315,20 @@ private function parseUserInput($userInput)

return $this->addUniquenessFunctionCall($userInput);
}

/**
* Supports fallback for BACKEND URL
*
* @param string $func
* @param string $refVariable
* @return string
*/
private function getReplacement($func, $refVariable): string
{
if ($refVariable === 'MAGENTO_BACKEND_BASE_URL') {
return "({$func}(\"{$refVariable}\") ? rtrim({$func}(\"{$refVariable}\"), \"/\") : \"\")";
}

return "{$func}(\"{$refVariable}\")";
}
}