Skip to content

Commit 53a65de

Browse files
authored
Merge branch 'develop' into MQE-2013
2 parents a5b03de + 5990abb commit 53a65de

File tree

23 files changed

+592
-323
lines changed

23 files changed

+592
-323
lines changed

dev/tests/_bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
true,
3636
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::UNIT_TEST_PHASE,
3737
true,
38-
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::LEVEL_NONE,
38+
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::LEVEL_DEFAULT,
3939
false
4040
);
4141

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ public function testResolveUrl()
233233
*/
234234
public function testResolveUrlWithNoAttribute()
235235
{
236+
$this->expectException(TestReferenceException::class);
237+
236238
// Set up mocks
237239
$actionObject = new ActionObject('merge123', 'amOnPage', [
238240
'url' => '{{PageObject}}'
@@ -247,19 +249,6 @@ public function testResolveUrlWithNoAttribute()
247249

248250
// Call the method under test
249251
$actionObject->resolveReferences();
250-
251-
// Expect this warning to get generated
252-
TestLoggingUtil::getInstance()->validateMockLogStatement(
253-
"warning",
254-
"page url attribute not found and is required",
255-
['action' => $actionObject->getType(), 'url' => '{{PageObject}}', 'stepKey' => $actionObject->getStepKey()]
256-
);
257-
258-
// Verify
259-
$expected = [
260-
'url' => '{{PageObject}}'
261-
];
262-
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
263252
}
264253

265254
/**

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

Lines changed: 167 additions & 57 deletions
Large diffs are not rendered by default.

docs/commands/mftf.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ vendor/bin/mftf generate:tests [option] [<test name>] [<test name>] [--remove]
164164
| `-i,--time` | Set time in minutes to determine the group size when `--config=parallel` is used. The __default value__ is `10`. Example: `generate:tests --config=parallel --time=15`|
165165
| `--tests` | Defines the test configuration as a JSON string.|
166166
| `--allow-skipped` | Allows MFTF to generate and run tests marked with `<skip>.`|
167-
| `--debug or --debug=[<none>]`| Performs schema validations on XML files. <br/> DEFAULT: `generate:tests` implicitly performs schema validation on merged files. It does not indicate the file name where the error is encountered. <br/> DEVELOPER: `--debug` performs per-file validation and returns additional debug information (such as the filename where an error occurred) when test generation fails because of an invalid XML schema. This option takes extra processing time. Use it after test generation has failed once.<br/>NONE: `--debug=none` skips debugging during test generation. Added for backward compatibility, it will be removed in the next MAJOR release.<br/>|
167+
| `--debug` | Performs schema validations on XML files. <br/> DEFAULT: `generate:tests` implicitly performs schema validation on merged files. It does not indicate the file name where the error is encountered. <br/> DEVELOPER: `--debug` performs per-file validation and returns additional debug information (such as the filename where an error occurred) when test generation fails because of an invalid XML schema. This option takes extra processing time. Use it after test generation has failed once.<br/>|
168168
| `-r,--remove`| Removes the existing generated suites and tests cleaning up the `_generated` directory before the actual run. For example, `generate:tests SampleTest --remove` cleans up the entire `_generated` directory and generates `SampleTest` only.|
169169

170170
#### Examples of the JSON configuration
@@ -337,7 +337,7 @@ vendor/bin/mftf run:group [--skip-generate|--remove] [--] <group1> [<group2>]
337337
| --------------------- | --------------------------------------------------------------------------------------------------------- |
338338
| `-k, --skip-generate` | Skips generating from the source XML. Instead, the command executes previously-generated groups of tests. |
339339
| `-r, --remove` | Removes previously generated suites and tests before the actual generation and run. |
340-
| `--debug or --debug=[<none>]`| Performs schema validations on XML files. `run:group` implicitly performs schema validation on merged files. It does not indicate the file name where the error is encountered. `--debug` performs per-file validation and returns additional debug information (such as the filename where an error occurred). `--debug=none` skips debugging during test run. Added for backward compatibility, it will be removed in the next MAJOR release.|
340+
| `--debug` | Performs schema validations on XML files. `run:group` implicitly performs schema validation on merged files. It does not indicate the file name where the error is encountered. `--debug` performs per-file validation and returns additional debug information (such as the filename where an error occurred).|
341341

342342
#### Examples
343343

@@ -369,7 +369,7 @@ vendor/bin/mftf run:test [--skip-generate|--remove] [--] <name1> [<name2>]
369369
|-----------------------|-----------------------------------------------------------------------------------------------------------|
370370
| `-k, --skip-generate` | Skips generating from the source XML. Instead, the command executes previously-generated groups of tests. |
371371
| `-r, --remove` | Remove previously generated suites and tests. |
372-
| `--debug or --debug=[<none>]`| Performs schema validations on XML files. `run:test` implicitly performs schema validation on merged files. It does not indicate the file name where the error is encountered. `--debug` performs per-file validation and returns additional debug information (such as the filename where an error occurred). `--debug=none` skips debugging during test run. Added for backward compatibility, it will be removed in the next MAJOR release.
372+
| `--debug` | Performs schema validations on XML files. `run:test` implicitly performs schema validation on merged files. It does not indicate the file name where the error is encountered. `--debug` performs per-file validation and returns additional debug information (such as the filename where an error occurred).|
373373

374374
#### Examples
375375

@@ -419,7 +419,7 @@ vendor/bin/mftf run:failed
419419

420420
| Option | Description |
421421
|-----------------------|-----------------------------------------------------------------------------------------------------------|
422-
| `--debug or --debug=[<none>]`| Performs schema validations on XML files. `run:failed` implicitly performs schema validation on merged files. It does not indicate the file name where the error is encountered. `--debug` performs per-file validation and returns additional debug information (such as the filename where an error occurred). Use it after test run has failed once. `--debug=none` skips debugging during test run. Added for backward compatibility, it will be removed in the next MAJOR release.|
422+
| `--debug` | Performs schema validations on XML files. `run:failed` implicitly performs schema validation on merged files. It does not indicate the file name where the error is encountered. `--debug` performs per-file validation and returns additional debug information (such as the filename where an error occurred). Use it after test run has failed once.|
423423

424424
#### Examples
425425

src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class MftfApplicationConfig
2323
*/
2424
const LEVEL_DEFAULT = "default";
2525
const LEVEL_DEVELOPER = "developer";
26-
const LEVEL_NONE = "none";
27-
const MFTF_DEBUG_LEVEL = [self::LEVEL_DEFAULT, self::LEVEL_DEVELOPER, self::LEVEL_NONE];
26+
const MFTF_DEBUG_LEVEL = [self::LEVEL_DEFAULT, self::LEVEL_DEVELOPER];
2827

2928
/**
3029
* Contains object with test filters.
@@ -89,7 +88,7 @@ private function __construct(
8988
$forceGenerate = false,
9089
$phase = self::EXECUTION_PHASE,
9190
$verboseEnabled = null,
92-
$debugLevel = self::LEVEL_NONE,
91+
$debugLevel = self::LEVEL_DEFAULT,
9392
$allowSkipped = false,
9493
$filters = []
9594
) {
@@ -101,14 +100,17 @@ private function __construct(
101100

102101
$this->phase = $phase;
103102
$this->verboseEnabled = $verboseEnabled;
104-
switch ($debugLevel) {
103+
if (isset($debugLevel) && !in_array(strtolower($debugLevel), self::MFTF_DEBUG_LEVEL)) {
104+
throw new TestFrameworkException("{$debugLevel} is not a debug level. Use 'DEFAULT' or 'DEVELOPER'");
105+
}
106+
switch (strtolower($debugLevel)) {
105107
case self::LEVEL_DEVELOPER:
106108
case self::LEVEL_DEFAULT:
107-
case self::LEVEL_NONE:
108109
$this->debugLevel = $debugLevel;
109110
break;
110-
default:
111+
case null:
111112
$this->debugLevel = self::LEVEL_DEVELOPER;
113+
break;
112114
}
113115
$this->allowSkipped = $allowSkipped;
114116
$this->filterList = new FilterList($filters);
@@ -131,7 +133,7 @@ public static function create(
131133
$forceGenerate = false,
132134
$phase = self::EXECUTION_PHASE,
133135
$verboseEnabled = null,
134-
$debugLevel = self::LEVEL_NONE,
136+
$debugLevel = self::LEVEL_DEFAULT,
135137
$allowSkipped = false,
136138
$filters = []
137139
) {

src/Magento/FunctionalTestingFramework/Config/Reader/Filesystem.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ protected function readFiles($fileList)
146146
{
147147
/** @var \Magento\FunctionalTestingFramework\Config\Dom $configMerger */
148148
$configMerger = null;
149+
$debugLevel = MftfApplicationConfig::getConfig()->getDebugLevel();
149150
foreach ($fileList as $key => $content) {
150151
//check if file is empty and continue to next if it is
151152
if (!$this->verifyFileEmpty($content, $fileList->getFilename())) {
@@ -157,7 +158,7 @@ protected function readFiles($fileList)
157158
} else {
158159
$configMerger->merge($content);
159160
}
160-
if (MftfApplicationConfig::getConfig()->getDebugLevel() === MftfApplicationConfig::LEVEL_DEVELOPER) {
161+
if (strcasecmp($debugLevel, MftfApplicationConfig::LEVEL_DEVELOPER) == 0) {
161162
$this->validateSchema($configMerger, $fileList->getFilename());
162163
}
163164
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {

src/Magento/FunctionalTestingFramework/Config/Reader/MftfFilesystem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function readFiles($fileList)
4242
$configMerger->merge($content, $fileList->getFilename(), $exceptionCollector);
4343
}
4444
// run per file validation with generate:tests -d
45-
if ($debugLevel === MftfApplicationConfig::LEVEL_DEVELOPER) {
45+
if (strcasecmp($debugLevel, MftfApplicationConfig::LEVEL_DEVELOPER) == 0) {
4646
$this->validateSchema($configMerger, $fileList->getFilename());
4747
}
4848
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {
@@ -52,7 +52,7 @@ public function readFiles($fileList)
5252
$exceptionCollector->throwException();
5353

5454
//run validation on merged file with generate:tests
55-
if ($debugLevel === MftfApplicationConfig::LEVEL_DEFAULT) {
55+
if (strcasecmp($debugLevel, MftfApplicationConfig::LEVEL_DEFAULT) == 0) {
5656
$this->validateSchema($configMerger);
5757
}
5858

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ protected function configure()
5858
'debug',
5959
'd',
6060
InputOption::VALUE_OPTIONAL,
61-
'Run extra validation when generating and running tests. Use option \'none\' to turn off debugging --
62-
added for backward compatibility, will be removed in the next MAJOR release',
61+
'Run extra validation when generating and running tests.',
6362
MftfApplicationConfig::LEVEL_DEFAULT
6463
);
6564
}

src/Magento/FunctionalTestingFramework/Console/GenerateDocsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767
$force,
6868
MftfApplicationConfig::GENERATION_PHASE,
6969
false,
70-
MftfApplicationConfig::LEVEL_NONE,
70+
MftfApplicationConfig::LEVEL_DEFAULT,
7171
true
7272
);
7373

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
123123

124124
// Remove previous GENERATED_DIR if --remove option is used
125125
if ($remove) {
126-
$this->removeGeneratedDirectory($output, $verbose ||
127-
($debug !== MftfApplicationConfig::LEVEL_NONE));
126+
$this->removeGeneratedDirectory($output, $verbose);
128127
}
129128

130129
try {

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/DataObjectHandler.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1515
use Magento\FunctionalTestingFramework\DataGenerator\Util\DataExtensionUtil;
1616
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
17+
use Magento\FunctionalTestingFramework\Util\Validation\NameValidationUtil;
1718

1819
class DataObjectHandler implements ObjectHandlerInterface
1920
{
@@ -58,6 +59,20 @@ class DataObjectHandler implements ObjectHandlerInterface
5859
*/
5960
private $extendUtil;
6061

62+
/**
63+
* Validates and keeps track of entity name violations.
64+
*
65+
* @var NameValidationUtil
66+
*/
67+
private $entityNameValidator;
68+
69+
/**
70+
* Validates and keeps track of entity key violations.
71+
*
72+
* @var NameValidationUtil
73+
*/
74+
private $entityKeyValidator;
75+
6176
/**
6277
* Constructor
6378
*/
@@ -68,6 +83,8 @@ private function __construct()
6883
if (!$parserOutput) {
6984
return;
7085
}
86+
$this->entityNameValidator = new NameValidationUtil();
87+
$this->entityKeyValidator = new NameValidationUtil();
7188
$this->entityDataObjects = $this->processParserOutput($parserOutput);
7289
$this->extendUtil = new DataExtensionUtil();
7390
}
@@ -132,14 +149,19 @@ private function processParserOutput($parserOutput)
132149
throw new XmlException(sprintf(self::DATA_NAME_ERROR_MSG, $name));
133150
}
134151

152+
$filename = $rawEntity[self::_FILENAME] ?? null;
153+
$this->entityNameValidator->validatePascalCase(
154+
$name,
155+
NameValidationUtil::DATA_ENTITY_NAME,
156+
$filename
157+
);
135158
$type = $rawEntity[self::_TYPE] ?? null;
136159
$data = [];
137160
$deprecated = null;
138161
$linkedEntities = [];
139162
$uniquenessData = [];
140163
$vars = [];
141164
$parentEntity = null;
142-
$filename = $rawEntity[self::_FILENAME] ?? null;
143165

144166
if (array_key_exists(self::_DATA, $rawEntity)) {
145167
$data = $this->processDataElements($rawEntity);
@@ -188,7 +210,8 @@ private function processParserOutput($parserOutput)
188210

189211
$entityDataObjects[$entityDataObject->getName()] = $entityDataObject;
190212
}
191-
213+
$this->entityNameValidator->summarize(NameValidationUtil::DATA_ENTITY_NAME);
214+
$this->entityKeyValidator->summarize(NameValidationUtil::DATA_ENTITY_KEY);
192215
return $entityDataObjects;
193216
}
194217

@@ -220,7 +243,14 @@ private function processDataElements($entityData)
220243
{
221244
$dataValues = [];
222245
foreach ($entityData[self::_DATA] as $dataElement) {
223-
$dataElementKey = strtolower($dataElement[self::_KEY]);
246+
$originalDataElementKey = $dataElement[self::_KEY];
247+
$filename = $entityData[self::_FILENAME] ?? null;
248+
$this->entityKeyValidator->validateCamelCase(
249+
$originalDataElementKey,
250+
NameValidationUtil::DATA_ENTITY_KEY,
251+
$filename
252+
);
253+
$dataElementKey = strtolower($originalDataElementKey);
224254
$dataElementValue = $dataElement[self::_VALUE] ?? "";
225255
$dataValues[$dataElementKey] = $dataElementValue;
226256
}

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\FunctionalTestingFramework\ObjectManager\ObjectHandlerInterface;
1313
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1414
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
15+
use Magento\FunctionalTestingFramework\Util\Validation\NameValidationUtil;
1516

1617
class OperationDefinitionObjectHandler implements ObjectHandlerInterface
1718
{
@@ -136,7 +137,14 @@ private function initialize()
136137
$objectManager = ObjectManagerFactory::getObjectManager();
137138
$parser = $objectManager->create(OperationDefinitionParser::class);
138139
$parserOutput = $parser->readOperationMetadata()[OperationDefinitionObjectHandler::ENTITY_OPERATION_ROOT_TAG];
140+
141+
$operationNameValidator = new NameValidationUtil();
139142
foreach ($parserOutput as $dataDefName => $opDefArray) {
143+
$operationNameValidator->validatePascalCase(
144+
$dataDefName,
145+
NameValidationUtil::METADATA_OPERATION_NAME
146+
);
147+
140148
$operation = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_TYPE];
141149
$dataType = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_DATA_TYPE];
142150
$url = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_URL] ?? null;
@@ -230,6 +238,7 @@ private function initialize()
230238
$deprecated
231239
);
232240
}
241+
$operationNameValidator->summarize(NameValidationUtil::METADATA_OPERATION_NAME);
233242
}
234243

