aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cache
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-12-01 00:48:21 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2012-12-01 00:48:21 -0500
commitc852044d6eecc0a652800b1661491c0f9c545054 (patch)
tree3b5777cf4fa1c3fb76293c227e1eb86d7171e187 /tests/cache
parent3a702084e4249830a87dc0914127e00c1bb1b1dd (diff)
downloadforums-c852044d6eecc0a652800b1661491c0f9c545054.tar
forums-c852044d6eecc0a652800b1661491c0f9c545054.tar.gz
forums-c852044d6eecc0a652800b1661491c0f9c545054.tar.bz2
forums-c852044d6eecc0a652800b1661491c0f9c545054.tar.xz
forums-c852044d6eecc0a652800b1661491c0f9c545054.zip
[ticket/9983] Add redis cache driver tests.
In order to not overwrite data in default redis store, at least one of redis host or post must be explicitly specified. Redis cache driver constructor has been modified to accept host and port as parameters. This was not added to public API as there are more parameters being passed via global constants. PHPBB3-9983
Diffstat (limited to 'tests/cache')
-rw-r--r--tests/cache/cache_test.php68
1 files changed, 66 insertions, 2 deletions
diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php
index 285af5cd0c..ad60a9077e 100644
--- a/tests/cache/cache_test.php
+++ b/tests/cache/cache_test.php
@@ -77,7 +77,7 @@ class phpbb_cache_test extends phpbb_database_test_case
);
}
- public function test_cache_sql()
+ public function test_cache_sql_file()
{
$driver = new phpbb_cache_driver_file($this->cache_dir);
@@ -87,12 +87,76 @@ class phpbb_cache_test extends phpbb_database_test_case
$sql = "SELECT * FROM phpbb_config
WHERE config_name = 'foo'";
+
+ $cache_path = $this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php';
+ $this->assertFileNotExists($cache_path);
+
+ $result = $db->sql_query($sql, 300);
+ $first_result = $db->sql_fetchrow($result);
+ $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0);
+ $this->assertEquals($expected, $first_result);
+
+ $this->assertFileExists($cache_path);
+
+ $sql = 'DELETE FROM phpbb_config';
+ $result = $db->sql_query($sql);
+
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'foo'";
+ $result = $db->sql_query($sql, 300);
+
+ $this->assertEquals($expected, $db->sql_fetchrow($result));
+
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'foo'";
+ $result = $db->sql_query($sql);
+
+ $no_cache_result = $db->sql_fetchrow($result);
+ $this->assertSame(false, $no_cache_result);
+
+ $db->sql_close();
+ }
+
+ public function test_cache_sql_redis()
+ {
+ if (!extension_loaded('redis'))
+ {
+ $this->markTestSkipped('redis extension is not loaded');
+ }
+
+ $config = phpbb_test_case_helpers::get_test_config();
+ if (isset($config['redis_host']) || isset($config['redis_port']))
+ {
+ $host = isset($config['redis_host']) ? $config['redis_host'] : 'localhost';
+ $port = isset($config['redis_port']) ? $config['redis_port'] : 6379;
+ }
+ else
+ {
+ $this->markTestSkipped('Test redis host/port is not specified');
+ }
+ $driver = new phpbb_cache_driver_redis($host, $port);
+ $driver->purge();
+
+ global $db, $cache;
+ $db = $this->new_dbal();
+ $cache = new phpbb_cache_service($driver);
+
+ $redis = new Redis();
+ $ok = $redis->connect($host, $port);
+ $this->assertTrue($ok);
+
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'foo'";
+
+ $key = $driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql));
+ $this->assertFalse($redis->exists($key));
+
$result = $db->sql_query($sql, 300);
$first_result = $db->sql_fetchrow($result);
$expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0);
$this->assertEquals($expected, $first_result);
- $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php');
+ $this->assertTrue($redis->exists($key));
$sql = 'DELETE FROM phpbb_config';
$result = $db->sql_query($sql);