Skip to content

Commit d14cdf8

Browse files
committed
Merge branch 'develop' into MQE-1117
# Conflicts: # src/Magento/FunctionalTestingFramework/Extension/ErrorLogger.php
2 parents 8b2fa37 + 94afc74 commit d14cdf8

38 files changed

+694
-153
lines changed

bin/mftf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (PHP_SAPI !== 'cli') {
1212
}
1313

1414
$autoloadPath = realpath(__DIR__ . '/../../../autoload.php');
15-
$testBootstrapPath = realpath(__DIR__ . '/../dev/tests/functional/_bootstrap.php');
15+
$testBootstrapPath = realpath(__DIR__ . '/../dev/tests/functional/standalone_bootstrap.php');
1616

1717
try {
1818
if (file_exists($autoloadPath)) {

dev/tests/_bootstrap.php

Lines changed: 2 additions & 1 deletion
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/_bootstrap.php renamed to dev/tests/functional/standalone_bootstrap.php

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,30 @@
1212
}
1313

1414
defined('PROJECT_ROOT') || define('PROJECT_ROOT', dirname(dirname(dirname(__DIR__))));
15+
1516
require_once realpath(PROJECT_ROOT . '/vendor/autoload.php');
1617

1718
//Load constants from .env file
18-
defined('FW_BP') || define('FW_BP', PROJECT_ROOT);
19-
20-
// add the debug flag here
21-
$debug_mode = $_ENV['MFTF_DEBUG'] ?? false;
22-
if (!(bool)$debug_mode && extension_loaded('xdebug')) {
23-
xdebug_disable();
24-
}
25-
26-
$RELATIVE_TESTS_MODULE_PATH = '/tests/functional/tests/MFTF';
27-
28-
defined('MAGENTO_BP') || define('MAGENTO_BP', PROJECT_ROOT);
29-
defined('TESTS_BP') || define('TESTS_BP', dirname(dirname(__DIR__)));
30-
defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', realpath(TESTS_BP . $RELATIVE_TESTS_MODULE_PATH));
31-
32-
if (file_exists(TESTS_BP . DIRECTORY_SEPARATOR . '.env')) {
33-
$env = new \Dotenv\Loader(TESTS_BP . DIRECTORY_SEPARATOR . '.env');
19+
$envFilePath = dirname(dirname(__DIR__));
20+
if (file_exists($envFilePath . DIRECTORY_SEPARATOR . '.env')) {
21+
$env = new \Dotenv\Loader($envFilePath . DIRECTORY_SEPARATOR . '.env');
3422
$env->load();
3523

3624
foreach ($_ENV as $key => $var) {
3725
defined($key) || define($key, $var);
3826
}
3927

28+
if (array_key_exists('MAGENTO_BP', $_ENV)) {
29+
// TODO REMOVE THIS CODE ONCE WE HAVE STOPPED SUPPORTING dev/tests/acceptance PATH
30+
// define TEST_PATH and TEST_MODULE_PATH
31+
defined('TESTS_BP') || define('TESTS_BP', dirname(dirname(__DIR__)));
32+
$RELATIVE_TESTS_MODULE_PATH = '/tests/functional/tests/MFTF';
33+
defined('TESTS_MODULE_PATH') || define(
34+
'TESTS_MODULE_PATH',
35+
realpath(TESTS_BP . $RELATIVE_TESTS_MODULE_PATH)
36+
);
37+
}
38+
4039
defined('MAGENTO_CLI_COMMAND_PATH') || define(
4140
'MAGENTO_CLI_COMMAND_PATH',
4241
'dev/tests/acceptance/utils/command.php'
@@ -45,4 +44,28 @@
4544

4645
defined('MAGENTO_CLI_COMMAND_PARAMETER') || define('MAGENTO_CLI_COMMAND_PARAMETER', 'command');
4746
$env->setEnvironmentVariable('MAGENTO_CLI_COMMAND_PARAMETER', MAGENTO_CLI_COMMAND_PARAMETER);
47+
48+
defined('DEFAULT_TIMEZONE') || define('DEFAULT_TIMEZONE', 'America/Los_Angeles');
49+
$env->setEnvironmentVariable('DEFAULT_TIMEZONE', DEFAULT_TIMEZONE);
50+
51+
try {
52+
new DateTimeZone(DEFAULT_TIMEZONE);
53+
} catch (\Exception $e) {
54+
throw new \Exception("Invalid DEFAULT_TIMEZONE in .env: " . DEFAULT_TIMEZONE . PHP_EOL);
55+
}
56+
57+
}
58+
59+
defined('FW_BP') || define('FW_BP', PROJECT_ROOT);
60+
defined('MAGENTO_BP') || define('MAGENTO_BP', PROJECT_ROOT);
61+
defined('TESTS_BP') || define('TESTS_BP', dirname(dirname(__DIR__)));
62+
63+
$RELATIVE_TESTS_MODULE_PATH = '/tests/functional/tests/MFTF';
64+
defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', realpath(TESTS_BP . $RELATIVE_TESTS_MODULE_PATH));
65+
66+
67+
// add the debug flag here
68+
$debug_mode = $_ENV['MFTF_DEBUG'] ?? false;
69+
if (!(bool)$debug_mode && extension_loaded('xdebug')) {
70+
xdebug_disable();
4871
}

dev/tests/unit/Magento/FunctionalTestFramework/Test/Config/ActionGroupDomTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testActionGroupDomStepKeyValidation()
2525
</actionGroups>";
2626

2727
$exceptionCollector = new ExceptionCollector();
28-
$actionDom = new ActionGroupDom($sampleXml, 'dupeStepKeyActionGroup.xml', $exceptionCollector);
28+
new ActionGroupDom($sampleXml, 'dupeStepKeyActionGroup.xml', $exceptionCollector);
2929

3030
$this->expectException(\Exception::class);
3131
$exceptionCollector->throwException();
@@ -47,4 +47,25 @@ public function testActionGroupDomInvalidXmlValidation()
4747
$this->expectExceptionMessage("XML Parse Error: invalid.xml\n");
4848
new ActionGroupDom($sampleXml, 'invalid.xml', $exceptionCollector);
4949
}
50+
51+
/**
52+
* Test detection of two ActionGroups with the same Name in the same file.
53+
*/
54+
public function testActionGroupDomDuplicateActionGroupsValidation()
55+
{
56+
$sampleXml = '<actionGroups>
57+
<actionGroup name="actionGroupName">
58+
<wait time="1" stepKey="key1" />
59+
</actionGroup>
60+
<actionGroup name="actionGroupName">
61+
<wait time="1" stepKey="key1" />
62+
</actionGroup>
63+
</actionGroups>';
64+
65+
$exceptionCollector = new ExceptionCollector();
66+
new ActionGroupDom($sampleXml, 'dupeNameActionGroup.xml', $exceptionCollector);
67+
$this->expectException(\Exception::class);
68+
$this->expectExceptionMessageRegExp("/name: actionGroupName is used more than once./");
69+
$exceptionCollector->throwException();
70+
}
5071
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestFramework\Test\Config;
7+
8+
use Magento\FunctionalTestingFramework\Exceptions\Collector\ExceptionCollector;
9+
use Magento\FunctionalTestingFramework\Config\Dom\ValidationException;
10+
use Magento\FunctionalTestingFramework\Test\Config\ActionGroupDom;
11+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
12+
13+
class DomTest extends MagentoTestCase
14+
{
15+
/**
16+
* Test Test duplicate step key validation
17+
*/
18+
public function testTestStepKeyDuplicateValidation()
19+
{
20+
$sampleXml = '<tests>
21+
<test name="testName">
22+
<comment userInput="step1" stepKey="key1"/>
23+
<comment userInput="step2" stepKey="key1"/>
24+
</test>
25+
</tests>';
26+
27+
$exceptionCollector = new ExceptionCollector();
28+
new ActionGroupDom($sampleXml, 'dupeStepKeyTest.xml', $exceptionCollector);
29+
30+
$this->expectException(\Exception::class);
31+
$this->expectExceptionMessageRegExp("/stepKey: key1 is used more than once. \(Parent: testName\)/");
32+
$exceptionCollector->throwException();
33+
}
34+
35+
/**
36+
* Test detection of two Tests with the same Name in the same file.
37+
*/
38+
public function testTestNameDuplicateValidation()
39+
{
40+
$sampleXml = '<tests>
41+
<test name="testName">
42+
<comment userInput="step1" stepKey="key1"/>
43+
</test>
44+
<test name="testName">
45+
<comment userInput="step1" stepKey="key1"/>
46+
</test>
47+
</tests>';
48+
49+
$exceptionCollector = new ExceptionCollector();
50+
new ActionGroupDom($sampleXml, 'dupeTestsTest.xml', $exceptionCollector);
51+
$this->expectException(\Exception::class);
52+
$this->expectExceptionMessageRegExp("/name: testName is used more than once./");
53+
$exceptionCollector->throwException();
54+
}
55+
}

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

Lines changed: 15 additions & 0 deletions
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]);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Tests\unit\Magento\FunctionalTestFramework\Test\Handlers;
8+
9+
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
10+
use Magento\FunctionalTestingFramework\Test\Util\ActionMergeUtil;
11+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
12+
13+
class ActionMergeUtilTest extends MagentoTestCase
14+
{
15+
/**
16+
* Test Exception Handler for merging actions
17+
*
18+
* @throws \Exception
19+
*/
20+
public function testMergeActionsException()
21+
{
22+
$testActionMergeUtil = new ActionMergeUtil(null, null);
23+
24+
$actionObject = new ActionObject('fakeAction', 'comment', [
25+
'userInput' => '{{someEntity.entity}}'
26+
]);
27+
28+
$this->expectExceptionMessage("Could not resolve entity reference \"{{someEntity.entity}}\" " .
29+
"in Action with stepKey \"fakeAction\".\n" .
30+
"Exception occurred parsing action at StepKey \"fakeAction\"");
31+
32+
$testActionMergeUtil->resolveActionSteps(["merge123" => $actionObject]);
33+
}
34+
}

