function SchemaTest::testSchemaAddField in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Database/SchemaTest.php \Drupal\system\Tests\Database\SchemaTest::testSchemaAddField()
Tests adding columns to an existing table.
File
- core/
modules/ system/ src/ Tests/ Database/ SchemaTest.php, line 477 - Contains \Drupal\system\Tests\Database\SchemaTest.
Class
- SchemaTest
- Tests table creation and modification via the schema API.
Namespace
Drupal\system\Tests\DatabaseCode
function testSchemaAddField() {
// Test varchar types.
foreach (array(
1,
32,
128,
256,
512,
) as $length) {
$base_field_spec = array(
'type' => 'varchar',
'length' => $length,
);
$variations = array(
array(
'not null' => FALSE,
),
array(
'not null' => FALSE,
'default' => '7',
),
array(
'not null' => FALSE,
'default' => substr('"thing"', 0, $length),
),
array(
'not null' => FALSE,
'default' => substr("\"'hing", 0, $length),
),
array(
'not null' => TRUE,
'initial' => 'd',
),
array(
'not null' => FALSE,
'default' => NULL,
),
array(
'not null' => TRUE,
'initial' => 'd',
'default' => '7',
),
);
foreach ($variations as $variation) {
$field_spec = $variation + $base_field_spec;
$this
->assertFieldAdditionRemoval($field_spec);
}
}
// Test int and float types.
foreach (array(
'int',
'float',
) as $type) {
foreach (array(
'tiny',
'small',
'medium',
'normal',
'big',
) as $size) {
$base_field_spec = array(
'type' => $type,
'size' => $size,
);
$variations = array(
array(
'not null' => FALSE,
),
array(
'not null' => FALSE,
'default' => 7,
),
array(
'not null' => TRUE,
'initial' => 1,
),
array(
'not null' => TRUE,
'initial' => 1,
'default' => 7,
),
);
foreach ($variations as $variation) {
$field_spec = $variation + $base_field_spec;
$this
->assertFieldAdditionRemoval($field_spec);
}
}
}
// Test numeric types.
foreach (array(
1,
5,
10,
40,
65,
) as $precision) {
foreach (array(
0,
2,
10,
30,
) as $scale) {
// Skip combinations where precision is smaller than scale.
if ($precision <= $scale) {
continue;
}
$base_field_spec = array(
'type' => 'numeric',
'scale' => $scale,
'precision' => $precision,
);
$variations = array(
array(
'not null' => FALSE,
),
array(
'not null' => FALSE,
'default' => 7,
),
array(
'not null' => TRUE,
'initial' => 1,
),
array(
'not null' => TRUE,
'initial' => 1,
'default' => 7,
),
);
foreach ($variations as $variation) {
$field_spec = $variation + $base_field_spec;
$this
->assertFieldAdditionRemoval($field_spec);
}
}
}
}