You are here

protected function AssertContentTrait::assertOptionByText in Drupal 9

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

File

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

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\KernelTests

Code

protected function assertOptionByText($id, $text, $message = '') {
  $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.');
}