dev/tests/unit/Magento/FunctionalTestFramework/Util/ModuleResolverTest.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,22 @@ public function testGetModulePathsLocations()
9696
);
9797

9898
// Define the Module paths from app/code
99-
$appCodePath = MAGENTO_BP
100-
. DIRECTORY_SEPARATOR
101-
. 'app' . DIRECTORY_SEPARATOR
102-
. 'code' . DIRECTORY_SEPARATOR;
99+
$magentoBaseCodePath = MAGENTO_BP;
103100

104101
// Define the Module paths from default TESTS_MODULE_PATH
105102
$modulePath = defined('TESTS_MODULE_PATH') ? TESTS_MODULE_PATH : TESTS_BP;
106103

107104
// Define the Module paths from vendor modules
108-
$vendorCodePath = PROJECT_ROOT
109-
. DIRECTORY_SEPARATOR
110-
. 'vendor' . DIRECTORY_SEPARATOR;
105+
$projectRootCodePath = PROJECT_ROOT;
111106

112107
$mockResolver->verifyInvoked('globRelevantPaths', [$modulePath, '']);
113108
$mockResolver->verifyInvoked(
114109
'globRelevantPaths',
115-
[$appCodePath, DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR .'Mftf']
110+
[$magentoBaseCodePath, 'Test' . DIRECTORY_SEPARATOR .'Mftf']
116111
);
117112
$mockResolver->verifyInvoked(
118113
'globRelevantPaths',
119-
[$vendorCodePath, DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR .'Mftf']
114+
[$projectRootCodePath, 'Test' . DIRECTORY_SEPARATOR .'Mftf']
120115
);
121116
}
122117

