Skip to content

MQE-2126: Can't modify DataEntity data #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
<entity name="DeprecatedMessageData" deprecated="Entity is deprecated. Please use 'MessageData'.">
<data key="message">Introduction to the Magento Functional Testing Framework</data>
</entity>
<entity name="MessageData">
<data key="justSomeField">Some data</data>
</entity>
</entities>
16 changes: 16 additions & 0 deletions dev/tests/functional/tests/MFTF/DevDocs/Data/ExtendMessageData.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd">
<entity name="MessageData">
<array key="numbers">
<item>Something New</item>
</array>
</entity>
</entities>
6 changes: 6 additions & 0 deletions dev/tests/functional/tests/MFTF/DevDocs/Data/MessageData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
<entity name="MessageData">
<data key="message">Introduction to the Magento Functional Testing Framework</data>
<array key="numbers">
<item name="zero">0</item>
<item name="one">1</item>
<item name="two">2</item>
<item name="three">3</item>
</array>
</entity>
</entities>
5 changes: 5 additions & 0 deletions dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@
<argument name="test" value="{{HelperData.entityField}}" />
<argument name="entityTest" value="HelperData" />
</actionGroup>

<assertEqualsCanonicalizing stepKey="assertMergedArray">
<actualResult type="array">{{MessageData.numbers}}</actualResult>
<expectedResult type="array">["Something New", "0", "1", "2", "3"]</expectedResult>
</assertEqualsCanonicalizing>
</test>
</tests>
5 changes: 5 additions & 0 deletions docs/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ Attributes|Type|Use|Description

`<item>` is an individual piece of data to be passed in as part of the parent `<array>` type.

Attributes|Type|Use|Description
---|---|---|---
`name`|string|optional|Key attribute of <item/> entity in which to assign a value. By default numeric key will be generated.


<!-- Link Definitions -->
[`<array>`]: #array-tag
[`<data>`]: #data-tag
Expand Down
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<argument name="idAttributes" xsi:type="array">
<item name="/entities/entity" xsi:type="string">name</item>
<item name="/entities/entity/(data|array)" xsi:type="string">key</item>
<item name="/entities/entity/array/item" xsi:type="string">name</item>
<item name="/entities/entity/requiredEntity" xsi:type="string">type</item>
</argument>
<argument name="mergeablePaths" xsi:type="array">
Expand Down
4 changes: 2 additions & 2 deletions src/Magento/FunctionalTestingFramework/Config/Dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ protected function getNodePathByParent(\DOMElement $node, $parentPath)
$idAttribute = $this->nodeMergingConfig->getIdAttribute($path);
if ($idAttribute) {
foreach (explode('|', $idAttribute) as $idAttributeValue) {
if ($value = $node->getAttribute($idAttributeValue)) {
$path .= "[@{$idAttributeValue}='{$value}']";
if ($node->hasAttribute($idAttributeValue)) {
$path .= "[@{$idAttributeValue}='" . $node->getAttribute($idAttributeValue) . "']";
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public function initDom($xml, $filename = null)
}
}

$itemNodes = $dom->getElementsByTagName('item');
/** @var \DOMElement $itemNode */
foreach ($itemNodes as $itemKey => $itemNode) {
if ($itemNode->hasAttribute("name") == false) {
$itemNode->setAttribute("name", (string)$itemKey);
}
}
return $dom;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,32 @@

<xs:complexType name="arrayType">
<xs:sequence>
<xs:element name="item" type="xs:string" maxOccurs="unbounded" minOccurs="0">
<xs:annotation>
<xs:documentation>
Individual piece of data to be passed in as part of the parrent array type.
</xs:documentation>
</xs:annotation>
<xs:element name="item" type="itemType" maxOccurs="unbounded" minOccurs="0">
<xs:annotation>
<xs:documentation>
Individual piece of data to be passed in as part of the parrent array type.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="key" use="required"/>
</xs:complexType>


<xs:complexType name="itemType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name" use="optional">
<xs:annotation>
<xs:documentation>
Key attribute of item pair.
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="requiredEntityType">
<xs:simpleContent>
<xs:extension base="xs:string">
Expand Down