public function DynamicEntityReferenceFormatterTest::testIdFormatter in Dynamic Entity Reference 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/DynamicEntityReferenceFormatterTest.php \Drupal\Tests\dynamic_entity_reference\Kernel\DynamicEntityReferenceFormatterTest::testIdFormatter()
Tests the ID formatter.
File
- tests/
src/ Kernel/ DynamicEntityReferenceFormatterTest.php, line 199
Class
- DynamicEntityReferenceFormatterTest
- Tests the formatters functionality.
Namespace
Drupal\Tests\dynamic_entity_reference\KernelCode
public function testIdFormatter() {
$formatter = 'dynamic_entity_reference_entity_id';
$build = $this
->buildRenderArray([
$this->referencedEntity,
$this->unsavedReferencedEntity,
], $formatter);
$this
->assertEquals($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
->assertEquals($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));
}