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. 8.9.x 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 318

Class

SqlContentEntityStorageTest
@coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorage[[api-linebreak]] @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testSetTableMapping() : void {
  $this->entityType
    ->expects($this->any())
    ->method('isRevisionable')
    ->willReturn(FALSE);
  $this->entityType
    ->expects($this->any())
    ->method('isTranslatable')
    ->willReturn(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')
    ->willReturn($this->entityTypeId);
  $updated_entity_type->expects($this->any())
    ->method('isRevisionable')
    ->willReturn(TRUE);
  $updated_entity_type->expects($this->any())
    ->method('isTranslatable')
    ->willReturn(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.