@@ -151,8 +146,6 @@ public function testGetModulePathsBlacklist()
151146
function ($arg1, $arg2) {
152147
if ($arg2 === "") {
153148
$mockValue = ["somePath" => "somePath"];
154-
} elseif (strpos($arg1, "app")) {
155-
$mockValue = ["otherPath" => "otherPath"];
156149
} else {
157150
$mockValue = ["lastPath" => "lastPath"];
158151
}
@@ -161,7 +154,7 @@ function ($arg1, $arg2) {
161154
);
162155
$resolver = ModuleResolver::getInstance();
163156
$this->setMockResolverProperties($resolver, null, null, ["somePath"]);
164-
$this->assertEquals(["otherPath", "lastPath"], $resolver->getModulesPath());
157+
$this->assertEquals(["lastPath", "lastPath"], $resolver->getModulesPath());
165158
TestLoggingUtil::getInstance()->validateMockLogStatement(
166159
'info',
167160
'excluding module',
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Tests\unit\Magento\FunctionalTestFramework\Test\Handlers;
8+
9+
use AspectMock\Test as AspectMock;
10+
11+
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
12+
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
13+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
14+
use Magento\FunctionalTestingFramework\Util\TestGenerator;
15+
16+
class TestGeneratorTest extends MagentoTestCase
17+
{
18+
/**
19+
* Basic test to check exceptions for incorrect entities.
20+
*
21+
* @throws \Exception
22+
*/
23+
public function testEntityException()
24+
{
25+
$actionObject = new ActionObject('fakeAction', 'comment', [
26+
'userInput' => '{{someEntity.entity}}'
27+
]);
28+
29+
$testObject = new TestObject("sampleTest", ["merge123" => $actionObject], [], [], "filename");
30+
31+
$testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $testObject]);
32+
33+
AspectMock::double(TestGenerator::class, ['loadAllTestObjects' => ["sampleTest" => $testObject]]);
34+
35+
$this->expectExceptionMessage("Could not resolve entity reference \"{{someEntity.entity}}\" " .
36+
"in Action with stepKey \"fakeAction\".\n" .
37+
"Exception occurred parsing action at StepKey \"fakeAction\" in Test \"sampleTest\"");
38+
39+
$testGeneratorObject->createAllTestFiles(null, []);
40+
}
41+
}

dev/tests/unit/Magento/FunctionalTestFramework/Util/Validation/DuplicateNodeValidationUtilTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function testTestActionValidation()
2929
';
3030
$uniqueIdentifier = "stepKey";
3131
$filename = "file";
32+
$testName = "test";
3233

3334
// Perform Test
3435
$dom = new \DOMDocument();
@@ -40,8 +41,7 @@ public function testTestActionValidation()
4041
$validator->validateChildUniqueness(
4142
$testNode,
4243
$filename,
43-
$uniqueIdentifier,
44-
$exceptionCollector
44+
$testName
4545
);
4646
$this->expectException(\Exception::class);
4747
$exceptionCollector->throwException();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_default\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
7+
use \Codeception\Util\Locator;
8+
use Yandex\Allure\Adapter\Annotation\Features;
9+
use Yandex\Allure\Adapter\Annotation\Stories;
10+
use Yandex\Allure\Adapter\Annotation\Title;
11+
use Yandex\Allure\Adapter\Annotation\Description;
12+
use Yandex\Allure\Adapter\Annotation\Parameter;
13+
use Yandex\Allure\Adapter\Annotation\Severity;
14+
use Yandex\Allure\Adapter\Model\SeverityLevel;
15+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
16+
17+
/**
18+
*/
19+
class ActionGroupWithParameterizedElementWithHyphenCest
20+
{
21+
/**
22+
* @Features({"TestModule"})
23+
* @Parameter(name = "AcceptanceTester", value="$I")
24+
* @param AcceptanceTester $I
25+
* @return void
26+
* @throws \Exception
27+
*/
28+
public function ActionGroupWithParameterizedElementWithHyphen(AcceptanceTester $I)
29+
{
30+
$keyoneActionGroup = $I->executeJS("#element .full-width");
31+
}
32+
}

0 commit comments

Comments
 (0)