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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -255,6 +255,35 @@ public function testResolveDataInUserInput()
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
}

/**
* {{EntityDataObject.values}} should be replaced with ["value1","value2"]
*/
public function testResolveArrayData()
{
// Set up mocks
$actionObject = new ActionObject('merge123', 'fillField', [
'selector' => '#selector',
'userInput' => '{{EntityDataObject.values}}'
]);
$entityDataObject = new EntityDataObject('EntityDataObject', 'test', [
'values' => [
'value1',
'value2'
]
], [], '', '');
$this->mockDataHandlerWithData($entityDataObject);

// Call the method under test
$actionObject->resolveReferences();

// Verify
$expected = [
'selector' => '#selector',
'userInput' => '["value1","value2"]'
];
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
}

/**
* Action object should throw an exception if a reference to a parameterized selector has too few given args.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

$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

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.

}

$outputString = str_replace($match, $replacement, $outputString);
}
return $outputString;
Expand Down