You are here

protected function AssertContentTrait::getAllOptions in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getAllOptions()
  2. 10 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getAllOptions()

Get all option elements, including nested options, in a select.

Parameters

\SimpleXMLElement $element: The element for which to get the options.

Return value

\SimpleXmlElement[] Option elements in select.

1 call to AssertContentTrait::getAllOptions()
AssertContentTrait::assertFieldsByValue in core/tests/Drupal/KernelTests/AssertContentTrait.php
Asserts that a field exists in the current page with a given Xpath result.

File

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

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\KernelTests

Code

protected function getAllOptions(\SimpleXMLElement $element) {
  $options = [];

  // Add all options items.
  foreach ($element->option as $option) {
    $options[] = $option;
  }

  // Search option group children.
  if (isset($element->optgroup)) {
    foreach ($element->optgroup as $group) {
      $options = array_merge($options, $this
        ->getAllOptions($group));
    }
  }
  return $options;
}