1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-17 19:37:22 +02:00

added test for storing gzencoded string in memcache

This commit is contained in:
Steve Clay
2010-10-16 00:10:24 +00:00
parent c6a2f87641
commit f8415b9ca8

View File

@@ -6,33 +6,47 @@ require_once 'Minify/Cache/Memcache.php';
function test_Minify_Cache_Memcache() function test_Minify_Cache_Memcache()
{ {
$prefix = 'Minify_Cache_Memcache : '; $prefix = 'Minify_Cache_Memcache : ';
$thisFileActive = (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME']));
if (! function_exists('memcache_set')) { if (! function_exists('memcache_set')) {
if ($thisFileActive) {
echo "NOTE: {$prefix}PHP lacks memcache support\n";
}
return; return;
} }
$mc = new Memcache; $mc = new Memcache;
if (! @$mc->connect('localhost', 11211)) { if (! @$mc->connect('localhost', 11211)) {
if ($thisFileActive) {
echo "NOTE: {$prefix}Could not connect to localhost:11211\n";
}
return; return;
} }
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8 $data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
$id = 'Minify_test_cache'; $id = 'Minify_test_memcache';
$cache = new Minify_Cache_Memcache($mc); $cache = new Minify_Cache_Memcache($mc);
assertTrue(true === $cache->store($id, $data), $prefix . 'store'); assertTrue(true === $cache->store($id, $data), $prefix . 'store');
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize'); assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid'); assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
ob_start(); ob_start();
$cache->display($id); $cache->display($id);
$displayed = ob_get_contents(); $displayed = ob_get_contents();
ob_end_clean(); ob_end_clean();
assertTrue($data === $displayed, $prefix . 'display'); assertTrue($data === $displayed, $prefix . 'display');
assertTrue($data === $cache->fetch($id), $prefix . 'fetch'); assertTrue($data === $cache->fetch($id), $prefix . 'fetch');
if (function_exists('gzencode')) {
$data = gzencode($data);
$id .= ".gz";
$cache->store($id, $data);
assertTrue($data === $cache->fetch($id), $prefix . 'store/fetch gzencoded string');
}
} }
test_Minify_Cache_Memcache(); test_Minify_Cache_Memcache();