X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FCacheTest.php;h=992e26a5502cea6afc15cc9756f85c7e507089d0;hb=ae7c954b1279981cc23c9f67d88f55bfecc4d828;hp=4caf6552ac668a2238672c4dfa5513d92e5489cb;hpb=01e48f269df59e02798dad4a698c125d76b0ed70;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/CacheTest.php b/tests/CacheTest.php index 4caf6552..992e26a5 100644 --- a/tests/CacheTest.php +++ b/tests/CacheTest.php @@ -11,10 +11,10 @@ require_once 'application/Cache.php'; /** * Unitary tests for cached pages */ -class CachedTest extends PHPUnit_Framework_TestCase +class CacheTest extends PHPUnit_Framework_TestCase { // test cache directory - protected static $testCacheDir = 'tests/dummycache'; + protected static $testCacheDir = 'sandbox/dummycache'; // dummy cached file names / content protected static $pages = array('a', 'toto', 'd7b59c'); @@ -27,11 +27,23 @@ class CachedTest extends PHPUnit_Framework_TestCase { if (! is_dir(self::$testCacheDir)) { mkdir(self::$testCacheDir); + } else { + array_map('unlink', glob(self::$testCacheDir.'/*')); } - + foreach (self::$pages as $page) { file_put_contents(self::$testCacheDir.'/'.$page.'.cache', $page); } + file_put_contents(self::$testCacheDir.'/intru.der', 'ShouldNotBeThere'); + } + + /** + * Remove dummycache folder after each tests. + */ + public function tearDown() + { + array_map('unlink', glob(self::$testCacheDir.'/*')); + rmdir(self::$testCacheDir); } /** @@ -42,7 +54,23 @@ class CachedTest extends PHPUnit_Framework_TestCase purgeCachedPages(self::$testCacheDir); foreach (self::$pages as $page) { $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); - } + } + + $this->assertFileExists(self::$testCacheDir.'/intru.der'); + } + + /** + * Purge cached pages - missing directory + */ + public function testPurgeCachedPagesMissingDir() + { + $oldlog = ini_get('error_log'); + ini_set('error_log', '/dev/null'); + $this->assertEquals( + 'Cannot purge sandbox/dummycache_missing: no directory', + purgeCachedPages(self::$testCacheDir.'_missing') + ); + ini_set('error_log', $oldlog); } /**