diff --git a/core/modules/system/src/Tests/Database/SchemaTest.php b/core/modules/system/src/Tests/Database/SchemaTest.php index fb5a1c2..1952cc9 100644 --- a/core/modules/system/src/Tests/Database/SchemaTest.php +++ b/core/modules/system/src/Tests/Database/SchemaTest.php @@ -640,7 +640,7 @@ protected function assertFieldCharacteristics($table_name, $field_name, $field_s } /** - * Tests changing columns between numeric types. + * Tests changing columns between types. */ function testSchemaChangeField() { $field_specs = array( @@ -661,6 +661,22 @@ function testSchemaChangeField() { $this->assertFieldChange($old_spec, $new_spec); } } + + $field_specs = array( + array('type' => 'varchar_ascii', 'length' => '255'), + array('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; + } + $this->assertFieldChange($old_spec, $new_spec, "This \n has \\\\ some backslash acction.\\n"); + } + } + } /** @@ -671,7 +687,7 @@ function testSchemaChangeField() { * @param $new_spec * The ending field specification. */ - protected function assertFieldChange($old_spec, $new_spec) { + protected function assertFieldChange($old_spec, $new_spec, $test_data = NULL) { $table_name = 'test_table_' . ($this->counter++); $table_spec = array( 'fields' => array( @@ -689,9 +705,24 @@ protected function assertFieldChange($old_spec, $new_spec) { // Remove inserted rows. db_truncate($table_name)->execute(); + if ($test_data) { + $id = db_insert($table_name) + ->fields(['test_field'], [$test_data]) + ->execute(); + } + // Change the field. db_change_field($table_name, 'test_field', 'test_field', $new_spec); + if ($test_data) { + $field_value = db_select($table_name) + ->fields($table_name, ['test_field']) + ->condition('serial_column', $id) + ->execute() + ->fetchField(); + $this->assertIdentical($field_value, $test_data); + } + // Check the field was changed. $this->assertFieldCharacteristics($table_name, 'test_field', $new_spec);