public function SqlContentEntityStorageTest::testOnEntityTypeCreate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testOnEntityTypeCreate()
Tests ContentEntityDatabaseStorage::onEntityTypeCreate().
@covers ::__construct @covers ::onEntityTypeCreate @covers ::getTableMapping
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ Sql/ SqlContentEntityStorageTest.php, line 285 - Contains \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest.
Class
- SqlContentEntityStorageTest
- @coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorage @group Entity
Namespace
Drupal\Tests\Core\Entity\SqlCode
public function testOnEntityTypeCreate() {
$columns = array(
'value' => array(
'type' => 'int',
),
);
$this->fieldDefinitions = $this
->mockFieldDefinitions(array(
'id',
));
$this->fieldDefinitions['id']
->expects($this
->any())
->method('getColumns')
->will($this
->returnValue($columns));
$this->fieldDefinitions['id']
->expects($this
->once())
->method('getSchema')
->will($this
->returnValue(array(
'columns' => $columns,
)));
$this->entityType
->expects($this
->once())
->method('getKeys')
->will($this
->returnValue(array(
'id' => 'id',
)));
$this->entityType
->expects($this
->any())
->method('getKey')
->will($this
->returnValueMap(array(
// EntityStorageBase::__construct()
array(
'id',
'id',
),
// ContentEntityStorageBase::__construct()
array(
'uuid',
NULL,
),
array(
'bundle',
NULL,
),
// SqlContentEntityStorageSchema::initializeBaseTable()
array(
'id' => 'id',
),
// SqlContentEntityStorageSchema::processBaseTable()
array(
'id' => 'id',
),
)));
$this
->setUpEntityStorage();
$expected = array(
'description' => 'The base table for entity_test entities.',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
),
),
'primary key' => array(
'id',
),
'unique keys' => array(),
'indexes' => array(),
'foreign keys' => array(),
);
$schema_handler = $this
->getMockBuilder('Drupal\\Core\\Database\\Schema')
->disableOriginalConstructor()
->getMock();
$schema_handler
->expects($this
->any())
->method('createTable')
->with($this
->equalTo('entity_test'), $this
->equalTo($expected));
$this->connection
->expects($this
->once())
->method('schema')
->will($this
->returnValue($schema_handler));
$storage = $this
->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage')
->setConstructorArgs(array(
$this->entityType,
$this->connection,
$this->entityManager,
$this->cache,
$this->languageManager,
))
->setMethods(array(
'getStorageSchema',
))
->getMock();
$key_value = $this
->getMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreInterface');
$schema_handler = $this
->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorageSchema')
->setConstructorArgs(array(
$this->entityManager,
$this->entityType,
$storage,
$this->connection,
))
->setMethods(array(
'installedStorageSchema',
'createSharedTableSchema',
))
->getMock();
$schema_handler
->expects($this
->any())
->method('installedStorageSchema')
->will($this
->returnValue($key_value));
$storage
->expects($this
->any())
->method('getStorageSchema')
->will($this
->returnValue($schema_handler));
$storage
->onEntityTypeCreate($this->entityType);
}