mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-20 07:42:09 +02:00
[ticket/9983] Make sql cache test into a black box.
This makes it non-driver-specific and also makes it possible to make prefix variable private on drivers. PHPBB3-9983
This commit is contained in:
parent
49f2925900
commit
d93f582b04
38
tests/cache/apc_driver_test.php
vendored
38
tests/cache/apc_driver_test.php
vendored
@ -50,42 +50,4 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case
|
||||
$this->driver = new phpbb_cache_driver_apc;
|
||||
$this->driver->purge();
|
||||
}
|
||||
|
||||
public function test_cache_sql()
|
||||
{
|
||||
global $db, $cache;
|
||||
$db = $this->new_dbal();
|
||||
$cache = new phpbb_cache_service($this->driver);
|
||||
|
||||
$sql = "SELECT * FROM phpbb_config
|
||||
WHERE config_name = 'foo'";
|
||||
|
||||
$key = $this->driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql));
|
||||
$this->assertFalse(apc_fetch($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((bool) apc_fetch($key));
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
33
tests/cache/common_test_case.php
vendored
33
tests/cache/common_test_case.php
vendored
@ -61,4 +61,37 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case
|
||||
$this->driver->get('second_key')
|
||||
);
|
||||
}
|
||||
|
||||
public function test_cache_sql()
|
||||
{
|
||||
global $db, $cache;
|
||||
$db = $this->new_dbal();
|
||||
$cache = new phpbb_cache_service($this->driver);
|
||||
|
||||
$sql = "SELECT * FROM phpbb_config
|
||||
WHERE config_name = 'foo'";
|
||||
|
||||
$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);
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
38
tests/cache/file_driver_test.php
vendored
38
tests/cache/file_driver_test.php
vendored
@ -66,42 +66,4 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
|
||||
}
|
||||
rmdir($this->cache_dir);
|
||||
}
|
||||
|
||||
public function test_cache_sql()
|
||||
{
|
||||
global $db, $cache;
|
||||
$db = $this->new_dbal();
|
||||
$cache = new phpbb_cache_service($this->driver);
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
42
tests/cache/redis_driver_test.php
vendored
42
tests/cache/redis_driver_test.php
vendored
@ -46,46 +46,4 @@ class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case
|
||||
$this->driver = new phpbb_cache_driver_redis(self::$config['host'], self::$config['port']);
|
||||
$this->driver->purge();
|
||||
}
|
||||
|
||||
public function test_cache_sql()
|
||||
{
|
||||
global $db, $cache;
|
||||
$db = $this->new_dbal();
|
||||
$cache = new phpbb_cache_service($this->driver);
|
||||
|
||||
$redis = new Redis();
|
||||
$ok = $redis->connect(self::$config['host'], self::$config['port']);
|
||||
$this->assertTrue($ok);
|
||||
|
||||
$sql = "SELECT * FROM phpbb_config
|
||||
WHERE config_name = 'foo'";
|
||||
|
||||
$key = $this->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);
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user