function AssertLegacyTrait::assertOptionSelected

Same name in other branches
  1. 8.9.x core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php \Drupal\FunctionalTests\AssertLegacyTrait::assertOptionSelected()

Asserts that a select option in the current page is checked.

Parameters

string $id: ID of select field to assert.

string $option: Option to assert.

string $message: (optional) A message to display with the assertion. Do not translate messages with t(). If left blank, a default message will be displayed.

Deprecated

in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead and check the "selected" attribute yourself.

See also

https://www.drupal.org/node/3129738

2 calls to AssertLegacyTrait::assertOptionSelected()
AssertLegacyTraitTest::testAssertOptionSelected in core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@covers ::assertOptionSelected
AssertLegacyTraitTest::testAssertOptionSelectedFail in core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@covers ::assertOptionSelected

File

core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php, line 616

Class

AssertLegacyTrait
Provides convenience methods for assertions in browser tests.

Namespace

Drupal\FunctionalTests

Code

protected function assertOptionSelected($id, $option, $message = NULL) {
    @trigger_error('AssertLegacyTrait::assertOptionSelected() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead and check the "selected" attribute. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
    $option_field = $this->assertSession()
        ->optionExists($id, $option);
    $message = $message ?: "Option {$option} for field {$id} is selected.";
    $this->assertTrue($option_field->hasAttribute('selected'), $message);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.