function AssertContentTrait::assertOptionByText

Same name 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()
  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.

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

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