function InsertDefaultsTest::testDefaultInsert

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php \Drupal\KernelTests\Core\Database\InsertDefaultsTest::testDefaultInsert()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php \Drupal\KernelTests\Core\Database\InsertDefaultsTest::testDefaultInsert()
  3. 11.x core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php \Drupal\KernelTests\Core\Database\InsertDefaultsTest::testDefaultInsert()

Tests that we can run a query that uses default values for everything.

See also

\database_test_schema()

File

core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php, line 21

Class

InsertDefaultsTest
Tests the Insert query builder with default values.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testDefaultInsert() : void {
    $query = $this->connection
        ->insert('test')
        ->useDefaults([
        'job',
    ]);
    $id = $query->execute();
    $job = $this->connection
        ->query('SELECT [job] FROM {test} WHERE [id] = :id', [
        ':id' => $id,
    ])
        ->fetchField();
    $this->assertSame('Undefined', $job, 'Default field value is set.');
}

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