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. 11.x 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 1103

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.');
}

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