mirror of
https://github.com/mrclay/minify.git
synced 2025-03-12 16:39:38 +01:00
port MinifyCacheFileTest to phpunit
This commit is contained in:
parent
ed79a279a9
commit
554542401f
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
require_once '_inc.php';
|
||||
|
||||
function test_Minify_Cache_File()
|
||||
{
|
||||
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||
$id = 'Minify_test_cache_noLock';
|
||||
$prefix = 'Minify_Cache_File : ';
|
||||
|
||||
$cache = new Minify_Cache_File();
|
||||
|
||||
echo " Minify_Cache_File : path is set to: '" . $cache->getPath() . "'.\n";
|
||||
|
||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
||||
|
||||
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
|
||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||
|
||||
ob_start();
|
||||
$cache->display($id);
|
||||
$displayed = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
assertTrue($data === $displayed, $prefix . 'display');
|
||||
|
||||
assertTrue($data === $cache->fetch($id), $prefix . 'fetch');
|
||||
|
||||
// test with locks
|
||||
|
||||
$id = 'Minify_test_cache_withLock';
|
||||
$cache = new Minify_Cache_File('', true);
|
||||
|
||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store w/ lock');
|
||||
|
||||
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
|
||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||
|
||||
ob_start();
|
||||
$cache->display($id);
|
||||
$displayed = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
assertTrue($data === $displayed, $prefix . 'display w/ lock');
|
||||
|
||||
assertTrue($data === $cache->fetch($id), $prefix . 'fetch w/ lock');
|
||||
}
|
||||
|
||||
test_Minify_Cache_File();
|
@ -3,7 +3,6 @@
|
||||
require 'test_Minify.php';
|
||||
require 'test_Minify_HTML_Helper.php';
|
||||
require 'test_Minify_Cache_APC.php';
|
||||
require 'test_Minify_Cache_File.php';
|
||||
require 'test_Minify_Cache_Memcache.php';
|
||||
require 'test_Minify_Cache_WinCache.php';
|
||||
require 'test_Minify_Cache_ZendPlatform.php';
|
||||
|
40
tests/MinifyCacheFileTest.php
Normal file
40
tests/MinifyCacheFileTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
class MinifyCacheFileTest extends TestCase
|
||||
{
|
||||
public function test1()
|
||||
{
|
||||
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||
$id = 'Minify_test_cache_noLock';
|
||||
$cache = new Minify_Cache_File();
|
||||
|
||||
$this->assertTestCache($cache, $id, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* test with locks
|
||||
*/
|
||||
public function test2()
|
||||
{
|
||||
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||
$id = 'Minify_test_cache_withLock';
|
||||
$cache = new Minify_Cache_File('', true);
|
||||
|
||||
$this->assertTestCache($cache, $id, $data);
|
||||
}
|
||||
|
||||
private function assertTestCache(Minify_Cache_File $cache, $id, $data)
|
||||
{
|
||||
$this->assertTrue($cache->store($id, $data), "$id store");
|
||||
$this->assertEquals($cache->getSize($id), $this->countBytes($data), "$id getSize");
|
||||
$this->assertTrue($cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), "$id isValid");
|
||||
|
||||
ob_start();
|
||||
$cache->display($id);
|
||||
$displayed = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertSame($data, $displayed, "$id display");
|
||||
$this->assertEquals($data, $cache->fetch($id), "$id fetch");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user