1.20.x field_views.test public FieldViewsFieldTest::_testMultipleFieldRender()

File

modules/field/tests/field_views.test, line 351
Tests the Views integration with Field API.

Class

FieldViewsFieldTest
Tests the field_field handler. @TODO Check a entity-type with bundles Check a entity-type without bundles Check locale:disabled, locale:enabled and locale:enabled with another language Check revisions

Code

public function _testMultipleFieldRender() {
  $view = $this->getFieldView();

  // Test delta limit.
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3;
  $this->executeView($view);

  for ($i = 0; $i < 3; $i++) {
    $rendered_field = $view->style_plugin->get_field($i + 2, $this->fields[3]['field_name']);
    $items = array();
    $pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NONE];
    $pure_items = array_splice($pure_items, 0, 3);
    foreach ($pure_items as $j => $item) {
      $items[] = $pure_items[$j]['value'];
    }
    $this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.');
  }

  // Test that an empty field is rendered without error.
  $rendered_field = $view->style_plugin->get_field(4, $this->fields[4]['field_name']);

  $view->destroy();

  // Test delta limit + offset
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_offset'] = 1;
  $this->executeView($view);

  for ($i = 0; $i < 3; $i++) {
    $rendered_field = $view->style_plugin->get_field($i + 2, $this->fields[3]['field_name']);
    $items = array();
    $pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NONE];
    $pure_items = array_splice($pure_items, 1, 3);
    foreach ($pure_items as $j => $item) {
      $items[] = $pure_items[$j]['value'];
    }
    $this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.');
  }
  $view->destroy();

  // Test delta limit + reverse.
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_offset'] = 0;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_reversed'] = TRUE;
  $this->executeView($view);

  for ($i = 0; $i < 3; $i++) {
    $rendered_field = $view->style_plugin->get_field($i + 2, $this->fields[3]['field_name']);
    $items = array();
    $pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NONE];
    array_splice($pure_items, 0, -3);
    $pure_items = array_reverse($pure_items);
    foreach ($pure_items as $j => $item) {
      $items[] = $pure_items[$j]['value'];
    }
    $this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.');
  }
  $view->destroy();

  // Test delta first last.
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 0;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_first_last'] = TRUE;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_reversed'] = FALSE;
  $this->executeView($view);

  for ($i = 0; $i < 3; $i++) {
    $rendered_field = $view->style_plugin->get_field($i + 2, $this->fields[3]['field_name']);
    $items = array();
    $pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NONE];
    $items[] = $pure_items[0]['value'];
    $items[] = $pure_items[4]['value'];
    $this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.');
  }
  $view->destroy();

  // Test delta limit + custom seperator.
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_first_last'] = FALSE;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE;
  $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['separator'] = ':';
  $this->executeView($view);

  for ($i = 0; $i < 3; $i++) {
    $rendered_field = $view->style_plugin->get_field($i + 2, $this->fields[3]['field_name']);
    $items = array();
    $pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NONE];
    $pure_items = array_splice($pure_items, 0, 3);
    foreach ($pure_items as $j => $item) {
      $items[] = $pure_items[$j]['value'];
    }
    $this->assertEqual($rendered_field, implode(':', $items), 'Take sure that the amount of items are limited.');
  }
}