Support the ongoing development of Laravel.io →
Forms Testing

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?

Last updated 2 years ago.
0

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.

Last updated 9 years ago.
0

Dot notation definitely does not work. It complains about an undefined variable comment.

0

Running into this same issue. Ever find a solution?

0

Same issue

0

Sign in to participate in this thread!

Eventy

Your banner here too?

EdRands edrands Joined 3 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.