function RowEntityTest::testEntityRow

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/RowEntityTest.php \Drupal\Tests\views\Kernel\Plugin\RowEntityTest::testEntityRow()
  2. 10 core/modules/views/tests/src/Kernel/Plugin/RowEntityTest.php \Drupal\Tests\views\Kernel\Plugin\RowEntityTest::testEntityRow()
  3. 11.x core/modules/views/tests/src/Kernel/Plugin/RowEntityTest.php \Drupal\Tests\views\Kernel\Plugin\RowEntityTest::testEntityRow()

Tests the entity row handler.

File

core/modules/views/tests/src/Kernel/Plugin/RowEntityTest.php, line 55

Class

RowEntityTest
Tests the generic entity row plugin.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testEntityRow() {
    $vocab = Vocabulary::create([
        'name' => $this->randomMachineName(),
        'vid' => strtolower($this->randomMachineName()),
    ]);
    $vocab->save();
    $term = Term::create([
        'name' => $this->randomMachineName(),
        'vid' => $vocab->id(),
    ]);
    $term->save();
    $view = Views::getView('test_entity_row');
    $build = $view->preview();
    $this->render($build);
    $this->assertText($term->getName(), 'The rendered entity appears as row in the view.');
    // Tests the available view mode options.
    $form = [];
    $form_state = new FormState();
    $form_state->set('view', $view->storage);
    $view->rowPlugin
        ->buildOptionsForm($form, $form_state);
    $this->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.