zenstruck / browser

A fluent interface for your Symfony functional tests.
MIT License
186 stars 17 forks source link

assertChecked and assertNotChecked on Symfony ChoiceType #100

Open Chris53897 opened 2 years ago

Chris53897 commented 2 years ago

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')

kbond commented 2 years ago

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)

Chris53897 commented 2 years ago

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.