function InsertDefaultsTest::testDefaultInsertWithFields

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php \Drupal\KernelTests\Core\Database\InsertDefaultsTest::testDefaultInsertWithFields()
  2. 10 core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php \Drupal\KernelTests\Core\Database\InsertDefaultsTest::testDefaultInsertWithFields()
  3. 11.x 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.

File

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

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();
    $schema = drupal_get_module_schema('database_test', 'test');
    $job = $this->connection
        ->query('SELECT job FROM {test} WHERE id = :id', [
        ':id' => $id,
    ])
        ->fetchField();
    $this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.');
}

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