function AssertLegacyTrait::assertOptionSelected

Same name and namespace in other branches
  1. 9 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.

30 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
BlockUiTest::testBlockAdminUiPage in core/modules/block/tests/src/Functional/BlockUiTest.php
Test block admin page exists and functions correctly.
BookTest::testBookOutline in core/modules/book/tests/src/Functional/BookTest.php
Tests outline of a book.
BrowserTestBaseTest::testFieldAssertsForOptions in core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
Tests legacy field asserts for options field type.

... See full list

File

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

Class

AssertLegacyTrait
Provides convenience methods for assertions in browser tests.

Namespace

Drupal\FunctionalTests

Code

protected function assertOptionSelected($id, $option, $message = NULL) {
    $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.