I'm using the new built in testing that comes with Laravel 5.1. Awesome stuff. But I've a problem I can't seem to find an answer to.
I have several inputs in a form which use array syntax for the name, so I get an array in my resulting input. That's all fine. The form works manually. What I can't get working is:
$this->type('foo', 'comment[0][name]')
The test complains "Expected identifier or "*", but <number at 10> found."
Since the form is found by css selectors, I thought maybe the brackets needed to be escaped.
$this->type('foo', 'comment\[0\]\[name\]')
Nope. "Nothing matched the filter [comment[0][name]] CSS query provided"
I tried giving the input an id (not name) that was simple like "newComment" but I can't type using the id, with or without a # prefix.
How do I type into an input with an array name?
Not sure, but try dot notation maybe?
$this->type('foo', 'comment.0.name')
EDIT: Whatever you provide as element, its validity is checked via CrawlerTrait\filterByNameOrId()
method, which is:
protected function filterByNameOrId($name, $element = '*')
{
$name = str_replace('#', '', $name);
return $this->crawler->filter("{$element}#{$name}, {$element}[name='{$name}']");
}
Just make sure whatever name you pass to it, it turns out to be valid filter, especially valid XPath context, because underlying Symfony FormFilter class supports XPath.
Dot notation definitely does not work. It complains about an undefined variable comment
.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community