You are here

function FieldAttachOtherTest::testEntityDisplayViewMultiple in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/FieldAttachOtherTest.php \Drupal\field\Tests\FieldAttachOtherTest::testEntityDisplayViewMultiple()

Tests rendering fields with EntityDisplay::buildMultiple().

File

core/modules/field/src/Tests/FieldAttachOtherTest.php, line 138
Contains \Drupal\field\Tests\FieldAttachOtherTest.

Class

FieldAttachOtherTest
Tests other Field API functions.

Namespace

Drupal\field\Tests

Code

function testEntityDisplayViewMultiple() {

  // Use a formatter that has a prepareView() step.
  $display = entity_get_display('entity_test', 'entity_test', 'full')
    ->setComponent($this->fieldTestData->field_name, array(
    'type' => 'field_test_with_prepare_view',
  ));

  // Create two entities.
  $entity1 = entity_create('entity_test', array(
    'id' => 1,
    'type' => 'entity_test',
  ));
  $entity1->{$this->fieldTestData->field_name}
    ->setValue($this
    ->_generateTestFieldValues(1));
  $entity2 = entity_create('entity_test', array(
    'id' => 2,
    'type' => 'entity_test',
  ));
  $entity2->{$this->fieldTestData->field_name}
    ->setValue($this
    ->_generateTestFieldValues(1));

  // Run buildMultiple(), and check that the entities come out as expected.
  $display
    ->buildMultiple(array(
    $entity1,
    $entity2,
  ));
  $item1 = $entity1->{$this->fieldTestData->field_name}[0];
  $this
    ->assertEqual($item1->additional_formatter_value, $item1->value + 1, 'Entity 1 ran through the prepareView() formatter method.');
  $item2 = $entity2->{$this->fieldTestData->field_name}[0];
  $this
    ->assertEqual($item2->additional_formatter_value, $item2->value + 1, 'Entity 2 ran through the prepareView() formatter method.');
}