From b0428aa9b02b058b72c40b6e8dc2298d55bf692f Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 23 Jan 2020 21:13:41 +0100 Subject: Migrate cache purge function to a proper class And update dependencies and tests. Note that SESSION['tags'] has been removed a log ago --- tests/render/PageCacheManagerTest.php | 86 +++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/render/PageCacheManagerTest.php (limited to 'tests/render') diff --git a/tests/render/PageCacheManagerTest.php b/tests/render/PageCacheManagerTest.php new file mode 100644 index 00000000..991515d0 --- /dev/null +++ b/tests/render/PageCacheManagerTest.php @@ -0,0 +1,86 @@ +cacheManager = new PageCacheManager(static::$testCacheDir); + + 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); + } + + /** + * Purge cached pages + */ + public function testPurgeCachedPages() + { + $this->cacheManager->purgeCachedPages(); + 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->cacheManager = new PageCacheManager(self::$testCacheDir . '_missing'); + + $oldlog = ini_get('error_log'); + ini_set('error_log', '/dev/null'); + $this->assertEquals( + 'Cannot purge sandbox/dummycache_missing: no directory', + $this->cacheManager->purgeCachedPages() + ); + ini_set('error_log', $oldlog); + } +} -- cgit v1.2.3