summaryrefslogtreecommitdiff
path: root/core/tests
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-03-12 03:20:13 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-03-12 03:20:13 +0000
commitd1f181da08cbb747a7353bf84fbaa5d1ab82bd02 (patch)
tree5b2f3c3e6675c59db77af4699b5e4585d071af02 /core/tests
parente58b955d4acc44bc2b49fffbffda42ad8b66069d (diff)
Attempt to reduce the chance of replacing text in sql statements that
is not a table name (but contained in braces) with the database prefix by building and maintaining a cache of database tables and prefixes.
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/Database_Test.php19
1 files changed, 17 insertions, 2 deletions
diff --git a/core/tests/Database_Test.php b/core/tests/Database_Test.php
index 1e0764cc..3d3c965b 100644
--- a/core/tests/Database_Test.php
+++ b/core/tests/Database_Test.php
@@ -86,14 +86,28 @@ class Database_Test extends Unit_Test_Case {
function prefix_replacement_test() {
$db = Database_For_Test::instance();
- $sql = "UPDATE {access_caches} SET `edit_1` = 1 " .
+ $converted = $db->add_table_prefixes("CREATE TABLE IF NOT EXISTS {test_tables} (
+ `id` int(9) NOT NULL auto_increment,
+ `name` varchar(32) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY(`name`))
+ ENGINE=InnoDB DEFAULT CHARSET=utf8");
+ $expected = "CREATE TABLE IF NOT EXISTS g3test_test_tables (
+ `id` int(9) NOT NULL auto_increment,
+ `name` varchar(32) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY(`name`))
+ ENGINE=InnoDB DEFAULT CHARSET=utf8";
+ $this->assert_same($expected, $converted);
+
+ $sql = "UPDATE {test_tables} SET `name` = '{test string}' " .
"WHERE `item_id` IN " .
" (SELECT `id` FROM {items} " .
" WHERE `left` >= 1 " .
" AND `right` <= 6)";
$sql = $db->add_table_prefixes($sql);
- $expected = "UPDATE g3test_access_caches SET `edit_1` = 1 " .
+ $expected = "UPDATE g3test_test_tables SET `name` = '{test string}' " .
"WHERE `item_id` IN " .
" (SELECT `id` FROM g3test_items " .
" WHERE `left` >= 1 " .
@@ -113,6 +127,7 @@ class Database_Test extends Unit_Test_Case {
class Database_For_Test extends Database {
static function instance() {
$db = new Database_For_Test();
+ $db->_table_names["{items}"] = "g3test_items";
$db->config["table_prefix"] = "g3test_";
return $db;
}