You are here

protected function DrupalWebTestCase::getSelectedItem in SimpleTest 7

Same name and namespace in other branches
  1. 6.2 drupal_web_test_case.php \DrupalWebTestCase::getSelectedItem()
  2. 7.2 drupal_web_test_case.php \DrupalWebTestCase::getSelectedItem()

Get the selected value from a select field.

Parameters

$element: SimpleXMLElement select element.

Return value

The selected value or FALSE.

1 call to DrupalWebTestCase::getSelectedItem()
DrupalWebTestCase::assertFieldByXPath in ./drupal_web_test_case.php
Assert that a field exists in the current page by the given XPath.

File

./drupal_web_test_case.php, line 2270

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function getSelectedItem(SimpleXMLElement $element) {
  foreach ($element
    ->children() as $item) {
    if (isset($item['selected'])) {
      return $item['value'];
    }
    elseif ($item
      ->getName() == 'optgroup') {
      if ($value = $this
        ->getSelectedItem($item)) {
        return $value;
      }
    }
  }
  return FALSE;
}