function BasicSyntaxTest::testLikeEscape in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Database/BasicSyntaxTest.php \Drupal\system\Tests\Database\BasicSyntaxTest::testLikeEscape()
Tests escaping of LIKE wildcards.
File
- core/
modules/ system/ src/ Tests/ Database/ BasicSyntaxTest.php, line 75 - Contains \Drupal\system\Tests\Database\BasicSyntaxTest.
Class
- BasicSyntaxTest
- Tests SQL syntax interpretation.
Namespace
Drupal\system\Tests\DatabaseCode
function testLikeEscape() {
db_insert('test')
->fields(array(
'name' => 'Ring_',
))
->execute();
// Match both "Ringo" and "Ring_".
$num_matches = db_select('test', 't')
->condition('name', 'Ring_', 'LIKE')
->countQuery()
->execute()
->fetchField();
$this
->assertIdentical($num_matches, '2', 'Found 2 records.');
// Match only "Ring_" using a LIKE expression with no wildcards.
$num_matches = db_select('test', 't')
->condition('name', db_like('Ring_'), 'LIKE')
->countQuery()
->execute()
->fetchField();
$this
->assertIdentical($num_matches, '1', 'Found 1 record.');
}