Skip to content

Commit b3db4a2

Browse files
committed
MQE-2016: Add warning for test materials that violate naming convention
1 parent 1efdb22 commit b3db4a2

File tree

7 files changed

+58
-166
lines changed

7 files changed

+58
-166
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ private function processParserOutput($parserOutput)
150150
}
151151

152152
$filename = $rawEntity[self::_FILENAME] ?? null;
153-
$this->entityNameValidator->validateDataEntityName($name, $filename);
153+
$this->entityNameValidator->validatePascalCase(
154+
$name,
155+
NameValidationUtil::DATA_ENTITY_NAME,
156+
$filename
157+
);
154158
$type = $rawEntity[self::_TYPE] ?? null;
155159
$data = [];
156160
$deprecated = null;
@@ -206,8 +210,8 @@ private function processParserOutput($parserOutput)
206210

207211
$entityDataObjects[$entityDataObject->getName()] = $entityDataObject;
208212
}
209-
$this->entityNameValidator->summarize("data entity name");
210-
$this->entityKeyValidator->summarize("data entity key");
213+
$this->entityNameValidator->summarize(NameValidationUtil::DATA_ENTITY_NAME);
214+
$this->entityKeyValidator->summarize(NameValidationUtil::DATA_ENTITY_KEY);
211215
return $entityDataObjects;
212216
}
213217

@@ -241,7 +245,11 @@ private function processDataElements($entityData)
241245
foreach ($entityData[self::_DATA] as $dataElement) {
242246
$originalDataElementKey = $dataElement[self::_KEY];
243247
$filename = $entityData[self::_FILENAME] ?? null;
244-
$this->entityKeyValidator->validateDataEntityKey($originalDataElementKey, $filename);
248+
$this->entityKeyValidator->validateCamelCase(
249+
$originalDataElementKey,
250+
NameValidationUtil::DATA_ENTITY_KEY,
251+
$filename
252+
);
245253
$dataElementKey = strtolower($originalDataElementKey);
246254
$dataElementValue = $dataElement[self::_VALUE] ?? "";
247255
$dataValues[$dataElementKey] = $dataElementValue;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ private function initialize()
140140

141141
$operationNameValidator = new NameValidationUtil();
142142
foreach ($parserOutput as $dataDefName => $opDefArray) {
143-
$operationNameValidator->validateMetadataOperationName($dataDefName);
143+
$operationNameValidator->validatePascalCase(
144+
$dataDefName,
145+
NameValidationUtil::METADATA_OPERATION_NAME
146+
);
144147

145148
$operation = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_TYPE];
146149
$dataType = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_DATA_TYPE];
@@ -235,7 +238,7 @@ private function initialize()
235238
$deprecated
236239
);
237240
}
238-
$operationNameValidator->summarize("metadata operation name");
241+
$operationNameValidator->summarize(NameValidationUtil::METADATA_OPERATION_NAME);
239242
}
240243

241244
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function __construct()
6262
}
6363

6464
$filename = $pageData[self::FILENAME] ?? null;
65-
$pageNameValidator->validatePageName($pageName, $filename);
65+
$pageNameValidator->validateAffixes($pageName, NameValidationUtil::PAGE, $filename);
6666
$area = $pageData[self::AREA] ?? null;
6767
$url = $pageData[self::URL] ?? null;
6868

@@ -85,7 +85,7 @@ private function __construct()
8585
$this->pageObjects[$pageName] =
8686
new PageObject($pageName, $url, $module, $sectionNames, $parameterized, $area, $filename, $deprecated);
8787
}
88-
$pageNameValidator->summarize("page name");
88+
$pageNameValidator->summarize(NameValidationUtil::PAGE . " name");
8989
}
9090

