function TermKernelTest::testTermPreview

Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testTermPreview()
  2. 8.9.x core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testTermPreview()
  3. 10 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 156

Class

TermKernelTest
Kernel tests for taxonomy term functions.

Namespace

Drupal\Tests\taxonomy\Kernel

Code

public function testTermPreview() : void {
    $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 = (string) \Drupal::service('renderer')->renderInIsolation($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.