Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / views / tests / src / Kernel / Plugin / RowEntityTest.php
1 <?php
2
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 use Drupal\taxonomy\Entity\Vocabulary;
9 use Drupal\taxonomy\Entity\Term;
10
11 /**
12  * Tests the generic entity row plugin.
13  *
14  * @group views
15  * @see \Drupal\views\Plugin\views\row\EntityRow
16  */
17 class RowEntityTest extends ViewsKernelTestBase {
18
19   /**
20    * Modules to enable.
21    *
22    * @var array
23    */
24   public static $modules = ['taxonomy', 'text', 'filter', 'field', 'system', 'node', 'user'];
25
26   /**
27    * Views used by this test.
28    *
29    * @var array
30    */
31   public static $testViews = ['test_entity_row'];
32
33   /**
34    * {@inheritdoc}
35    */
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    * Tests the entity row handler.
46    */
47   public function testEntityRow() {
48     $vocab = Vocabulary::create(['name' => $this->randomMachineName(), 'vid' => strtolower($this->randomMachineName())]);
49     $vocab->save();
50     $term = Term::create(['name' => $this->randomMachineName(), 'vid' => $vocab->id()]);
51     $term->save();
52
53     $view = Views::getView('test_entity_row');
54     $build = $view->preview();
55     $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     $view->rowPlugin->buildOptionsForm($form, $form_state);
64
65     $this->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available');
66   }
67
68 }