diff options
author | VirtualTam <virtualtam@flibidi.net> | 2018-12-03 00:08:04 +0100 |
---|---|---|
committer | VirtualTam <virtualtam@flibidi.net> | 2019-01-12 22:47:48 +0100 |
commit | dfc650aa239d3a2c028d0ba13132ce75b4f4c0b4 (patch) | |
tree | 4b3f54ecfe27e57fd5d32f3543f688c545588aab /tests/CacheTest.php | |
parent | f3d2f257946e2a3c8791c1ba99b379acbe934fec (diff) | |
download | Shaarli-dfc650aa239d3a2c028d0ba13132ce75b4f4c0b4.tar.gz Shaarli-dfc650aa239d3a2c028d0ba13132ce75b4f4c0b4.tar.zst Shaarli-dfc650aa239d3a2c028d0ba13132ce75b4f4c0b4.zip |
namespacing: \Shaarli\Feed\{Cache,CachedPage,FeedBuilder}
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/CacheTest.php')
-rw-r--r-- | tests/CacheTest.php | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/tests/CacheTest.php b/tests/CacheTest.php deleted file mode 100644 index f60fad91..00000000 --- a/tests/CacheTest.php +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Cache tests | ||
4 | */ | ||
5 | |||
6 | // required to access $_SESSION array | ||
7 | session_start(); | ||
8 | |||
9 | require_once 'application/Cache.php'; | ||
10 | |||
11 | /** | ||
12 | * Unitary tests for cached pages | ||
13 | */ | ||
14 | class CacheTest extends PHPUnit_Framework_TestCase | ||
15 | { | ||
16 | // test cache directory | ||
17 | protected static $testCacheDir = 'sandbox/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 | } else { | ||
31 | array_map('unlink', glob(self::$testCacheDir.'/*')); | ||
32 | } | ||
33 | |||
34 | foreach (self::$pages as $page) { | ||
35 | file_put_contents(self::$testCacheDir.'/'.$page.'.cache', $page); | ||
36 | } | ||
37 | file_put_contents(self::$testCacheDir.'/intru.der', 'ShouldNotBeThere'); | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * Remove dummycache folder after each tests. | ||
42 | */ | ||
43 | public function tearDown() | ||
44 | { | ||
45 | array_map('unlink', glob(self::$testCacheDir.'/*')); | ||
46 | rmdir(self::$testCacheDir); | ||
47 | } | ||
48 | |||
49 | /** | ||
50 | * Purge cached pages | ||
51 | */ | ||
52 | public function testPurgeCachedPages() | ||
53 | { | ||
54 | purgeCachedPages(self::$testCacheDir); | ||
55 | foreach (self::$pages as $page) { | ||
56 | $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); | ||
57 | } | ||
58 | |||
59 | $this->assertFileExists(self::$testCacheDir.'/intru.der'); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Purge cached pages - missing directory | ||
64 | */ | ||
65 | public function testPurgeCachedPagesMissingDir() | ||
66 | { | ||
67 | $oldlog = ini_get('error_log'); | ||
68 | ini_set('error_log', '/dev/null'); | ||
69 | $this->assertEquals( | ||
70 | 'Cannot purge sandbox/dummycache_missing: no directory', | ||
71 | purgeCachedPages(self::$testCacheDir.'_missing') | ||
72 | ); | ||
73 | ini_set('error_log', $oldlog); | ||
74 | } | ||
75 | |||
76 | /** | ||
77 | * Purge cached pages and session cache | ||
78 | */ | ||
79 | public function testInvalidateCaches() | ||
80 | { | ||
81 | $this->assertArrayNotHasKey('tags', $_SESSION); | ||
82 | $_SESSION['tags'] = array('goodbye', 'cruel', 'world'); | ||
83 | |||
84 | invalidateCaches(self::$testCacheDir); | ||
85 | foreach (self::$pages as $page) { | ||
86 | $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); | ||
87 | } | ||
88 | |||
89 | $this->assertArrayNotHasKey('tags', $_SESSION); | ||
90 | } | ||
91 | } | ||