function DriverSpecificSchemaTestBase::testSchemaMethodsWithView
Tests table schema methods when a view exists.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ DriverSpecificSchemaTestBase.php, line 1160
Class
- DriverSpecificSchemaTestBase
- Tests table creation and modification via the schema API.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testSchemaMethodsWithView() : void {
// We will be testing with three tables.
$test_schema = Database::getConnection()->schema();
// Create the tables.
$table_specification = [
'description' => 'Test table.',
'fields' => [
'id' => [
'type' => 'int',
'default' => NULL,
'description' => 'Test field.',
],
],
];
$test_schema->createTable('test_table', $table_specification);
// Create a view to ensure it is not found.
Database::getConnection()->query('create view {test_view} as select * from {test_table}');
// Test \Drupal\Core\Database\Schema::tableExists().
$this->assertTrue($this->schema
->tableExists('test_table'), 'Table exists');
$this->assertFalse($this->schema
->tableExists('test_view'), 'View is not checked by tableExists() method');
// Test \Drupal\Core\Database\Schema::findTables().
$tables = array_values($test_schema->findTables('t%'));
$this->assertEquals([
'test_table',
], $tables, 'All tables were found.');
// Test \Drupal\Core\Database\Schema::getComment().
$this->checkSchemaComment('Test table.', 'test_table');
$this->checkSchemaComment('Test field.', 'test_table', 'id');
$this->checkSchemaComment(FALSE, 'test_view');
$this->checkSchemaComment(FALSE, 'test_view', 'id');
$this->checkSchemaComment(FALSE, 'does_not_exist');
$this->checkSchemaComment(FALSE, 'does_not_exist', 'id');
// Clean up the view.
Database::getConnection()->query('drop view {test_view}');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.