9191
/**

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,19 @@ private function __construct()
6868
}
6969

7070
$filename = $sectionData[self::FILENAME] ?? null;
71-
$sectionNameValidator->validateSectionName($sectionName, $filename);
71+
$sectionNameValidator->validateAffixes($sectionName, NameValidationUtil::SECTION, $filename);
7272

7373
try {
7474
foreach ($sectionData[SectionObjectHandler::ELEMENT] as $elementName => $elementData) {
7575
if (preg_match('/[^a-zA-Z0-9_]/', $elementName)) {
7676
throw new XmlException(sprintf(self::ELEMENT_NAME_ERROR_MSG, $elementName, $sectionName));
7777
}
7878

79-
$elementNameValidator->validateElementName($elementName, $filename);
79+
$elementNameValidator->validateCamelCase(
80+
$elementName,
81+
NameValidationUtil::SECTION_ELEMENT_NAME,
82+
$filename
83+
);
8084
$elementType = $elementData[SectionObjectHandler::TYPE] ?? null;
8185
$elementSelector = $elementData[SectionObjectHandler::SELECTOR] ?? null;
8286
$elementLocatorFunc = $elementData[SectionObjectHandler::LOCATOR_FUNCTION] ?? null;
@@ -119,8 +123,8 @@ private function __construct()
119123
$sectionDeprecated
120124
);
121125
}
122-
$sectionNameValidator->summarize("section name");
123-
$elementNameValidator->summarize("element name");
126+
$sectionNameValidator->summarize(NameValidationUtil::SECTION . " name");
127+
$elementNameValidator->summarize(NameValidationUtil::SECTION_ELEMENT_NAME);
124128
}
125129

126130
/**

src/Magento/FunctionalTestingFramework/Test/Handlers/ActionGroupObjectHandler.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ private function initActionGroups()
115115
foreach ($neededActionGroup as $actionGroupName => $actionGroupData) {
116116
if (!in_array($actionGroupName, ["nodeName", "xsi:noNamespaceSchemaLocation"])) {
117117
$filename = $actionGroupData[ActionGroupObjectHandler::ACTION_GROUP_FILENAME_ATTRIBUTE];
118-
$actionGroupNameValidator->validateActionGroupName($actionGroupName, $filename);
118+
$actionGroupNameValidator->validatePascalCase(
119+
$actionGroupName,
120+
NameValidationUtil::ACTION_GROUP_NAME,
121+
$filename
122+
);
119123
}
120124

121125
if (!is_array($actionGroupData)) {
@@ -125,7 +129,7 @@ private function initActionGroups()
125129
$this->actionGroups[$actionGroupName] =
126130
$actionGroupObjectExtractor->extractActionGroup($actionGroupData);
127131
}
128-
$actionGroupNameValidator->summarize("action group name");
132+
$actionGroupNameValidator->summarize(NameValidationUtil::ACTION_GROUP_NAME);
129133
}
130134

131135
/**

src/Magento/FunctionalTestingFramework/Test/Handlers/TestObjectHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private function initTestData()
145145
$testNameValidator = new NameValidationUtil();
146146
foreach ($parsedTestArray as $testName => $testData) {
147147
$filename = $testData[TestObjectHandler::TEST_FILENAME_ATTRIBUTE];
148-
$testNameValidator->validateTestName($testName, $filename);
148+
$testNameValidator->validatePascalCase($testName, NameValidationUtil::TEST_NAME, $filename);
149149
if (!is_array($testData)) {
150150
continue;
151151
}
@@ -156,7 +156,7 @@ private function initTestData()
156156
}
157157
}
158158
$exceptionCollector->throwException();
159-
$testNameValidator->summarize("test name");
159+
$testNameValidator->summarize(NameValidationUtil::TEST_NAME);
160160
$testObjectExtractor->getAnnotationExtractor()->validateStoryTitleUniqueness();
161161
$testObjectExtractor->getAnnotationExtractor()->validateTestCaseIdTitleUniqueness();
162162
}

src/Magento/FunctionalTestingFramework/Util/Validation/NameValidationUtil.php

Lines changed: 23 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ class NameValidationUtil
1414
{
1515
const PHP_CLASS_REGEX_PATTERN = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/';
1616

17+
const DATA_ENTITY_NAME = "data entity name";
18+
const DATA_ENTITY_KEY = "data entity key";
19+
const METADATA_OPERATION_NAME = "metadata operation name";
20+
const PAGE = "Page";
21+
const SECTION = "Section";
22+
const SECTION_ELEMENT_NAME = "section element name";
23+
const ACTION_GROUP_NAME = "action group name";
24+
const TEST_NAME = "test name";
25+
1726
/**
1827
* The number of violations this instance has detected.
1928
*
@@ -70,17 +79,18 @@ public static function validateName($name, $type)
7079
}
7180

7281
/**
73-
* Validates data entity names.
82+
* Validates that the string is PascalCase.
7483
*
7584
* @param string $str
85+
* @param string $type
7686
* @param string $filename
7787
* @throws Exception
7888
* @return void
7989
*/
80-
public function validateDataEntityName($str, $filename = null)
90+
public function validatePascalCase($str, $type, $filename = null)
8191
{
8292
if (!ctype_upper($str[0])) {
83-
$message = "The data entity name {$str} should be PascalCase with an uppercase first letter.";
93+
$message = "The {$type} {$str} should be PascalCase with an uppercase first letter.";
8494

8595
if ($filename !== null) {
8696
$message .= " See file {$filename}.";
@@ -97,44 +107,18 @@ public function validateDataEntityName($str, $filename = null)
97107
}
98108

99109
/**
100-
* Validates data entity key names.
110+
* Validates that the string is camelCase.
101111
*
102112
* @param string $str
113+
* @param string $type
103114
* @param string $filename
104115
* @throws Exception
105116
* @return void
106117
*/
107-
public function validateDataEntityKey($str, $filename = null)
118+
public function validateCamelCase($str, $type, $filename = null)
108119
{
109120
if (!ctype_lower($str[0])) {
110-
$message = "The data entity key {$str} should be camelCase with a lowercase first letter.";
111-
112-
if ($filename !== null) {
113-
$message .= " See file {$filename}.";
114-
}
115-
116-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
117-
$message,
118-
[],
119-
false
120-
);
121-
122-
$this->count++;
123-
}
124-
}
125-
126-
/**
127-
* Validates metadata operation names.
128-
*
129-
* @param string $str
130-
* @param string $filename
131-
* @throws Exception
132-
* @return void
133-
*/
134-
public function validateMetadataOperationName($str, $filename = null)
135-
{
136-
if (!ctype_upper($str[0])) {
137-
$message = "The metadata operation name {$str} should be PascalCase with an uppercase first letter.";
121+
$message = "The {$type} {$str} should be camelCase with a lowercase first letter.";
138122

139123
if ($filename !== null) {
140124
$message .= " See file {$filename}.";
@@ -151,133 +135,22 @@ public function validateMetadataOperationName($str, $filename = null)
151135
}
152136

153137
/**
154-
* Validates page names.
155-
*
156-
* @param string $str
157-
* @param string $filename
158-
* @throws Exception
159-
* @return void
160-
*/
161-
public function validatePageName($str, $filename = null)
162-
{
163-
$isPrefixAdmin = substr($str, 0, 5) === "Admin";
164-
$isPrefixStorefront = substr($str, 0, 10) === "Storefront";
165-
$isSuffixPage = substr($str, -4) === "Page";
166-
167-
if ((!$isPrefixAdmin && !$isPrefixStorefront) || !$isSuffixPage) {
168-
$message = "The page name {$str} should follow the pattern {Admin or Storefront}{Description}Page.";
169-
170-
if ($filename !== null) {
171-
$message .= " See file {$filename}.";
172-
}
173-
174-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
175-
$message,
176-
[],
177-
false
178-
);
179-
180-
$this->count++;
181-
}
182-
}
183-
184-
/**
185-
* Validates section names.
138+
* Validates that the string is of the pattern {Admin or Storefront}{Description}{Type}.
186139
*
187140
* @param string $str
141+
* @param string $type
188142
* @param string $filename
189143
* @throws Exception
190144
* @return void
191145
*/
192-
public function validateSectionName($str, $filename = null)
146+
public function validateAffixes($str, $type, $filename = null)
193147
{
194148
$isPrefixAdmin = substr($str, 0, 5) === "Admin";
195149
$isPrefixStorefront = substr($str, 0, 10) === "Storefront";
196-
$isSuffixSection = substr($str, -7) === "Section";
197-
198-
if ((!$isPrefixAdmin && !$isPrefixStorefront) || !$isSuffixSection) {
199-
$message = "The section name {$str} should follow the pattern {Admin or Storefront}{Description}Section.";
200-
201-
if ($filename !== null) {
202-
$message .= " See file {$filename}.";
203-
}
204-
205-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
206-
$message,
207-
[],
208-
false
209-
);
210-
211-
$this->count++;
212-
}
213-
}
214-
215-
/**
216-
* Validates section element names.
217-
*
218-
* @param string $str
219-
* @param string $filename
220-
* @throws Exception
221-
* @return void
222-
*/
223-
public function validateElementName($str, $filename = null)
224-
{
225-
if (!ctype_lower($str[0])) {
226-
$message = "The element name {$str} should be camelCase with a lowercase first letter.";
150+
$isSuffixType = substr($str, -strlen($type)) === $type;
227151

228-
if ($filename !== null) {
229-
$message .= " See file {$filename}.";
230-
}
231-
232-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
233-
$message,
234-
[],
235-
false
236-
);
237-
238-
$this->count++;
239-
}
240-
}
241-
242-
/**
243-
* Validates action group names.
244-
*
245-
* @param string $str
246-
* @param string $filename
247-
* @throws Exception
248-
* @return void
249-
*/
250-
public function validateActionGroupName($str, $filename = null)
251-
{
252-
if (!ctype_upper($str[0])) {
253-
$message = "The action group name {$str} should be PascalCase with an uppercase first letter.";
254-
255-
if ($filename !== null) {
256-
$message .= " See file {$filename}.";
257-
}
258-
259-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
260-
$message,
261-
[],
262-
false
263-
);
264-
265-
$this->count++;
266-
}
267-
}
268-
269-
/**
270-
* Validates test names.
271-
*
272-
* @param string $str
273-
* @param string $filename
274-
* @throws Exception
275-
* @return void
276-
*/
277-
public function validateTestName($str, $filename = null)
278-
{
279-
if (!ctype_upper($str[0])) {
280-
$message = "The test name {$str} should be PascalCase with an uppercase first letter.";
152+
if ((!$isPrefixAdmin && !$isPrefixStorefront) || !$isSuffixType) {
153+
$message = "The {$type} name {$str} should follow the pattern {Admin or Storefront}{Description}{$type}.";
281154

282155
if ($filename !== null) {
283156
$message .= " See file {$filename}.";

0 commit comments

Comments
 (0)