Skip to content
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 @@ -227,7 +227,9 @@ public function trimAssertionAttributes()
$oldAttributes = array_intersect($actionAttributeKeys, ActionObject::OLD_ASSERTION_ATTRIBUTES);
if (!empty($oldAttributes)) {
// @codingStandardsIgnoreStart
echo("WARNING: Use of one line Assertion actions will be deprecated in MFTF 3.0.0, please use nested syntax (Action: {$this->type} StepKey: {$this->stepKey})" . PHP_EOL);
if ($GLOBALS['GENERATE_TESTS'] ?? false == true) {
echo("WARNING: Use of one line Assertion actions will be deprecated in MFTF 3.0.0, please use nested syntax (Action: {$this->type} StepKey: {$this->stepKey})" . PHP_EOL);
}
// @codingStandardsIgnoreEnd
return;
}
Expand All @@ -239,6 +241,29 @@ public function trimAssertionAttributes()
return;
}

$this->validateAssertionSchema($relevantAssertionAttributes);

// Flatten nested Elements's type and value into key=>value entries
foreach ($this->actionAttributes as $key => $subAttributes) {
if (in_array($key, $relevantKeys)) {
$prefix = ActionObject::ASSERTION_ATTRIBUTES[$key];
$this->resolvedCustomAttributes[$prefix . ucfirst(ActionObject::ASSERTION_TYPE_ATTRIBUTE)] =
$subAttributes[ActionObject::ASSERTION_TYPE_ATTRIBUTE];
$this->resolvedCustomAttributes[$prefix] =
$subAttributes[ActionObject::ASSERTION_VALUE_ATTRIBUTE];
unset($this->actionAttributes[$key]);
}
}
}

/**
* Validates that the given assertion attributes have valid schema according to nested assertion syntax.
* @param array $attributes
* @return void
* @throws TestReferenceException
*/
private function validateAssertionSchema($attributes)
{
/** MQE-683 DEPRECATE OLD METHOD HERE
* Unnecessary validation, only needed for backwards compatibility
*/
Expand All @@ -247,25 +272,13 @@ public function trimAssertionAttributes()
'assertElementContainsAttribute'];

if (!in_array($this->type, $singleChildTypes)) {
if (!in_array('expectedResult', $relevantAssertionAttributes)
|| !in_array('actualResult', $relevantAssertionAttributes)) {
if (!in_array('expectedResult', $attributes)
|| !in_array('actualResult', $attributes)) {
// @codingStandardsIgnoreStart
throw new TestReferenceException("{$this->type} must have both an expectedResult and actualResult defined (stepKey: {$this->stepKey})");
// @codingStandardsIgnoreEnd
}
}

// Flatten nested Elements's type and value into key=>value entries
foreach ($this->actionAttributes as $key => $subAttributes) {
if (in_array($key, $relevantKeys)) {
$prefix = ActionObject::ASSERTION_ATTRIBUTES[$key];
$this->resolvedCustomAttributes[$prefix . ucfirst(ActionObject::ASSERTION_TYPE_ATTRIBUTE)] =
$subAttributes[ActionObject::ASSERTION_TYPE_ATTRIBUTE];
$this->resolvedCustomAttributes[$prefix] =
$subAttributes[ActionObject::ASSERTION_VALUE_ATTRIBUTE];
unset($this->actionAttributes[$key]);
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ private static function validateConfigBasedVars($config)
*/
public static function sanitizeUrl($url)
{
if ($url === "") {
$forceGenerate = $GLOBALS['FORCE_PHP_GENERATE'] ?? false;
if (strlen($url) == 0 && $forceGenerate === false) {
trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR);
}

Expand Down
10 changes: 8 additions & 2 deletions src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ private function __construct()
*/
public function getEnabledModules()
{
$testGenerationPhase = $GLOBALS['GENERATE_TESTS'] ?? false;

if (isset($this->enabledModules)) {
return $this->enabledModules;
}

$testGenerationPhase = $GLOBALS['GENERATE_TESTS'] ?? false;
if ($testGenerationPhase) {
$this->printMagentoVersionInfo();
}
Expand All @@ -141,7 +142,7 @@ public function getEnabledModules()
return $this->enabledModules;
}

$url = ConfigSanitizerUtil::sanitizeUrl($_ENV['MAGENTO_BASE_URL']) . $this->moduleUrl;
$url = ConfigSanitizerUtil::sanitizeUrl(getenv('MAGENTO_BASE_URL')) . $this->moduleUrl;

$headers = [
'Authorization: Bearer ' . $token,
Expand Down Expand Up @@ -252,6 +253,11 @@ private function printMagentoVersionInfo()
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

if (!$response) {
$response = "No version information available.";
}

print "\nVersion Information: {$response}\n";
}

Expand Down