You are here

public function ConditionTest::testLikeWithBrackets in Drupal driver for SQL Server and SQL Azure 8.2

Same name and namespace in other branches
  1. 4.2.x tests/src/Kernel/ConditionTest.php \Drupal\Tests\sqlsrv\Kernel\ConditionTest::testLikeWithBrackets()
  2. 3.0.x tests/src/Kernel/ConditionTest.php \Drupal\Tests\sqlsrv\Kernel\ConditionTest::testLikeWithBrackets()
  3. 3.1.x tests/src/Kernel/ConditionTest.php \Drupal\Tests\sqlsrv\Kernel\ConditionTest::testLikeWithBrackets()
  4. 4.0.x tests/src/Kernel/ConditionTest.php \Drupal\Tests\sqlsrv\Kernel\ConditionTest::testLikeWithBrackets()
  5. 4.1.x tests/src/Kernel/ConditionTest.php \Drupal\Tests\sqlsrv\Kernel\ConditionTest::testLikeWithBrackets()

Test that brackets are escaped correctly.

File

tests/src/Kernel/ConditionTest.php, line 104

Class

ConditionTest
Test the functions of the custom Condition class.

Namespace

Drupal\Tests\sqlsrv\Kernel

Code

public function testLikeWithBrackets() {
  $this->connection
    ->insert('test_people')
    ->fields([
    'job' => '[Rutles] - Guitar',
    'name' => 'Dirk',
  ])
    ->execute();
  $name = $this->connection
    ->select('test_people', 't')
    ->fields('t', [
    'name',
  ])
    ->condition('job', '%[Rutles%', 'LIKE')
    ->execute()
    ->fetchField();
  $this
    ->assertEqual('Dirk', $name);
  $this->connection
    ->insert('test_people')
    ->fields([
    'job' => '[Rutles] - Drummer [Original]',
    'name' => 'Kevin',
  ])
    ->execute();
  $names = $this->connection
    ->select('test_people', 't')
    ->fields('t', [
    'name',
    'job',
  ])
    ->condition('job', '%[Rutles]%', 'LIKE')
    ->execute()
    ->fetchAllAssoc('job');
  $this
    ->assertCount(2, $names);
}