bencarter78@hotmail.com's avatar

How to test submitting a form with multiple checkboxes

Hi there

When I run my test I get the following error...

InvalidArgumentException: Input "grade_id[]" cannot take "11" as a value (possible values: 1).

I have the following test...

function it_displays_submitted_summaries_with_given_criteria()
    {
        $grades = $this->grades(3);
        $processes = $this->processes(3);
        $sectors = $this->sector(3);

        $this->actingAs($this->judiAdmin())
             ->visit('judi')
             ->submitForm('Search', [
                 'grade_id' => $grades->pluck('id')->all(),
                 'process_id' => $processes->pluck('id')->all(),
                 'sector_id' => $sectors->pluck('id')->all(),
             ])
             ->see('Name')
             ->see('Assessment Date')
             ->see('Outcome');
             ->see($grades[0]->name)
             ->see($processes[0]->name)
             ->see($sectors[0]->name);
    }

If I dd($this-html()) I can see all of my checkboxes as I would expect to see them. I'm guessing the error is saying the possible values (e.g. 1) means 'checked'?

How do you submit multiple checkboxes (i.e. grade_id[] etc) when running tests with Laravel?

0 likes
1 reply
jekinney's avatar

Same as how'd you validate. Also set a known value and expect that value to be passed in the test.

Please or to participate in this conversation.