You are here

public function SqlContentEntityStorageSchemaTest::testGetSchemaTranslatable in Zircon Profile 8

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

Tests the schema for non-revisionable, translatable entities.

@covers ::__construct @covers ::getEntitySchemaTables @covers ::initializeDataTable @covers ::addTableDefaults @covers ::getEntityIndexName @covers ::processDataTable

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php, line 491
Contains \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest.

Class

SqlContentEntityStorageSchemaTest
@coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetSchemaTranslatable() {
  $this->entityType = new ContentEntityType(array(
    'id' => 'entity_test',
    'entity_keys' => array(
      'id' => 'id',
      'langcode' => 'langcode',
    ),
  ));
  $this->storage
    ->expects($this
    ->any())
    ->method('getDataTable')
    ->will($this
    ->returnValue('entity_test_field_data'));
  $this
    ->setUpStorageDefinition('langcode', array(
    'columns' => array(
      'value' => array(
        'type' => 'varchar',
      ),
    ),
  ));
  $this
    ->setUpStorageDefinition('default_langcode', array(
    'columns' => array(
      'value' => array(
        'type' => 'int',
        'size' => 'tiny',
      ),
    ),
  ));
  $expected = array(
    'entity_test' => array(
      'description' => 'The base table for entity_test entities.',
      'fields' => array(
        'id' => array(
          'type' => 'serial',
          'not null' => TRUE,
        ),
        'langcode' => array(
          'type' => 'varchar',
          'not null' => TRUE,
        ),
      ),
      'primary key' => array(
        'id',
      ),
      'unique keys' => array(),
      'indexes' => array(),
      'foreign keys' => array(),
    ),
    'entity_test_field_data' => array(
      'description' => 'The data table for entity_test entities.',
      'fields' => array(
        'id' => array(
          'type' => 'int',
          'not null' => TRUE,
        ),
        'langcode' => array(
          'type' => 'varchar',
          'not null' => TRUE,
        ),
        'default_langcode' => array(
          'type' => 'int',
          'size' => 'tiny',
          'not null' => true,
        ),
      ),
      'primary key' => array(
        'id',
        'langcode',
      ),
      'unique keys' => array(),
      'indexes' => array(
        'entity_test__id__default_langcode__langcode' => array(
          0 => 'id',
          1 => 'default_langcode',
          2 => 'langcode',
        ),
      ),
      'foreign keys' => array(
        'entity_test' => array(
          'table' => 'entity_test',
          'columns' => array(
            'id' => 'id',
          ),
        ),
      ),
    ),
  );
  $this
    ->setUpStorageSchema($expected);
  $table_mapping = new DefaultTableMapping($this->entityType, $this->storageDefinitions);
  $non_data_fields = array_keys($this->storageDefinitions);
  unset($non_data_fields[array_search('default_langcode', $non_data_fields)]);
  $table_mapping
    ->setFieldNames('entity_test', $non_data_fields);
  $table_mapping
    ->setFieldNames('entity_test_field_data', array_keys($this->storageDefinitions));
  $this->storage
    ->expects($this
    ->any())
    ->method('getTableMapping')
    ->will($this
    ->returnValue($table_mapping));
  $this
    ->assertNull($this->storageSchema
    ->onEntityTypeCreate($this->entityType));
}