diff --git a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php index 7866146..9a1f726 --- a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php @@ -789,4 +789,85 @@ public function testFindTables() { Database::setActiveConnection('default'); } + /** + * Test corner cases of the Schema support. + */ + protected function testSchemaCornerCases() { + // We should be able to create a table without a primary key. + try { + $table_specification = array( + 'fields' => array( + 'id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + ), + 'indexes' => array( + 'id' => array('id'), + ), + ); + Database::getConnection()->schema()->createTable('test_non_primary_key', $table_specification); + + $this->pass('The creation of a table without a primary key succeeded.'); + } + catch (\Exception $e) { + $this->fail('The creation of a table without a primary key failed.'); + } + + // We should be able to create two tables sharing the same index name. + try { + $table_specification = array( + 'fields' => array( + 'name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE), + ), + 'indexes' => array( + 'name' => array('name'), + ), + ); + Database::getConnection()->schema()->createTable('test_index_1', $table_specification); + + $table_specification = array( + 'fields' => array( + 'name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE), + ), + 'indexes' => array( + 'name' => array('name'), + ), + ); + Database::getConnection()->schema()->createTable('test_index_2', $table_specification); + + $this->pass('The creation of two tables sharing the same index name succeeded.'); + } + catch (\Exception $e) { + $this->fail('The creation of two tables sharing the same index name failed.'); + } + + // We should be able to create a table and an index sharing the same name. + try { + // A table name 'test' has an index named 'field'. Does that collide with + // a table named 'test_field'? + $table_specification = array( + 'fields' => array( + 'field' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE), + ), + 'indexes' => array( + 'field' => array('field'), + ) + ); + Database::getConnection()->schema()->createTable('test', $table_specification); + + $table_specification = array( + 'fields' => array( + 'id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + ), + 'indexes' => array( + 'id' => array('id'), + ), + ); + Database::getConnection()->schema()->createTable('test_field', $table_specification); + + $this->pass('The creation of a table and an index sharing the same name succeeded.'); + } + catch (\Exception $e) { + $this->fail('The creation of a table and an index sharing the same name failed.'); + } + } + }