You are here

protected function FeedsWebTestCase::assertFieldByXPath in Feeds 7.2

Overrides DrupalWebTestCase::assertFieldByXPath().

The core version has a bug, this is the D8 version.

@todo Remove once https://drupal.org/node/2105617 lands.

Overrides DrupalWebTestCase::assertFieldByXPath

File

tests/feeds.test, line 443
Common functionality for all Feeds tests.

Class

FeedsWebTestCase
Test basic Data API functionality.

Code

protected function assertFieldByXPath($xpath, $value = NULL, $message = '', $group = 'Other') {
  $fields = $this
    ->xpath($xpath);

  // If value specified then check array for match.
  $found = TRUE;
  if (isset($value)) {
    $found = FALSE;
    if ($fields) {
      foreach ($fields as $field) {
        if (isset($field['value']) && $field['value'] == $value) {

          // Input element with correct value.
          $found = TRUE;
        }
        elseif (isset($field->option) || isset($field->optgroup)) {

          // Select element found.
          $selected = $this
            ->getSelectedItem($field);
          if ($selected === FALSE) {

            // No item selected so use first item.
            $items = $this
              ->getAllOptions($field);
            if (!empty($items) && $items[0]['value'] == $value) {
              $found = TRUE;
            }
          }
          elseif ($selected == $value) {
            $found = TRUE;
          }
        }
        elseif ((string) $field == $value) {

          // Text area with correct text.
          $found = TRUE;
        }
      }
    }
  }
  return $this
    ->assertTrue($fields && $found, $message, $group);
}