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 3 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 @@ -255,6 +255,36 @@ 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',
'"My" Value'
]
], [], '', '');
$this->mockDataHandlerWithData($entityDataObject);

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

// Verify
$expected = [
'selector' => '#selector',
'userInput' => '["value1","value2","\"My\" Value"]'
];
$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 @@ -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.

}

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

Expand Down