Skip to content

Commit 38295a4

Browse files
committed
Merge branch 'develop' into MQE-1040
2 parents a070fae + b4a27e5 commit 38295a4

File tree

9 files changed

+70
-2
lines changed

9 files changed

+70
-2
lines changed

dev/tests/_bootstrap.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
'MAGENTO_BASE_URL' => 'http://baseurl:8080',
4141
'MAGENTO_BACKEND_NAME' => 'admin',
4242
'MAGENTO_ADMIN_USERNAME' => 'admin',
43-
'MAGENTO_ADMIN_PASSWORD' => 'admin123'
43+
'MAGENTO_ADMIN_PASSWORD' => 'admin123',
44+
'DEFAULT_TIMEZONE' => 'America/Los_Angeles'
4445
];
4546

4647
foreach ($TEST_ENVS as $key => $value) {

dev/tests/functional/standalone_bootstrap.php

+10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@
4545

4646
defined('MAGENTO_CLI_COMMAND_PARAMETER') || define('MAGENTO_CLI_COMMAND_PARAMETER', 'command');
4747
$env->setEnvironmentVariable('MAGENTO_CLI_COMMAND_PARAMETER', MAGENTO_CLI_COMMAND_PARAMETER);
48+
49+
defined('DEFAULT_TIMEZONE') || define('DEFAULT_TIMEZONE', 'America/Los_Angeles');
50+
$env->setEnvironmentVariable('DEFAULT_TIMEZONE', DEFAULT_TIMEZONE);
51+
52+
try {
53+
new DateTimeZone(DEFAULT_TIMEZONE);
54+
} catch (\Exception $e) {
55+
throw new \Exception("Invalid DEFAULT_TIMEZONE in .env: " . DEFAULT_TIMEZONE . PHP_EOL);
56+
}
57+
4858
}
4959

5060
defined('FW_BP') || define('FW_BP', PROJECT_ROOT);

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

+15
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,21 @@ public function testTooManyArgumentException()
370370
$actionObject->resolveReferences();
371371
}
372372

373+
/**
374+
* Action object should throw an exception if the timezone provided is not valid.
375+
*/
376+
public function testInvalidTimezoneException()
377+
{
378+
$this->expectException(TestReferenceException::class);
379+
380+
$actionObject = new ActionObject('key123', 'generateDate', [
381+
'timezone' => "INVALID_TIMEZONE"
382+
]);
383+
384+
// Call the method under test
385+
$actionObject->resolveReferences();
386+
}
387+
373388
private function mockSectionHandlerWithElement($elementObject)
374389
{
375390
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);

dev/tests/verification/Resources/BasicFunctionalTest.txt

+4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class BasicFunctionalTestCest
107107
$date->setTimestamp(strtotime("Now"));
108108
$date->setTimezone(new \DateTimeZone("America/Los_Angeles"));
109109
$generateDateKey = $date->format("H:i:s");
110+
$date = new \DateTime();
111+
$date->setTimestamp(strtotime("Now"));
112+
$date->setTimezone(new \DateTimeZone("UTC"));
113+
$generateDateKey2 = $date->format("H:i:s");
110114
$grabAttributeFromKey1 = $I->grabAttributeFrom(".functionalTestSelector", "someInput");
111115
$grabCookieKey1 = $I->grabCookie("grabCookieInput", ['domain' => 'www.google.com']);
112116
$grabFromCurrentUrlKey1 = $I->grabFromCurrentUrl("/grabCurrentUrl");

dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<fillField selector=".functionalTestSelector" userInput="someInput" stepKey="fillFieldKey1" />
6363
<fillField selector=".functionalTestSelector" userInput="0" stepKey="fillFieldKey2" />
6464
<generateDate date="Now" format="H:i:s" stepKey="generateDateKey"/>
65+
<generateDate date="Now" format="H:i:s" stepKey="generateDateKey2" timezone="UTC"/>
6566
<grabAttributeFrom selector=".functionalTestSelector" userInput="someInput" stepKey="grabAttributeFromKey1" />
6667
<grabCookie userInput="grabCookieInput" parameterArray="['domain' => 'www.google.com']" stepKey="grabCookieKey1" />
6768
<grabFromCurrentUrl regex="/grabCurrentUrl" stepKey="grabFromCurrentUrlKey1" />

etc/config/.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ BROWSER=chrome
3131
#FW_BP=
3232
#TESTS_MODULE_PATH=
3333

34+
#*** Uncomment this property to change the default timezone MFTF will use for the generateDate action ***#
35+
#DEFAULT_TIMEZONE=America/Los_Angeles
36+
3437
#*** These properties impact the modules loaded into MFTF, you can point to your own full path, or a custom set of modules located with the core set
3538
MODULE_WHITELIST=Magento_Framework,Magento_ConfigurableProductWishlist,Magento_ConfigurableProductCatalogSearch
3639
#CUSTOM_MODULE_PATHS=

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

+25
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/**
2121
* Class ActionObject
22+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2223
*/
2324
class ActionObject
2425
{
@@ -62,6 +63,7 @@ class ActionObject
6263
const FUNCTION_CLOSURE_ACTIONS = ['waitForElementChange', 'performOn'];
6364
const MERGE_ACTION_ORDER_AFTER = 'after';
6465
const MERGE_ACTION_ORDER_BEFORE = 'before';
66+
const ACTION_ATTRIBUTE_TIMEZONE = 'timezone';
6567
const ACTION_ATTRIBUTE_URL = 'url';
6668
const ACTION_ATTRIBUTE_SELECTOR = 'selector';
6769
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/';
@@ -256,6 +258,7 @@ public function resolveReferences()
256258
$this->resolveSelectorReferenceAndTimeout();
257259
$this->resolveUrlReference();
258260
$this->resolveDataInputReferences();
261+
$this->validateTimezoneAttribute();
259262
if ($this->getType() == "deleteData") {
260263
$this->validateMutuallyExclusiveAttributes(self::DELETE_DATA_MUTUAL_EXCLUSIVE_ATTRIBUTES);
261264
}
@@ -599,6 +602,28 @@ private function validateUrlAreaAgainstActionType($obj)
599602
}
600603
}
601604

605+
/**
606+
* Validates that the timezone attribute contains a valid value.
607+
*
608+
* @return void
609+
* @throws TestReferenceException
610+
*/
611+
private function validateTimezoneAttribute()
612+
{
613+
$attributes = $this->getCustomActionAttributes();
614+
if (isset($attributes[self::ACTION_ATTRIBUTE_TIMEZONE])) {
615+
$timezone = $attributes[self::ACTION_ATTRIBUTE_TIMEZONE];
616+
try {
617+
new \DateTimeZone($timezone);
618+
} catch (\Exception $e) {
619+
throw new TestReferenceException(
620+
"Timezone '{$timezone}' is not a valid timezone",
621+
["stepKey" => $this->getStepKey(), self::ACTION_ATTRIBUTE_TIMEZONE => $timezone]
622+
);
623+
}
624+
}
625+
}
626+
602627
/**
603628
* Gets the object's dataByName with given $match, differentiating behavior between <array> and <data> nodes.
604629
* @param string $obj

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
12831283
$testSteps .= $argRef;
12841284
break;
12851285
case "generateDate":
1286-
$timezone = "America/Los_Angeles";
1286+
$timezone = getenv("DEFAULT_TIMEZONE");
12871287
if (isset($customActionAttributes['timezone'])) {
12881288
$timezone = $customActionAttributes['timezone'];
12891289
}

src/Magento/FunctionalTestingFramework/_bootstrap.php

+9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040

4141
defined('MAGENTO_CLI_COMMAND_PARAMETER') || define('MAGENTO_CLI_COMMAND_PARAMETER', 'command');
4242
$env->setEnvironmentVariable('MAGENTO_CLI_COMMAND_PARAMETER', MAGENTO_CLI_COMMAND_PARAMETER);
43+
44+
defined('DEFAULT_TIMEZONE') || define('DEFAULT_TIMEZONE', 'America/Los_Angeles');
45+
$env->setEnvironmentVariable('DEFAULT_TIMEZONE', DEFAULT_TIMEZONE);
46+
47+
try {
48+
new DateTimeZone(DEFAULT_TIMEZONE);
49+
} catch (\Exception $e) {
50+
throw new \Exception("Invalid DEFAULT_TIMEZONE in .env: " . DEFAULT_TIMEZONE . PHP_EOL);
51+
}
4352
}
4453

4554

0 commit comments

Comments
 (0)