You are here

public function SqlContentEntityStorageTest::testGetTableMappingRevisionableWithFields in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testGetTableMappingRevisionableWithFields()

Tests getTableMapping() with a revisionable entity type with fields.

@covers ::__construct @covers ::getTableMapping

@dataProvider providerTestGetTableMappingSimple()

Parameters

string[] $entity_keys: A map of entity keys to use for the mocked entity type.

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php, line 528
Contains \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest.

Class

SqlContentEntityStorageTest
@coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorage @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetTableMappingRevisionableWithFields(array $entity_keys) {

  // This allows to re-use the data provider.
  $entity_keys = array(
    'id' => $entity_keys['id'],
    'revision' => 'test_revision',
    'bundle' => $entity_keys['bundle'],
    'uuid' => $entity_keys['uuid'],
  );

  // PHPUnit does not allow for multiple data providers.
  $test_cases = array(
    array(),
    array(
      'revision_timestamp',
    ),
    array(
      'revision_uid',
    ),
    array(
      'revision_log',
    ),
    array(
      'revision_timestamp',
      'revision_uid',
    ),
    array(
      'revision_timestamp',
      'revision_log',
    ),
    array(
      'revision_uid',
      'revision_log',
    ),
    array(
      'revision_timestamp',
      'revision_uid',
      'revision_log',
    ),
  );
  foreach ($test_cases as $revision_metadata_field_names) {
    $this
      ->setUp();
    $base_field_names = array(
      'title',
    );
    $field_names = array_merge(array_values(array_filter($entity_keys)), $base_field_names);
    $this->fieldDefinitions = $this
      ->mockFieldDefinitions($field_names);
    $revisionable_field_names = array(
      'description',
      'owner',
    );
    $field_names = array_merge($field_names, $revisionable_field_names);
    $this->fieldDefinitions += $this
      ->mockFieldDefinitions(array_merge($revisionable_field_names, $revision_metadata_field_names), array(
      'isRevisionable' => TRUE,
    ));
    $this->entityType
      ->expects($this
      ->exactly(2))
      ->method('isRevisionable')
      ->will($this
      ->returnValue(TRUE));
    $this->entityType
      ->expects($this
      ->any())
      ->method('getKey')
      ->will($this
      ->returnValueMap(array(
      array(
        'id',
        $entity_keys['id'],
      ),
      array(
        'uuid',
        $entity_keys['uuid'],
      ),
      array(
        'bundle',
        $entity_keys['bundle'],
      ),
      array(
        'revision',
        $entity_keys['revision'],
      ),
    )));
    $this
      ->setUpEntityStorage();
    $mapping = $this->entityStorage
      ->getTableMapping();
    $expected = array(
      'entity_test',
      'entity_test_revision',
    );
    $this
      ->assertEquals($expected, $mapping
      ->getTableNames());
    $this
      ->assertEquals($field_names, $mapping
      ->getFieldNames('entity_test'));
    $expected = array_merge(array(
      $entity_keys['id'],
      $entity_keys['revision'],
    ), $revisionable_field_names, $revision_metadata_field_names);
    $this
      ->assertEquals($expected, $mapping
      ->getFieldNames('entity_test_revision'));
    $this
      ->assertEquals(array(), $mapping
      ->getExtraColumns('entity_test'));
    $this
      ->assertEquals(array(), $mapping
      ->getExtraColumns('entity_test_revision'));
  }
}