function DriverSpecificSchemaTestBase::testSchemaChangeFieldDefaultInitial

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Database/DriverSpecificSchemaTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificSchemaTestBase::testSchemaChangeFieldDefaultInitial()

Tests changing columns between types with default and initial values.

File

core/tests/Drupal/KernelTests/Core/Database/DriverSpecificSchemaTestBase.php, line 791

Class

DriverSpecificSchemaTestBase
Tests table creation and modification via the schema API.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testSchemaChangeFieldDefaultInitial() : void {
    $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",
            ]));
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.