function SqlContentEntityStorageTest::testSetTableMapping

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testSetTableMapping()
  2. 10 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testSetTableMapping()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testSetTableMapping()

Tests that setting a new table mapping also updates the table names.

@covers ::setTableMapping

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php, line 317

Class

SqlContentEntityStorageTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Sql%21SqlContentEntityStorage.php/class/SqlContentEntityStorage/8.9.x" title="A content entity database storage implementation." class="local">\Drupal\Core\Entity\Sql\SqlContentEntityStorage</a> @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testSetTableMapping() {
    $this->entityType
        ->expects($this->any())
        ->method('isRevisionable')
        ->will($this->returnValue(FALSE));
    $this->entityType
        ->expects($this->any())
        ->method('isTranslatable')
        ->will($this->returnValue(FALSE));
    $this->entityType
        ->expects($this->any())
        ->method('getRevisionMetadataKeys')
        ->willReturn([]);
    $this->setUpEntityStorage();
    $this->assertSame('entity_test', $this->entityStorage
        ->getBaseTable());
    $this->assertNull($this->entityStorage
        ->getRevisionTable());
    $this->assertNull($this->entityStorage
        ->getDataTable());
    $this->assertNull($this->entityStorage
        ->getRevisionDataTable());
    // Change the entity type definition and instantiate a new table mapping
    // with it.
    $updated_entity_type = $this->createMock('Drupal\\Core\\Entity\\ContentEntityTypeInterface');
    $updated_entity_type->expects($this->any())
        ->method('id')
        ->will($this->returnValue($this->entityTypeId));
    $updated_entity_type->expects($this->any())
        ->method('isRevisionable')
        ->will($this->returnValue(TRUE));
    $updated_entity_type->expects($this->any())
        ->method('isTranslatable')
        ->will($this->returnValue(TRUE));
    $table_mapping = new DefaultTableMapping($updated_entity_type, []);
    $this->entityStorage
        ->setTableMapping($table_mapping);
    $this->assertSame('entity_test', $this->entityStorage
        ->getBaseTable());
    $this->assertSame('entity_test_revision', $this->entityStorage
        ->getRevisionTable());
    $this->assertSame('entity_test_field_data', $this->entityStorage
        ->getDataTable());
    $this->assertSame('entity_test_field_revision', $this->entityStorage
        ->getRevisionDataTable());
}

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