How do I access a child entity field for reference in an MFTF Test
-
06-03-2021 - |
Question
I need assistance trying to access a field of a required entity inside a parent entity created for a test
Example I am trying to create a configurable product
<createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttributes">
The entity for that looks like this
<entity name="productAttributeWithTwoOptions" type="ProductAttribute">
<data key="attribute_code" unique="suffix">attribute</data>
<data key="frontend_input">select</data>
...
<data key="used_for_sort_by">true</data>
<requiredEntity type="FrontendLabel">ProductAttributeFrontendLabel</requiredEntity>
</entity>
In the test how could I access the label field from the FrontendLabel required entity?
<entity name="ProductAttributeFrontendLabel" type="FrontendLabel">
<data key="store_id">0</data>
<data key="label" unique="suffix">attribute</data>
</entity>
I assumed it might be something like this {{createConfigProductAttributes.ProductAttributeFrontendLabel.label}}
Solution
Using XDebug with Codeception https://devdocs.magento.com/mftf/docs/debugging.html I was able to see what the generated data entities looked like.
MFTF flattens the data returned by the createData action and so I was able to access the data needed by referencing it like this
$createConfigProductAttributeWithTwoOptions.attribute[frontend_labels][0][label]$