BenoitDesrosiers's avatar

phpunit: how to test that all value are present on view for a radio button

If I have a radio button to select the sex of a user (M/F) how can I unit test that both options are present on the form. I know that I can run a test and select M, save it to database and check that I seeInDatabase, and then do the same with F. But is there a way to verify that M and F are "present" on the view ? see('m') is almost sur to pass because there will be an "m" somewhere on the view.

thanks.

0 likes
3 replies
JoolsMcFly's avatar
Level 2

Hey,

HTML:

                <form method="post">
                    <input type="radio" id="gender-f" name="gender" value="f" />
                    <input type="radio" id="gender-m" name="gender" value="m" />
                    <textarea name="sometextarea">hello world</textarea>
                </form>

tests:

            $this->visit('/');
            $this->seeInField('sometextarea', 'hello world');
            $this->seeInField('gender-m', 'm');
            $this->seeInField('gender-f', 'f');

It won't work if you only set the name property of radio buttons as seeInField will look for one field.

1 like
JoolsMcFly's avatar

Cool. Could you mark my post as answer so your thread appears with a green tick box next to it? Shows your issue is solved. Thanks.

Please or to participate in this conversation.