Skip to content

Commit 89bd39a

Browse files
committed
MQE-1057: Update metadata filenames convention
1 parent f1820ff commit 89bd39a

File tree

5 files changed

+74
-11
lines changed

5 files changed

+74
-11
lines changed

docs/metadata.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ The following diagram demonstrates the XML structure of a metadata file:
6767
## Principles {#principles}
6868

6969
1. A `dataType` value must match the `type` value of the corresponding entity.
70-
2. A file name should contain data type split with `_` and must end with `-meta`.
71-
Example: `product_attribute-meta.xml`.
70+
2. A file name should be PascalCase and end with `Meta.xml`.
71+
Example: `ProductAttributeMeta.xml`.
7272
3. A metadata file may contain different types of operations (`type`) with the same data entity (`dataType`).
7373

7474
Example:
@@ -139,7 +139,7 @@ _Catalog/Data/CategoryData.xml_:
139139
Here, `type` is equal to `"category"`, which instructs the MFTF to search an operation with `dataType="category"`.
140140
Since the action is __to create__ a category, the MFTF will also search for operation with `type="create"` in _Metadata_ for `dataType="category"`.
141141

142-
_Catalog/Metadata/category-meta.xml_:
142+
_Catalog/Metadata/CategoryMeta.xml_:
143143

