function AssertContentTrait::assertOptionByText

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertOptionByText()
  2. 8.9.x core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertOptionByText()
  3. 10 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertOptionByText()

Asserts that a select option with the visible text exists.

Parameters

string $id: The ID of the select field to assert.

string $text: The text for the option tag to assert.

string $message: (optional) A message to display with the assertion.

Deprecated

in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement.

See also

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

File

core/tests/Drupal/KernelTests/AssertContentTrait.php, line 1185

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\KernelTests

Code

protected function assertOptionByText($id, $text, $message = '') {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
    $options = $this->xpath('//select[@id=:id]//option[normalize-space(text())=:text]', [
        ':id' => $id,
        ':text' => $text,
    ]);
    $this->assertTrue(isset($options[0]), $message ?: 'Option with text label ' . $text . ' for select field ' . $id . ' exits.');
}

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