jeudi 24 novembre 2016

How to checkmark a checkbox when testing with Laravel

I want to do application testing with Laravels built-in application testing framework. Due to the documentation you can check a checkbox with:

// HTML
<input name="accept-terms" type="checkbox">

// PHP
$this
    ->visit('/foo/bar')
    ->check('accept-terms')

Which works fine. However, sometimes I have a lot of checkboxes. Like:

// HTML
<input id="feature-1" name="features[]" type="checkbox" value="1">
<input id="feature-2" name="features[]" type="checkbox" value="2">
<input id="feature-3" name="features[]" type="checkbox" value="3">

// PHP
$this
    ->visit('/foo/bar')
    ->check('#feature-1')

I can't fetch them by name (as above), so I tried to fetch it by their ID. However, it seems like that's not supported, since I always get a unreachable field error.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire