function UpdateComplexTest::testOrConditionUpdate

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

Tests updates with OR conditionals.

File

core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php, line 17

Class

UpdateComplexTest
Tests the Update query builder, complex queries.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testOrConditionUpdate() : void {
    $update = $this->connection
        ->update('test')
        ->fields([
        'job' => 'Musician',
    ])
        ->condition($this->connection
        ->condition('OR')
        ->condition('name', 'John')
        ->condition('name', 'Paul'));
    $num_updated = $update->execute();
    $this->assertSame(2, $num_updated, 'Updated 2 records.');
    $num_matches = $this->connection
        ->query('SELECT COUNT(*) FROM {test} WHERE [job] = :job', [
        ':job' => 'Musician',
    ])
        ->fetchField();
    $this->assertSame('2', $num_matches, 'Updated fields successfully.');
}

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