You are here

protected function AssertContentTrait::getAllOptions in Drupal 8

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

2 calls 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.
WebTestBase::handleForm in core/modules/simpletest/src/WebTestBase.php
Handles form input related to drupalPostForm().

File

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

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;
}