You are here

protected function AssertContentTrait::assertOptionByText in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertOptionByText()
  2. 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.

Return value

bool TRUE on pass, FALSE on fail.

File

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

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,
  ]);
  return $this
    ->assertTrue(isset($options[0]), $message ?: 'Option with text label ' . $text . ' for select field ' . $id . ' exits.');
}