aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/CacheTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2015-07-09 22:14:39 +0200
committerVirtualTam <virtualtam@flibidi.net>2015-08-13 23:48:06 +0200
commit01e48f269df59e02798dad4a698c125d76b0ed70 (patch)
tree9341487badd4ed14e0104ae338cf48c4ee0dc994 /tests/CacheTest.php
parent5ac5349ac053b1e560b136c62f8c764fd3230039 (diff)
downloadShaarli-01e48f269df59e02798dad4a698c125d76b0ed70.tar.gz
Shaarli-01e48f269df59e02798dad4a698c125d76b0ed70.tar.zst
Shaarli-01e48f269df59e02798dad4a698c125d76b0ed70.zip
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 <virtualtam@flibidi.net>
Diffstat (limited to 'tests/CacheTest.php')
-rw-r--r--tests/CacheTest.php63
1 files changed, 63 insertions, 0 deletions
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 @@
1<?php
2/**
3 * Cache tests
4 */
5
6// required to access $_SESSION array
7session_start();
8
9require_once 'application/Cache.php';
10
11/**
12 * Unitary tests for cached pages
13 */
14class CachedTest extends PHPUnit_Framework_TestCase
15{
16 // test cache directory
17 protected static $testCacheDir = 'tests/dummycache';
18
19 // dummy cached file names / content
20 protected static $pages = array('a', 'toto', 'd7b59c');
21
22
23 /**
24 * Populate the cache with dummy files
25 */
26 public function setUp()
27 {
28 if (! is_dir(self::$testCacheDir)) {
29 mkdir(self::$testCacheDir);
30 }
31
32 foreach (self::$pages as $page) {
33 file_put_contents(self::$testCacheDir.'/'.$page.'.cache', $page);
34 }
35 }
36
37 /**
38 * Purge cached pages
39 */
40 public function testPurgeCachedPages()
41 {
42 purgeCachedPages(self::$testCacheDir);
43 foreach (self::$pages as $page) {
44 $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache');
45 }
46 }
47
48 /**
49 * Purge cached pages and session cache
50 */
51 public function testInvalidateCaches()
52 {
53 $this->assertArrayNotHasKey('tags', $_SESSION);
54 $_SESSION['tags'] = array('goodbye', 'cruel', 'world');
55
56 invalidateCaches(self::$testCacheDir);
57 foreach (self::$pages as $page) {
58 $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache');
59 }
60
61 $this->assertArrayNotHasKey('tags', $_SESSION);
62 }
63}