You are here

public function EntityReferenceFormatterTest::testIdFormatter in Zircon Profile 8

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

Tests the ID formatter.

File

core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php, line 165
Contains \Drupal\field\Tests\EntityReference\EntityReferenceFormatterTest.

Class

EntityReferenceFormatterTest
Tests the formatters functionality.

Namespace

Drupal\field\Tests\EntityReference

Code

public function testIdFormatter() {
  $formatter = 'entity_reference_entity_id';
  $build = $this
    ->buildRenderArray([
    $this->referencedEntity,
    $this->unsavedReferencedEntity,
  ], $formatter);
  $this
    ->assertEqual($build[0]['#plain_text'], $this->referencedEntity
    ->id(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
  $this
    ->assertEqual($build[0]['#cache']['tags'], $this->referencedEntity
    ->getCacheTags(), sprintf('The %s formatter has the expected cache tags.', $formatter));
  $this
    ->assertTrue(!isset($build[1]), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
}