Support the ongoing development of Laravel.io →
posted 8 years ago
Testing
Last updated 2 years ago.
0

If you specify the index for the multiple checkbox in both your form and test, then it works. Form:

    <input id="department_1" name="departments[0]" type="checkbox" value="1">
    <input id="department_2" name="departments[1]" type="checkbox" value="2">

Unit test:

    public function testUserCreation()
        {
            $this->be(User::find(10));
    
            $this->visit('/users/create')
                ->type('First', 'first_name')
                ->type('Last', 'last_name')
                ->type('[email protected]', 'email')
                ->type('123456', 'password')
                ->type('123456', 'password_confirmation')
                ->check('departments[0]')
                ->press('Submit')
                ->seePageIs('/users');
        }

Using named indexes works as well.

    <input name="departments[department_1]" type="checkbox" value="1">
    // [...]
    $this->check('departments[department_1]');
0

Sign in to participate in this thread!

Eventy

Your banner here too?

gyan111 gyan111 Joined 22 Sep 2015

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.

© 2024 Laravel.io - All rights reserved.