function SelectTest::testRegularExpressionCondition

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

Tests that filter by 'REGEXP' and 'NOT REGEXP' works as expected.

@dataProvider providerRegularExpressionCondition

File

core/tests/Drupal/KernelTests/Core/Database/SelectTest.php, line 526

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testRegularExpressionCondition($expected, $column, $pattern, $operator) : void {
    $database = $this->container
        ->get('database');
    $database->insert('test')
        ->fields([
        'name' => 'Pete',
        'age' => 26,
        'job' => '#Drummer',
    ])
        ->execute();
    $query = $database->select('test', 't');
    $query->addField('t', 'name');
    $query->condition("t.{$column}", $pattern, $operator);
    $result = $query->execute()
        ->fetchCol();
    sort($result);
    $this->assertEquals($expected, $result);
}

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