browser icon indicating copy to clipboard operation
browser copied to clipboard

assertChecked and assertNotChecked on Symfony ChoiceType

Open Chris53897 opened this issue 2 years ago • 2 comments

I have a ChoiceType in Symfony.

->add('assignedRoles', ChoiceType::class, [
                'expanded' => true, 
                'multiple' => true, 
                'choices' => $this->allRoles,
                'choice_label' => function ($item) { return 'system.role.'.str_replace("role_","", strtolower($item)); },
                'choice_value' => function ($item) { return $item; }
 ])

HTML (github has problems with < and >)

<input type="checkbox" id="user_edit_form_assignedRoles_3" name="user_edit_form[assignedRoles][]" class="form-check-input" value="bar" />
<label class="form-check-label" for="user_edit_form_assignedRoles_3">bar</label>

<input type="checkbox" id="user_edit_form_assignedRoles_4" name="user_edit_form[assignedRoles][]" class="form-check-input" value="bar" />
<label class="form-check-label" for="user_edit_form_assignedRoles_4">foo</label>

Check/Uncheck of Checkboxes is working ->checkField('foo') ->uncheckField('foo')

But ->assertChecked('bar') is always true. But it is not checked. ->assertNotChecked('bar') fails too.

Am i doing something wrong? I tried the assertNotSelected() function as well. ->assertNotSelected('user_edit_form[assignedRoles][]', 'foo')

Chris53897 avatar Aug 19 '22 13:08 Chris53897

Strange. I wonder if it has something to do with the nested nature of your expanded checkbox list (I don't believe the tests cover this specific scenario). Are you using PantherBrowser or KernelBrowser.

(I updated your description to improve readability)

kbond avatar Aug 19 '22 17:08 kbond

I am using the PantherBrowser. I will search if Mink (Behat\Mink\WebAssert) has a function for that Use-Case. Maybe this Repo can add a function to it, if i found a solution. But that has not a top priority for now for me. I need to write tests for the whole App first.

Chris53897 avatar Aug 23 '22 06:08 Chris53897