1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-09 02:06:32 +02:00

[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
This commit is contained in:
Oleg Pudeyev
2012-12-01 00:48:21 -05:00
parent 3a702084e4
commit c852044d6e
4 changed files with 126 additions and 3 deletions

View File

@@ -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($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php');
$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->assertTrue($redis->exists($key));
$sql = 'DELETE FROM phpbb_config';
$result = $db->sql_query($sql);