You are here

public function InsertDefaultsTest::testDefaultInsertWithFields in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php \Drupal\KernelTests\Core\Database\InsertDefaultsTest::testDefaultInsertWithFields()
  2. 9 core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php \Drupal\KernelTests\Core\Database\InsertDefaultsTest::testDefaultInsertWithFields()

Tests that we can insert fields with values and defaults in the same query.

See also

\database_test_schema()

File

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

Class

InsertDefaultsTest
Tests the Insert query builder with default values.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testDefaultInsertWithFields() {
  $query = $this->connection
    ->insert('test')
    ->fields([
    'name' => 'Bob',
  ])
    ->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.');
}