3 namespace Drupal\Tests\views\Kernel\Plugin;
5 use Drupal\Core\Form\FormState;
6 use Drupal\views\Views;
7 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
8 use Drupal\taxonomy\Entity\Vocabulary;
9 use Drupal\taxonomy\Entity\Term;
12 * Tests the generic entity row plugin.
15 * @see \Drupal\views\Plugin\views\row\EntityRow
17 class RowEntityTest extends ViewsKernelTestBase {
24 public static $modules = ['taxonomy', 'text', 'filter', 'field', 'system', 'node', 'user'];
27 * Views used by this test.
31 public static $testViews = ['test_entity_row'];
36 protected function setUp($import_test_views = TRUE) {
39 $this->installEntitySchema('taxonomy_term');
40 $this->installConfig(['taxonomy']);
41 \Drupal::service('router.builder')->rebuild();
45 * Tests the entity row handler.
47 public function testEntityRow() {
48 $vocab = Vocabulary::create(['name' => $this->randomMachineName(), 'vid' => strtolower($this->randomMachineName())]);
50 $term = Term::create(['name' => $this->randomMachineName(), 'vid' => $vocab->id() ]);
53 $view = Views::getView('test_entity_row');
54 $build = $view->preview();
55 $this->render($build);
57 $this->assertText($term->getName(), 'The rendered entity appears as row in the view.');
59 // Tests the available view mode options.
61 $form_state = new FormState();
62 $form_state->set('view', $view->storage);
63 $view->rowPlugin->buildOptionsForm($form, $form_state);
65 $this->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available');