144144
```xml
145145
<operation name="CreateCategory" dataType="category" type="create" auth="adminOauth" url="/V1/categories" method="POST">
@@ -187,10 +187,10 @@ Comments in the example below are used to demonstrate relation between JSON requ
187187
JSON does not support comments.
188188
</div>
189189

190-
Model schema for _catalogCategoryRepositoryV1SavePostBody_ with XML representation of _Catalog/Metadata/category-meta.xml_ in comments:
190+
Model schema for _catalogCategoryRepositoryV1SavePostBody_ with XML representation of _Catalog/Metadata/CategoryMeta.xml_ in comments:
191191

192192
```json
193-
{ // XML representation in the MFTF metadata format (see 'Catalog/Metadata/category-meta.xml')
193+
{ // XML representation in the MFTF metadata format (see 'Catalog/Metadata/CategoryMeta.xml')
194194
"category": { // <object key="category" dataType="category">
195195
"id": 0, // Skipped, because Category ID is not available on UI when you create a new category.
196196
"parent_id": 0, // <field key="parent_id">integer</field>
@@ -206,9 +206,9 @@ Model schema for _catalogCategoryRepositoryV1SavePostBody_ with XML representati
206206
"string" // <value>string</value>
207207
], // </array>
208208
"include_in_menu": true, // <field key="include_in_menu">boolean</field>
209-
"extension_attributes": {}, // <field key="extension_attributes">empty_extension_attribute</field>, where 'empty_extension_attribute' is a reference to operation with 'dataType="empty_extension_attribute"' (see 'Catalog/Metadata/empty_extension_attribute-meta.xml')
209+
"extension_attributes": {}, // <field key="extension_attributes">empty_extension_attribute</field>, where 'empty_extension_attribute' is a reference to operation with 'dataType="empty_extension_attribute"' (see 'Catalog/Metadata/EmptyExtensionAttributeMeta.xml')
210210
"custom_attributes": [ // <array key="custom_attributes">
211-
{ // <value>custom_attribute</value>, where 'custom_attribute' is a reference to operation with 'dataType="custom_attribute"' (see 'Catalog/Metadata/custom_attribute-meta.xml')
211+
{ // <value>custom_attribute</value>, where 'custom_attribute' is a reference to operation with 'dataType="custom_attribute"' (see 'Catalog/Metadata/CustomAttributeMeta.xml')
212212
"attribute_code": "string",
213213
"value": "string"
214214
}
@@ -343,7 +343,7 @@ You are able to create assurances with `successRegex`, and, optionally, return v
343343

344344
The `CreateStoreGroup` operation is used to persist a store group:
345345

346-
Source file is _Store/Metadata/store_group-meta.xml_:
346+
Source file is _Store/Metadata/StoreGroupMeta.xml_:
347347

348348
```xml
349349
<operation name="CreateStoreGroup" dataType="group" type="create" auth="adminFormKey" url="/admin/system_store/save" method="POST" successRegex="/messages-message-success/" >
@@ -379,7 +379,7 @@ The operation enables you to assign the following form fields:
379379

380380
The MFTF uses the `CreateWishlist` operation to create a wish list on storefront:
381381

382-
Source file is _Wishlist/Metadata/wishlist-meta.xml_
382+
Source file is _Wishlist/Metadata/WishlistMeta.xml_
383383

384384
```xml
385385
<operation name="CreateWishlist" dataType="wishlist" type="create" auth="customerFormKey" url="/wishlist/index/add/" method="POST" successRegex="" returnRegex="~\/wishlist_id\/(\d*?)\/~" >

etc/di.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
<argument name="mergeablePaths" xsi:type="array">
199199
<item name="/operations/operation/object" xsi:type="string"/>
200200
</argument>
201-
<argument name="fileName" xsi:type="string">*-meta.xml</argument>
201+
<argument name="fileName" xsi:type="string">*Meta.xml</argument>
202202
<argument name="defaultScope" xsi:type="string">Metadata</argument>
203203
</arguments>
204204
</virtualType>

src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@
109109
<xs:enumeration value="DELETE" />
110110
</xs:restriction>
111111
</xs:simpleType>
112-
</xs:schema>
112+
</xs:schema>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Upgrade;
8+
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Finder\Finder;
11+
12+
/**
13+
* Class RenameMetadataFiles
14+
* @package Magento\FunctionalTestingFramework\Upgrade
15+
*/
16+
class RenameMetadataFiles implements UpgradeInterface
17+
{
18+
/**
19+
* Upgrades all test xml files
20+
*
21+
* @param InputInterface $input
22+
* @return string
23+
*/
24+
public function execute(InputInterface $input)
25+
{
26+
$path = $input->getArgument("path");
27+
$finder = new Finder();
28+
$finder->files()->in($path)->name("*-meta.xml");
29+
30+
foreach ($finder->files() as $file) {
31+
$oldFileName = $file->getFileName();
32+
$newFileName = $this->convertFileName($oldFileName);
33+
$oldPath = $file->getPathname();
34+
$newPath = $file->getPath() . "/" . $newFileName;
35+
print("Renaming " . $oldPath . " => " . $newPath . "\n");
36+
rename($oldPath, $newPath);
37+
}
38+
39+
return "Finished renaming -meta.xml files.";
40+
}
41+
42+
/**
43+
* Convert filenames like:
44+
* user_role-meta.xml => UserRoleMeta.xml
45+
* store-meta.xml => StoreMeta.xml
46+
*
47+
* @param string $oldFileName
48+
* @return string
49+
*/
50+
private function convertFileName(string $oldFileName) {
51+
$stripEnding = preg_replace("/-meta.xml/", "", $oldFileName);
52+
$hyphenToUnderscore = str_replace("-", "_", $stripEnding);
53+
$parts = explode("_", $hyphenToUnderscore);
54+
$ucParts = [];
55+
foreach ($parts as $part) {
56+
$ucParts[] = ucfirst($part);
57+
}
58+
$recombine = join("", $ucParts);
59+
$addEnding = $recombine . "Meta.xml";
60+
return $addEnding;
61+
}
62+
}

src/Magento/FunctionalTestingFramework/Upgrade/UpgradeScriptList.php

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct(array $scripts = [])
2929
{
3030
$this->scripts = [
3131
'upgradeTestSchema' => new UpdateTestSchemaPaths(),
32+
'renameMetadataFiles' => new RenameMetadataFiles()
3233
] + $scripts;
3334
}
3435

0 commit comments

Comments
 (0)