function EntityViewsDataTest::testRevisionTableWithRevisionDataTableAndDataTable

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

Tests revision table with data table support.

File

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

Class

EntityViewsDataTest
Tests entity views data.

Namespace

Drupal\Tests\views\Kernel\Entity

Code

public function testRevisionTableWithRevisionDataTableAndDataTable() {
    $entity_type = $this->baseEntityType
        ->set('data_table', 'entity_test_mul_property_data')
        ->set('revision_table', 'entity_test_mulrev_revision')
        ->set('revision_data_table', 'entity_test_mulrev_property_revision')
        ->set('id', 'entity_test_mulrev')
        ->set('translatable', TRUE)
        ->setKey('revision', 'revision_id');
    $this->setUpEntityType($entity_type);
    $data = $this->entityTypeManager
        ->getHandler('entity_test_mulrev', 'views_data')
        ->getViewsData();
    $this->assertEquals('Entity test revisions', $data['entity_test_mulrev_property_revision']['table']['base']['title']);
    $this->assertEquals('revision_id', $data['entity_test_mulrev_property_revision']['table']['base']['field']);
    $this->assertFalse(isset($data['entity_test_mulrev_revision']['table']['base']));
    $this->assertEquals('entity_test_mulrev', $data['entity_test_mulrev_property_revision']['table']['entity type']);
    $this->assertEquals('Entity test revision', $data['entity_test_mulrev_revision']['table']['group']);
    $this->assertEquals('entity_test', $data['entity_test']['table']['provider']);
    // Ensure the join information is set up properly.
    // Tests the join definition between the base and the revision table.
    $revision_field_data = $data['entity_test_mulrev_property_revision'];
    $this->assertCount(1, $revision_field_data['table']['join']);
    $this->assertEquals([
        'entity_test_mul_property_data' => [
            'left_field' => 'revision_id',
            'field' => 'revision_id',
            'type' => 'INNER',
        ],
    ], $revision_field_data['table']['join']);
    $revision_base_data = $data['entity_test_mulrev_revision'];
    $this->assertCount(2, $revision_base_data['table']['join']);
    $this->assertEquals([
        'entity_test_mulrev_property_revision' => [
            'left_field' => 'revision_id',
            'field' => 'revision_id',
            'type' => 'INNER',
        ],
        'entity_test_mul_property_data' => [
            'left_field' => 'revision_id',
            'field' => 'revision_id',
        ],
    ], $revision_base_data['table']['join']);
    $this->assertFalse(isset($data['data_table']));
    $this->assertEquals('entity_test_mul_property_data', $revision_field_data['id']['relationship']['base']);
    $this->assertEquals('id', $revision_field_data['id']['relationship']['base field']);
    $this->assertEquals('entity_test_mul_property_data', $revision_field_data['revision_id']['relationship']['base']);
    $this->assertEquals('revision_id', $revision_field_data['revision_id']['relationship']['base field']);
}

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