From 01bc818d465ab168288e260745a045ff2794648d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 18:44:40 -0500 Subject: [PATCH 1/6] [ticket/10875] Fix SQL Caching The sql_save function cannot take arguments by reference since it is called by call_user_func_array() Replace use of isset($cache->sql_rowset[$query_id]) with $cache->sql_exists Replace $cache->cache_dir with $cache->get_driver()->cache_dir PHPBB3-10875 --- phpBB/includes/cache/driver/file.php | 2 +- phpBB/includes/cache/driver/interface.php | 2 +- phpBB/includes/cache/driver/memory.php | 2 +- phpBB/includes/cache/driver/null.php | 2 +- phpBB/includes/db/dbal.php | 4 ++-- phpBB/includes/db/firebird.php | 4 ++-- phpBB/includes/db/mssql.php | 6 +++--- phpBB/includes/db/mssql_odbc.php | 4 ++-- phpBB/includes/db/mssqlnative.php | 4 ++-- phpBB/includes/db/mysql.php | 6 +++--- phpBB/includes/db/mysqli.php | 6 +++--- phpBB/includes/db/oracle.php | 6 +++--- phpBB/includes/db/postgres.php | 6 +++--- phpBB/includes/db/sqlite.php | 6 +++--- phpBB/install/install_update.php | 2 +- 15 files changed, 31 insertions(+), 31 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index 0d3b06f621..da942b921c 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -364,7 +364,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base /** * Save sql query */ - function sql_save($query, &$query_result, $ttl) + function sql_save($query, $query_result, $ttl) { global $db; diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php index 313a2d4b31..847ba97262 100644 --- a/phpBB/includes/cache/driver/interface.php +++ b/phpBB/includes/cache/driver/interface.php @@ -75,7 +75,7 @@ interface phpbb_cache_driver_interface /** * Save sql query */ - public function sql_save($query, &$query_result, $ttl); + public function sql_save($query, $query_result, $ttl); /** * Ceck if a given sql query exist in cache diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index e25c9229a1..aabad2bb6c 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -280,7 +280,7 @@ class phpbb_cache_driver_memory extends phpbb_cache_driver_base /** * Save sql query */ - function sql_save($query, &$query_result, $ttl) + function sql_save($query, $query_result, $ttl) { global $db; diff --git a/phpBB/includes/cache/driver/null.php b/phpBB/includes/cache/driver/null.php index c143803d0e..df2c6c026f 100644 --- a/phpBB/includes/cache/driver/null.php +++ b/phpBB/includes/cache/driver/null.php @@ -107,7 +107,7 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base /** * Save sql query */ - function sql_save($query, &$query_result, $ttl) + function sql_save($query, $query_result, $ttl) { } diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 159703d3be..1de236d3de 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -206,7 +206,7 @@ class dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -256,7 +256,7 @@ class dbal $this->sql_rowseek($rownum, $query_id); } - if (!is_object($query_id) && isset($cache->sql_rowset[$query_id])) + if (!is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_fetchfield($query_id, $field); } diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 06c76fa94a..99deb5603e 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -332,7 +332,7 @@ class dbal_firebird extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -398,7 +398,7 @@ class dbal_firebird extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index e40510835a..d92fe27b99 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -234,7 +234,7 @@ class dbal_mssql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -271,7 +271,7 @@ class dbal_mssql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -310,7 +310,7 @@ class dbal_mssql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 3c9a9599ec..6292792a55 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -254,7 +254,7 @@ class dbal_mssql_odbc extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -295,7 +295,7 @@ class dbal_mssql_odbc extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index d35337d05b..0d8786171a 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -418,7 +418,7 @@ class dbal_mssqlnative extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -478,7 +478,7 @@ class dbal_mssqlnative extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index dbab1ec0b8..fd567af076 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -249,7 +249,7 @@ class dbal_mysql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -270,7 +270,7 @@ class dbal_mysql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -298,7 +298,7 @@ class dbal_mysql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index fc98de31fb..26cade2ff0 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -251,7 +251,7 @@ class dbal_mysqli extends dbal $query_id = $this->query_result; } - if (!is_object($query_id) && isset($cache->sql_rowset[$query_id])) + if (!is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -278,7 +278,7 @@ class dbal_mysqli extends dbal $query_id = $this->query_result; } - if (!is_object($query_id) && isset($cache->sql_rowset[$query_id])) + if (!is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -306,7 +306,7 @@ class dbal_mysqli extends dbal $query_id = $this->query_result; } - if (!is_object($query_id) && isset($cache->sql_rowset[$query_id])) + if (!is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 4954f4d398..e9ff2f4434 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -473,7 +473,7 @@ class dbal_oracle extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -525,7 +525,7 @@ class dbal_oracle extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -594,7 +594,7 @@ class dbal_oracle extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 41838d2613..c35199e917 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -285,7 +285,7 @@ class dbal_postgres extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -306,7 +306,7 @@ class dbal_postgres extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -355,7 +355,7 @@ class dbal_postgres extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index d930567773..814b593f05 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -193,7 +193,7 @@ class dbal_sqlite extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -214,7 +214,7 @@ class dbal_sqlite extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -242,7 +242,7 @@ class dbal_sqlite extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index c2feaa086a..88b00f1cf1 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -349,7 +349,7 @@ class install_update extends module // We are directly within an update. To make sure our update list is correct we check its status. $update_list = ($request->variable('check_again', false, false, phpbb_request_interface::POST)) ? false : $cache->get('_update_list'); - $modified = ($update_list !== false) ? @filemtime($cache->cache_dir . 'data_update_list.' . $phpEx) : 0; + $modified = ($update_list !== false) ? @filemtime($cache->get_driver()->cache_dir . 'data_update_list.' . $phpEx) : 0; // Make sure the list is up-to-date if ($update_list !== false) From dcefa16318f6dc1058595a7ba221b75ed6a2504b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 16:26:55 -0500 Subject: [PATCH 2/6] [ticket/10875] Return $query_id from sql_save Have to return the $query_id from sql_save so that the results can be pulled Updated cache test to do some basic sql cache testing. PHPBB3-10875 --- phpBB/includes/cache/driver/file.php | 2 ++ phpBB/includes/cache/driver/memory.php | 2 ++ phpBB/includes/db/firebird.php | 2 +- phpBB/includes/db/mssql.php | 2 +- phpBB/includes/db/mssql_odbc.php | 2 +- phpBB/includes/db/mssqlnative.php | 2 +- phpBB/includes/db/mysql.php | 2 +- phpBB/includes/db/mysqli.php | 2 +- phpBB/includes/db/oracle.php | 2 +- phpBB/includes/db/postgres.php | 2 +- phpBB/includes/db/sqlite.php | 2 +- tests/cache/cache_test.php | 32 +++++++++++++++++++++++++- tests/mock/cache.php | 2 +- 13 files changed, 45 insertions(+), 11 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index da942b921c..f64a9e3ea8 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -385,6 +385,8 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base { $query_result = $query_id; } + + return $query_id; } /** diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index aabad2bb6c..92971c6cb2 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -335,6 +335,8 @@ class phpbb_cache_driver_memory extends phpbb_cache_driver_base $this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl); $query_result = $query_id; + + return $query_id; } /** diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 99deb5603e..9f9b8a1abd 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -272,7 +272,7 @@ class dbal_firebird extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index d92fe27b99..bde283c3ea 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -162,7 +162,7 @@ class dbal_mssql extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 6292792a55..687bc52abc 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -181,7 +181,7 @@ class dbal_mssql_odbc extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 0d8786171a..36ff461a29 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -338,7 +338,7 @@ class dbal_mssqlnative extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index fd567af076..5b4ff86579 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -190,7 +190,7 @@ class dbal_mysql extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index 26cade2ff0..1f13bd5459 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -196,7 +196,7 @@ class dbal_mysqli extends dbal if ($cache_ttl) { - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } } else if (defined('DEBUG_EXTRA')) diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index e9ff2f4434..de2729e973 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -421,7 +421,7 @@ class dbal_oracle extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index c35199e917..f0a4a7a7a2 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -218,7 +218,7 @@ class dbal_postgres extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index 814b593f05..2cf55b07e2 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -135,7 +135,7 @@ class dbal_sqlite extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 564bd35863..81ce9ac1aa 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -9,7 +9,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -class phpbb_cache_test extends phpbb_test_case +class phpbb_cache_test extends phpbb_database_test_case { private $cache_dir; @@ -18,6 +18,11 @@ class phpbb_cache_test extends phpbb_test_case $this->cache_dir = dirname(__FILE__) . '/../tmp/cache/'; } + public function getDataSet() + { + return array(); + } + protected function setUp() { if (file_exists($this->cache_dir)) @@ -67,4 +72,29 @@ class phpbb_cache_test extends phpbb_test_case 'File ACM put and get' ); } + + public function test_cache_sql() + { + $driver = new phpbb_cache_driver_file($this->cache_dir); + + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($driver); + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'board_disable\''; + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + + $this->assertFileExists($this->cache_dir . 'sql_' . md5($sql) . '.php'); + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'board_disable\''; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($first_result, $db->sql_fetchrow($result)); + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'version\''; + $result = $db->sql_query($sql, 300); + + $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); + } } diff --git a/tests/mock/cache.php b/tests/mock/cache.php index c6d08afef0..b64c92ea89 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -121,7 +121,7 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface public function sql_load($query) { } - public function sql_save($query, &$query_result, $ttl) + public function sql_save($query, $query_result, $ttl) { } public function sql_exists($query_id) From b64ac12bd566a08ff7d4ff3a257dfbb2f8168a56 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 19:41:00 -0500 Subject: [PATCH 3/6] [ticket/10875] Use fixtures for sql cache test PHPBB3-10875 --- tests/cache/cache_test.php | 28 ++++++++++++++++------------ tests/cache/fixtures/config.xml | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 tests/cache/fixtures/config.xml diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 81ce9ac1aa..c73d36973e 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -20,11 +20,13 @@ class phpbb_cache_test extends phpbb_database_test_case public function getDataSet() { - return array(); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); } protected function setUp() { + parent::setUp(); + if (file_exists($this->cache_dir)) { // cache directory possibly left after aborted @@ -40,6 +42,8 @@ class phpbb_cache_test extends phpbb_database_test_case { $this->remove_cache_dir(); } + + parent::tearDown(); } private function create_cache_dir() @@ -72,29 +76,29 @@ class phpbb_cache_test extends phpbb_database_test_case 'File ACM put and get' ); } - + public function test_cache_sql() { $driver = new phpbb_cache_driver_file($this->cache_dir); - + global $db, $cache; $db = $this->new_dbal(); $cache = new phpbb_cache_service($driver); - - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'board_disable\''; + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'foo\''; $result = $db->sql_query($sql, 300); $first_result = $db->sql_fetchrow($result); - + $this->assertFileExists($this->cache_dir . 'sql_' . md5($sql) . '.php'); - - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'board_disable\''; + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'foo\''; $result = $db->sql_query($sql, 300); - + $this->assertEquals($first_result, $db->sql_fetchrow($result)); - - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'version\''; + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'bar\''; $result = $db->sql_query($sql, 300); - + $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); } } diff --git a/tests/cache/fixtures/config.xml b/tests/cache/fixtures/config.xml new file mode 100644 index 0000000000..9d395b685c --- /dev/null +++ b/tests/cache/fixtures/config.xml @@ -0,0 +1,18 @@ + + + + config_name + config_value + is_dynamic + + foo + 23 + 0 + + + bar + 42 + 1 + +
+
From 44e48817c387ff5ee26746a00a00f900bdd375dd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 31 Jul 2012 14:43:22 -0500 Subject: [PATCH 4/6] [ticket/10875] Close $db connection at end of test Fixes a pgSQL issue PHPBB3-10875 --- tests/cache/cache_test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index c73d36973e..06d9d89f68 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -100,5 +100,7 @@ class phpbb_cache_test extends phpbb_database_test_case $result = $db->sql_query($sql, 300); $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); + + $db->sql_close(); } } From 1db91af0000a56b676bf593aab1852190d1d6a7b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 16:28:56 -0500 Subject: [PATCH 5/6] [ticket/10875] Break queries onto separate lines and use double quotes Coding guidelines PHPBB3-10875 --- tests/cache/cache_test.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 06d9d89f68..336c009ebe 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -85,18 +85,21 @@ class phpbb_cache_test extends phpbb_database_test_case $db = $this->new_dbal(); $cache = new phpbb_cache_service($driver); - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'foo\''; + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; $result = $db->sql_query($sql, 300); $first_result = $db->sql_fetchrow($result); $this->assertFileExists($this->cache_dir . 'sql_' . md5($sql) . '.php'); - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'foo\''; + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; $result = $db->sql_query($sql, 300); $this->assertEquals($first_result, $db->sql_fetchrow($result)); - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'bar\''; + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'bar'"; $result = $db->sql_query($sql, 300); $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); From 4b7cdd4264b2669aaf0a0f99db2a9b00b2b58c4e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 18:43:46 -0500 Subject: [PATCH 6/6] [ticket/10875] Fix cache test Check for the correct filename based on the way the cache driver creates it PHPBB3-10875 --- tests/cache/cache_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 336c009ebe..c5f5fac88c 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -90,7 +90,7 @@ class phpbb_cache_test extends phpbb_database_test_case $result = $db->sql_query($sql, 300); $first_result = $db->sql_fetchrow($result); - $this->assertFileExists($this->cache_dir . 'sql_' . md5($sql) . '.php'); + $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'";