Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DomCrawler] Add checkbox assertions for functional tests #38287

merged 1 commit into from Sep 24, 2020


Copy link

@mnapoli mnapoli commented Sep 24, 2020

Branch? master for features
Bug fix? no
New feature? yes
Deprecations? no
License MIT
Doc PR symfony/symfony-docs#...

Add new assertions for checkboxes, to use in functional tests.


    public function testAssertCheckboxChecked()

        $this->client->submitForm('Save', [
            'activateMembership' => 'on',

        // Check that the field is checked after the form was submitted

This wasn't possible to achieve with the existing self::assertInputValueSame() assertion.

Copy link
Contributor Author

mnapoli commented Sep 24, 2020

I also needed to assert on selects and that wasn't possible to add a similar helper.

So I went a different route and opened #38288: I think both PRs can be merged because they can cover different use cases (this PR doesn't require a form).

@nicolas-grekas nicolas-grekas added this to the next milestone Sep 24, 2020
fabpot approved these changes Sep 24, 2020
Copy link

fabpot commented Sep 24, 2020

Thank you @mnapoli.

@fabpot fabpot merged commit af90e1e into symfony:master Sep 24, 2020
3 checks passed
fabpot added a commit that referenced this pull request Sep 24, 2020

This PR was merged into the 5.2-dev branch.


[DomCrawler] Add `assertFormValue()` in `WebTestCase`

| Q             | A
| ------------- | ---
| Branch?       | master for features
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/ files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/ files -->
| Tickets       |
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Add new assertions for checking form values, to use in functional tests.


    public function testForm()

        self::assertNoFormValue('#form', 'activateMembership'); // checkboxes don't have values when unchecked
        self::assertFormValue('#form', 'trialPeriod', '15');

        $this->client->submitForm('Save', [
            'activateMembership' => 'on',
            'trialPeriod' => '7',

        self::assertFormValue('#form', 'activateMembership', 'on');
        self::assertFormValue('#form', 'trialPeriod', '7');

I resorted to using the `->form()` API because:

- checking the value of checkboxes was not possible today via existing assertions (I opened #38287 for that)
- checking the value of selects was impossible using CSS selectors (as far as I know), but possible with the `->form()` helper


c3e0336 [DomCrawler] Add `assertFormValue()` and `assertNoFormValue()` in `WebTestCase`
@mnapoli mnapoli deleted the domcrawler/assert-checkbox branch Sep 24, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
@fabpot fabpot mentioned this pull request Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

4 participants