235244
/**

src/Magento/FunctionalTestingFramework/Page/Handlers/PageObjectHandler.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1111
use Magento\FunctionalTestingFramework\Page\Objects\PageObject;
1212
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
13+
use Magento\FunctionalTestingFramework\Util\Validation\NameValidationUtil;
1314
use Magento\FunctionalTestingFramework\XmlParser\PageParser;
1415
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
1516

@@ -54,10 +55,14 @@ private function __construct()
5455
return;
5556
}
5657

58+
$pageNameValidator = new NameValidationUtil();
5759
foreach ($parserOutput as $pageName => $pageData) {
5860
if (preg_match('/[^a-zA-Z0-9_]/', $pageName)) {
5961
throw new XmlException(sprintf(self::NAME_BLACKLIST_ERROR_MSG, $pageName));
6062
}
63+
64+
$filename = $pageData[self::FILENAME] ?? null;
65+
$pageNameValidator->validateAffixes($pageName, NameValidationUtil::PAGE, $filename);
6166
$area = $pageData[self::AREA] ?? null;
6267
$url = $pageData[self::URL] ?? null;
6368

@@ -67,7 +72,8 @@ private function __construct()
6772

6873
$module = $pageData[self::MODULE] ?? null;
6974
$sectionNames = array_keys($pageData[self::SECTION] ?? []);
70-
$parameterized = $pageData[self::PARAMETERIZED] ?? false;
75+
$urlContainsMustaches = strpos($url, "{{") !== false && strpos($url, "}}") !== false;
76+
$parameterized = $pageData[self::PARAMETERIZED] ?? $urlContainsMustaches ?? false;
7177
$filename = $pageData[self::FILENAME] ?? null;
7278
$deprecated = $pageData[self::OBJ_DEPRECATED] ?? null;
7379

@@ -81,6 +87,7 @@ private function __construct()
8187
$this->pageObjects[$pageName] =
8288
new PageObject($pageName, $url, $module, $sectionNames, $parameterized, $area, $filename, $deprecated);
8389
}
90+
$pageNameValidator->summarize(NameValidationUtil::PAGE . " name");
8491
}
8592

8693
/**

0 commit comments

Comments
 (0)