mikerice's avatar

Unable to test select fields with array names (5.1)

Hey all,

Currently trying to test some select and multiselect inputs but constantly getting this error and haven't been able to come up with a solution.

Here's an example test block:

        $user = factory('App\Entities\Users\User')->create();

        $this->actingAs($user)
             ->visit('/register/')
             ->select(4, 'industries[]')
             ->press('Complete Registration')
             ->seePageIs('/');

Unfortunately this produces the following error:

There was 1 error:

1) UserRegistrationTest::testUserRegister
Symfony\Component\CssSelector\Exception\SyntaxErrorException: Expected identifier or "*", but <delimiter "]" at 13> found.

Any idea if this is a bug? Or am I doing something wrong?

Thanks!

0 likes
3 replies
ArthurGuy's avatar

I have just run into the same issue, I think it's just one of many limitations with the in build test framework

1 like
pixelpeter's avatar

Alternatively you should be able to select an element by ID attribute.

Unfortunately this is not working too, no matter which field type you have/trying to target.

From the source code it looks like the correct element is found by the Symfony DomCrawler when using the ID attribute. But there seems to be a problem in the FormFieldRegistry when trying to find the element with the &get function.

Can somebody else shed some more light on this ? Maybe @JeffreyWay by himself ?

1 like
ohffs's avatar

Just in case anyone else finds this thread as I did - my work-around was to do for a field called galleries[] :

 $input = [
            'name' => 'NEWNAME',
            'galleries' => [$gallery->id],
 ];
 $this->visit('/whatever')
             ->submitForm('Save Changes', $input)
             ->see('Updated')
             ->see('NEWNAME');
1 like

Please or to participate in this conversation.