public function TermKernelTest::testTermPreview in Drupal 10
Same name and namespace in other branches
- 8 core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testTermPreview()
- 9 core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testTermPreview()
Tests that a Term is renderable when unsaved (preview).
File
- core/
modules/ taxonomy/ tests/ src/ Kernel/ TermKernelTest.php, line 151
Class
- TermKernelTest
- Kernel tests for taxonomy term functions.
Namespace
Drupal\Tests\taxonomy\KernelCode
public function testTermPreview() {
$entity_manager = \Drupal::entityTypeManager();
$vocabulary = $this
->createVocabulary();
// Create a unsaved term.
$term = $entity_manager
->getStorage('taxonomy_term')
->create([
'vid' => $vocabulary
->id(),
'name' => 'Inator',
]);
// Confirm we can get the view of unsaved term.
$render_array = $entity_manager
->getViewBuilder('taxonomy_term')
->view($term);
$this
->assertNotEmpty($render_array, 'Term view builder is built.');
// Confirm we can render said view.
$rendered = \Drupal::service('renderer')
->renderPlain($render_array);
$this
->assertNotEmpty(trim($rendered), 'Term is able to be rendered.');
}