public function SchemaTest::testSchemaChangeFieldDefaultInitial in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php \Drupal\KernelTests\Core\Database\SchemaTest::testSchemaChangeFieldDefaultInitial()
Tests changing columns between types with default and initial values.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ SchemaTest.php, line 965
Class
- SchemaTest
- Tests table creation and modification via the schema API.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testSchemaChangeFieldDefaultInitial() {
$field_specs = [
[
'type' => 'int',
'size' => 'normal',
'not null' => FALSE,
],
[
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
'initial' => 1,
'default' => 17,
],
[
'type' => 'float',
'size' => 'normal',
'not null' => FALSE,
],
[
'type' => 'float',
'size' => 'normal',
'not null' => TRUE,
'initial' => 1,
'default' => 7.3,
],
[
'type' => 'numeric',
'scale' => 2,
'precision' => 10,
'not null' => FALSE,
],
[
'type' => 'numeric',
'scale' => 2,
'precision' => 10,
'not null' => TRUE,
'initial' => 1,
'default' => 7,
],
];
foreach ($field_specs as $i => $old_spec) {
foreach ($field_specs as $j => $new_spec) {
if ($i === $j) {
// Do not change a field into itself.
continue;
}
$this
->assertFieldChange($old_spec, $new_spec);
}
}
$field_specs = [
[
'type' => 'varchar_ascii',
'length' => '255',
],
[
'type' => 'varchar',
'length' => '255',
],
[
'type' => 'text',
],
[
'type' => 'blob',
'size' => 'big',
],
];
foreach ($field_specs as $i => $old_spec) {
foreach ($field_specs as $j => $new_spec) {
if ($i === $j) {
// Do not change a field into itself.
continue;
}
// Note if the serialized data contained an object this would fail on
// Postgres.
// @see https://www.drupal.org/node/1031122
$this
->assertFieldChange($old_spec, $new_spec, serialize([
'string' => "This \n has \\\\ some backslash \"*string action.\\n",
]));
}
}
}