6 // required to access $_SESSION array
9 require_once 'application/Cache.php';
12 * Unitary tests for cached pages
14 class CachedTest
extends PHPUnit_Framework_TestCase
16 // test cache directory
17 protected static $testCacheDir = 'tests/dummycache';
19 // dummy cached file names / content
20 protected static $pages = array('a', 'toto', 'd7b59c');
24 * Populate the cache with dummy files
26 public function setUp()
28 if (! is_dir(self
::$testCacheDir)) {
29 mkdir(self
::$testCacheDir);
32 foreach (self
::$pages as $page) {
33 file_put_contents(self
::$testCacheDir.'/'.$page.'.cache', $page);
40 public function testPurgeCachedPages()
42 purgeCachedPages(self
::$testCacheDir);
43 foreach (self
::$pages as $page) {
44 $this->assertFileNotExists(self
::$testCacheDir.'/'.$page.'.cache');
49 * Purge cached pages and session cache
51 public function testInvalidateCaches()
53 $this->assertArrayNotHasKey('tags', $_SESSION);
54 $_SESSION['tags'] = array('goodbye', 'cruel', 'world');
56 invalidateCaches(self
::$testCacheDir);
57 foreach (self
::$pages as $page) {
58 $this->assertFileNotExists(self
::$testCacheDir.'/'.$page.'.cache');
61 $this->assertArrayNotHasKey('tags', $_SESSION);