public function TermKernelTest::testTermPreview in Drupal 9
Same name and namespace in other branches
- 8 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
->assertTrue(!empty($render_array), 'Term view builder is built.');
// Confirm we can render said view.
$rendered = \Drupal::service('renderer')
->renderPlain($render_array);
$this
->assertTrue(!empty(trim($rendered)), 'Term is able to be rendered.');
}