public function EntityReferenceFormatterTest::testIdFormatter in Drupal 10
Same name and namespace in other branches
- 8 core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php \Drupal\Tests\field\Kernel\EntityReference\EntityReferenceFormatterTest::testIdFormatter()
- 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 184
Class
- EntityReferenceFormatterTest
- Tests the formatters functionality.
Namespace
Drupal\Tests\field\Kernel\EntityReferenceCode
public function testIdFormatter() {
$formatter = 'entity_reference_entity_id';
$build = $this
->buildRenderArray([
$this->referencedEntity,
$this->unsavedReferencedEntity,
], $formatter);
$this
->assertEquals($this->referencedEntity
->id(), $build[0]['#plain_text'], sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this
->assertEquals($this->referencedEntity
->getCacheTags(), $build[0]['#cache']['tags'], 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));
}