You are here

public function EntityViewsDataTest::testDataTable in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/tests/src/Unit/EntityViewsDataTest.php \Drupal\Tests\views\Unit\EntityViewsDataTest::testDataTable()

Tests data_table support.

File

core/modules/views/tests/src/Unit/EntityViewsDataTest.php, line 194
Contains \Drupal\Tests\views\Unit\EntityViewsDataTest.

Class

EntityViewsDataTest
@coversDefaultClass \Drupal\views\EntityViewsData @group Views

Namespace

Drupal\Tests\views\Unit

Code

public function testDataTable() {
  $entity_type = $this->baseEntityType
    ->set('data_table', 'entity_test_mul_property_data')
    ->set('id', 'entity_test_mul')
    ->set('translatable', TRUE)
    ->setKey('label', 'label');
  $this->viewsData
    ->setEntityType($entity_type);

  // Tests the join definition between the base and the data table.
  $data = $this->viewsData
    ->getViewsData();
  $base_views_data = $data['entity_test'];

  // Ensure that the base table is set to the data table.
  $this
    ->assertEquals('id', $data['entity_test_mul_property_data']['table']['base']['field']);
  $this
    ->assertEquals('Entity test', $data['entity_test_mul_property_data']['table']['base']['title']);
  $this
    ->assertFalse(isset($data['entity_test']['table']['base']));
  $this
    ->assertEquals('entity_test_mul', $data['entity_test_mul_property_data']['table']['entity type']);
  $this
    ->assertEquals(FALSE, $data['entity_test_mul_property_data']['table']['entity revision']);
  $this
    ->assertEquals('Entity test', $data['entity_test_mul_property_data']['table']['group']);
  $this
    ->assertEquals('entity_test', $data['entity_test']['table']['provider']);
  $this
    ->assertEquals([
    'field' => 'label',
    'table' => 'entity_test_mul_property_data',
  ], $data['entity_test_mul_property_data']['table']['base']['defaults']);

  // Ensure the join information is set up properly.
  $this
    ->assertCount(1, $base_views_data['table']['join']);
  $this
    ->assertEquals([
    'entity_test_mul_property_data' => [
      'left_field' => 'id',
      'field' => 'id',
      'type' => 'INNER',
    ],
  ], $base_views_data['table']['join']);
  $this
    ->assertFalse(isset($data['revision_table']));
  $this
    ->assertFalse(isset($data['revision_data_table']));
}