function TermKernelTest::testTermPreview
Same name in other branches
- 8.9.x core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testTermPreview()
- 10 core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testTermPreview()
- 11.x 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' => 'Foo',
]);
// 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.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.