diff options
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r-- | modules/simpletest/tests/database_test.test | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index f74ed1d9a..3862f16c0 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -2643,6 +2643,63 @@ class DatabaseAnsiSyntaxTestCase extends DatabaseTestCase { )); $this->assertIdentical($result->fetchField(), 'The age of John is 25.', t('Field ANSI Concat works.')); } + + /** + * Test escaping of LIKE wildcards. + */ + 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', t('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', t('Found 1 record.')); + } + + /** + * Test LIKE query containing a backslash. + */ + function testLikeBackslash() { + db_insert('test') + ->fields(array('name')) + ->values(array( + 'name' => 'abcde\f', + )) + ->values(array( + 'name' => 'abc%\_', + )) + ->execute(); + + // Match both rows using a LIKE expression with two wildcards and a verbatim + // backslash. + $num_matches = db_select('test', 't') + ->condition('name', 'abc%\\\\_', 'LIKE') + ->countQuery() + ->execute() + ->fetchField(); + $this->assertIdentical($num_matches, '2', t('Found 2 records.')); + // Match only the former using a LIKE expression with no wildcards. + $num_matches = db_select('test', 't') + ->condition('name', db_like('abc%\_'), 'LIKE') + ->countQuery() + ->execute() + ->fetchField(); + $this->assertIdentical($num_matches, '1', t('Found 1 record.')); + } } /** |