Skip to content

Add ability to use array entities as arguments. #89

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 4 commits into from
Apr 19, 2018

Conversation

nathanjosiah
Copy link
Contributor

@nathanjosiah nathanjosiah commented Apr 6, 2018

Added support for passing array entities as arguments.

Description

As a Test Engineer I want to pass data entity arrays as arguments so that don't have to use hard-coded flat arrays.

For example:

The Entity

<entities>
    <entity name="DefaultCustomerGroup" type="customerGroup">
        <array key="group_names">
            <item>Default</item>
        </array>
    </entity>
</entities>

The ActionGroup

<actionGroups>
    <actionGroup name="searchAndMultiSelectActionGroup">
        <arguments>
            <argument name="options" />
        </arguments>
        <selectMultipleOptions filterSelector="foo" optionSelector="bar" stepKey="selectSpecifiedOptions">
            <array>{{options}}</array>
        </selectMultipleOptions>
    </actionGroup>
</actionGroups>

The Test

<tests>
    <test name="AdminCreateCustomerTest">
        <actionGroup ref="searchAndMultiSelectActionGroup" stepKey="searchAndSelectGroup">
            <argument name="options" value="DefaultCustomerGroup.group_names"/>
        </actionGroup>
    </test>
</tests>

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/verification tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)
  • Changes to Framework doesn't have backward incompatible changes for tests or have related Pull Request with fixes to tests

@magento-cicd2
Copy link

magento-cicd2 commented Apr 6, 2018

CLA assistant check
All committers have signed the CLA.

@coveralls
Copy link

Coverage Status

Coverage increased (+9.7%) to 61.012% when pulling 00b21e3 on magento-borg:resolve-array-data into 2fe0d2a on magento:develop.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+9.7%) to 61.012% when pulling 00b21e3 on magento-borg:resolve-array-data into 2fe0d2a on magento:develop.

@coveralls
Copy link

coveralls commented Apr 6, 2018

Coverage Status

Coverage increased (+0.02%) to 50.316% when pulling 9bce276 on magento-borg:resolve-array-data into 8d6eadf on magento:develop.

@@ -496,6 +496,10 @@ private function findAndReplaceReferences($objectHandler, $inputString)

$replacement = $this->resolveParameterization($parameterized, $replacement, $match, $obj);

if (is_array($replacement)) {
$replacement = '["' . implode('","', $replacement) . '"]';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware this would be insufficient escapement but I wasn't sure how far this needed to go. I figured if nothing else this PR serves as a proof of concept and opens the conversation to this feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathanjosiah, by insufficient escapement do you mean how it assumes that the array members are strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KevinBKozan Unless multidimensional arrays have a use case then I'm not thinking as much about that. I was thinking more about if the items contain quotes or $. The resulting Codception unit test would potentially be malformed or inadvertently contain PHP variable interpolation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Let me leave some review comments on some small stuff then!

Copy link
Contributor

@KevinBKozan KevinBKozan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small changes requested, but otherwise good work and thank you for diving into it!

@@ -496,6 +496,10 @@ private function findAndReplaceReferences($objectHandler, $inputString)

$replacement = $this->resolveParameterization($parameterized, $replacement, $match, $obj);

if (is_array($replacement)) {
$replacement = '["' . implode('","', $replacement) . '"]';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should array_walk/array_map with addSlashes to break quotes at the very least. Inadvertend variable interpolation in MFTF is not yet handled, so this is not introducing anything new.

@@ -496,6 +496,10 @@ private function findAndReplaceReferences($objectHandler, $inputString)

$replacement = $this->resolveParameterization($parameterized, $replacement, $match, $obj);

if (is_array($replacement)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should either live in the elseif block in 497, or in the resolveEntityDataObjectReference() function. This conditional only ever applies to EntityDataObjects, so checking it every time is unecessary.

@nathanjosiah
Copy link
Contributor Author

@KevinBKozan I updated my branch with the requested changed and merged mainline and ran tests to verify current compatibility.

Copy link
Contributor

@KevinBKozan KevinBKozan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't very clear in my first feedback, my apologies. Still need to move the new conditional.

@@ -504,6 +504,9 @@ private function findAndReplaceReferences($objectHandler, $inputString)
throw new TestReferenceException("Could not resolve entity reference " . $inputString);
}
}
elseif (is_array($replacement)) {
$replacement = '["' . implode('","', array_map('addSlashes',$replacement)) . '"]';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathanjosiah my bad, I don't think I was very clear about this portion. I meant that your addition should be entirely inside the elseif on line 496; that elseif is the portion that deals with the object passed in being an EntityDataObject. Since the only time $replacement could only ever be an array is if it's an array inside an EntityDataObject, we should only every have to check it inside that conditional.

Does that make sense?

Copy link
Contributor Author

@nathanjosiah nathanjosiah Apr 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KevinBKozan Ah, yes I see what you mean. I have pushed an updated.

@nathanjosiah
Copy link
Contributor Author

@KevinBKozan I have updated the code and the Travis build is now passing.

@KevinBKozan
Copy link
Contributor

@nathanjosiah Awesome. Code additions look good and all the builds are passing, thank you very much for the contribution!

@KevinBKozan KevinBKozan merged commit 2bdc905 into magento:develop Apr 19, 2018
@nathanjosiah nathanjosiah deleted the resolve-array-data branch April 20, 2018 16:40
magento-devops-reposync-svc pushed a commit that referenced this pull request Aug 3, 2021
…2-functional-testing-framework-843

[Imported] MFTF-33305: Eliminate AspectMock from ObjectExtensionUtilTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants