You are here

public function EntityReferenceFormatterTest::testIdFormatter in Drupal 8

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

Tests the ID formatter.

File

core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php, line 187

Class

EntityReferenceFormatterTest
Tests the formatters functionality.

Namespace

Drupal\Tests\field\Kernel\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));
}