summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-12-13 18:10:43 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-12-13 18:10:43 +0000
commit82c20e6615aff1caec4b8cae422e6d6f043f1e5e (patch)
treef6c7ff60427c85c9e22d8b43d3c03ebece9f29f9 /modules/simpletest/tests
parente5356ea62dbe368532c3d23feed7bd26696453f9 (diff)
downloadbrdo-82c20e6615aff1caec4b8cae422e6d6f043f1e5e.tar.gz
brdo-82c20e6615aff1caec4b8cae422e6d6f043f1e5e.tar.bz2
#654662 by c960657 and Crell: Allow escaping wildcard characters in LIKE queries.
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r--modules/simpletest/tests/database_test.test57
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.'));
+ }
}
/**