From 01e48f269df59e02798dad4a698c125d76b0ed70 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Thu, 9 Jul 2015 22:14:39 +0200 Subject: CachedPage: move to a proper file, add tests Modifications - rename `pageCache` to `CachedPage` - move utilities to `Cache` - do not access globals - apply coding rules - update LinkDB and test code - add test coverage Signed-off-by: VirtualTam --- tests/CacheTest.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/CacheTest.php (limited to 'tests/CacheTest.php') diff --git a/tests/CacheTest.php b/tests/CacheTest.php new file mode 100644 index 00000000..4caf6552 --- /dev/null +++ b/tests/CacheTest.php @@ -0,0 +1,63 @@ +assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); + } + } + + /** + * Purge cached pages and session cache + */ + public function testInvalidateCaches() + { + $this->assertArrayNotHasKey('tags', $_SESSION); + $_SESSION['tags'] = array('goodbye', 'cruel', 'world'); + + invalidateCaches(self::$testCacheDir); + foreach (self::$pages as $page) { + $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); + } + + $this->assertArrayNotHasKey('tags', $_SESSION); + } +} -- cgit v1.2.3 From aedd62e2b84b4ea0d3c03f5c23ec594f4ebb1c17 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Thu, 13 Aug 2015 21:39:51 +0200 Subject: Cache: simplify cached content cleanup, improve tests Signed-off-by: VirtualTam --- tests/CacheTest.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'tests/CacheTest.php') diff --git a/tests/CacheTest.php b/tests/CacheTest.php index 4caf6552..aa5395b0 100644 --- a/tests/CacheTest.php +++ b/tests/CacheTest.php @@ -27,11 +27,14 @@ 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'); } /** @@ -42,7 +45,20 @@ 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() + { + $this->assertEquals( + 'Cannot purge tests/dummycache_missing: no directory', + purgeCachedPages(self::$testCacheDir.'_missing') + ); } /** -- cgit v1.2.3