function EntityViewsDataTest::testDataTable

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Entity/EntityViewsDataTest.php \Drupal\Tests\views\Kernel\Entity\EntityViewsDataTest::testDataTable()
  2. 8.9.x core/modules/views/tests/src/Unit/EntityViewsDataTest.php \Drupal\Tests\views\Unit\EntityViewsDataTest::testDataTable()
  3. 10 core/modules/views/tests/src/Kernel/Entity/EntityViewsDataTest.php \Drupal\Tests\views\Kernel\Entity\EntityViewsDataTest::testDataTable()

Tests data_table support.

File

core/modules/views/tests/src/Kernel/Entity/EntityViewsDataTest.php, line 194

Class

EntityViewsDataTest
Tests entity views data.

Namespace

Drupal\Tests\views\Kernel\Entity

Code

public function testDataTable() : void {
    $entity_type = $this->baseEntityType
        ->set('data_table', 'entity_test_mul_property_data')
        ->set('id', 'entity_test_mul')
        ->set('translatable', TRUE)
        ->setKey('label', 'label');
    $this->setUpEntityType($entity_type);
    // Tests the join definition between the base and the data table.
    $data = $this->entityTypeManager
        ->getHandler('entity_test_mul', 'views_data')
        ->getViewsData();
    // @todo Change the base table in the entity type definition to match the
    //   changed entity ID.
    $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']));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.