diff --git a/core/modules/views/src/Tests/Plugin/EntityRowTest.php b/core/modules/views/src/Tests/Plugin/EntityRowTest.php new file mode 100644 index 0000000..46a6366 --- /dev/null +++ b/core/modules/views/src/Tests/Plugin/EntityRowTest.php @@ -0,0 +1,101 @@ +installEntitySchema('entity_test'); + $this->installEntitySchema('user'); + } + + /** + * Tests the entity row handler. + */ + public function testEntityRow() { + $user = User::create([ + 'name' => 'test user', + ]); + $user->save(); + + $entity_test = EntityTest::create([ + 'user_id' => $user->id(), + 'name' => 'test entity test', + ]); + $entity_test->save(); + + // Ensure entities have different ids. + if ($entity_test->id() == $user->id()) { + $entity_test->delete(); + $entity_test = EntityTest::create([ + 'user_id' => $user->id(), + 'name' => 'test entity test', + ]); + $entity_test->save(); + } + + $view = Views::getView('test_entity_row'); + $build = $view->preview(); + $this->render($build); + + $this->assertText('test entity test'); + $this->assertNoText('Member for'); + + // Change the view to use a relationship to render the row. + $view = Views::getView('test_entity_row'); + $display = &$view->storage->getDisplay('default'); + $display['display_options']['row']['type'] = 'entity:user'; + $display['display_options']['row']['options']['relationship'] = 'user_id'; + $view->setDisplay('default'); + $build = $view->preview(); + $this->render($build); + + $this->assertNoText('test entity test'); + $this->assertText('Member for'); + + // Tests the available view mode options. + $form = array(); + $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'); + } + +} diff --git a/core/modules/views/src/Tests/Plugin/RowEntityTest.php b/core/modules/views/src/Tests/Plugin/RowEntityTest.php deleted file mode 100644 index 7de0305..0000000 --- a/core/modules/views/src/Tests/Plugin/RowEntityTest.php +++ /dev/null @@ -1,71 +0,0 @@ -installEntitySchema('taxonomy_term'); - $this->installConfig(array('taxonomy')); - \Drupal::service('router.builder')->rebuild(); - } - - /** - * Tests the entity row handler. - */ - public function testEntityRow() { - $vocab = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'vid' => strtolower($this->randomMachineName()))); - $vocab->save(); - $term = entity_create('taxonomy_term', array('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 = array(); - $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'); - } - -} diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_row.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_row.yml index ad9f748..c786e20 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_row.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_row.yml @@ -6,8 +6,8 @@ label: '' module: views description: '' tag: '' -base_table: taxonomy_term_field_data -base_field: nid +base_table: entity_test +base_field: id core: '8' display: default: @@ -21,10 +21,17 @@ display: offset: 0 type: none row: - type: 'entity:taxonomy_term' + type: 'entity:entity_test' options: relationship: none view_mode: full + relationships: + user_id: + table: entity_test + field: user_id + id: user_id + relationship: none + plugin_id: standard display_plugin: default display_title: Master id: default