RowEntityTest.php 1.74 KB
Newer Older
1 2
<?php

3
namespace Drupal\Tests\views\Kernel\Plugin;
4

5
use Drupal\Core\Form\FormState;
6
use Drupal\views\Views;
7
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
8 9
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
10 11 12 13

/**
 * Tests the generic entity row plugin.
 *
14
 * @group views
15 16
 * @see \Drupal\views\Plugin\views\row\EntityRow
 */
17
class RowEntityTest extends ViewsKernelTestBase {
18 19 20 21 22 23

  /**
   * Modules to enable.
   *
   * @var array
   */
24
  public static $modules = ['taxonomy', 'text', 'filter', 'field', 'system', 'node', 'user'];
25 26 27 28 29 30

  /**
   * Views used by this test.
   *
   * @var array
   */
31
  public static $testViews = ['test_entity_row'];
32 33 34 35

  /**
   * {@inheritdoc}
   */
36
  protected function setUp($import_test_views = TRUE) {
37
    parent::setUp();
38

39
    $this->installEntitySchema('taxonomy_term');
40
    $this->installConfig(['taxonomy']);
41
    \Drupal::service('router.builder')->rebuild();
42 43 44 45 46 47
  }

  /**
   * Tests the entity row handler.
   */
  public function testEntityRow() {
48 49
    $vocab = Vocabulary::create(['name' => $this->randomMachineName(), 'vid' => strtolower($this->randomMachineName())]);
    $vocab->save();
50
    $term = Term::create(['name' => $this->randomMachineName(), 'vid' => $vocab->id()]);
51
    $term->save();
52

53
    $view = Views::getView('test_entity_row');
54 55
    $build = $view->preview();
    $this->render($build);
56

57
    $this->assertText($term->getName(), 'The rendered entity appears as row in the view.');
58 59

    // Tests the available view mode options.
60
    $form = [];
61
    $form_state = new FormState();
62
    $form_state->set('view', $view->storage);
63 64 65
    $view->rowPlugin->buildOptionsForm($form, $form_state);

    $this->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available');
66 67 68
  }

}