aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/render/PageCacheManagerTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-08-27 10:27:34 +0200
committerGitHub <noreply@github.com>2020-08-27 10:27:34 +0200
commitaf41d5ab5d2bd3ba64d052c997bc6afa6966a63c (patch)
tree8fad2829c55f94022e359fa8914e11f80a2afc2a /tests/render/PageCacheManagerTest.php
parentb8e3630f2ecd142d397b1b062a346a667bb78595 (diff)
parent0c6fdbe12bbbb336348666b14b82096f24d5858b (diff)
downloadShaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.tar.gz
Shaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.tar.zst
Shaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.zip
Merge pull request #1511 from ArthurHoaro/wip-slim-routing
Diffstat (limited to 'tests/render/PageCacheManagerTest.php')
-rw-r--r--tests/render/PageCacheManagerTest.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/render/PageCacheManagerTest.php b/tests/render/PageCacheManagerTest.php
new file mode 100644
index 00000000..c258f45f
--- /dev/null
+++ b/tests/render/PageCacheManagerTest.php
@@ -0,0 +1,85 @@
1<?php
2
3/**
4 * Cache tests
5 */
6
7namespace Shaarli\Render;
8
9use PHPUnit\Framework\TestCase;
10use Shaarli\Security\SessionManager;
11
12/**
13 * Unitary tests for cached pages
14 */
15class PageCacheManagerTest extends TestCase
16{
17 // test cache directory
18 protected static $testCacheDir = 'sandbox/dummycache';
19
20 // dummy cached file names / content
21 protected static $pages = array('a', 'toto', 'd7b59c');
22
23 /** @var PageCacheManager */
24 protected $cacheManager;
25
26 /** @var SessionManager */
27 protected $sessionManager;
28
29 /**
30 * Populate the cache with dummy files
31 */
32 public function setUp()
33 {
34 $this->cacheManager = new PageCacheManager(static::$testCacheDir, true);
35
36 if (!is_dir(self::$testCacheDir)) {
37 mkdir(self::$testCacheDir);
38 } else {
39 array_map('unlink', glob(self::$testCacheDir . '/*'));
40 }
41
42 foreach (self::$pages as $page) {
43 file_put_contents(self::$testCacheDir . '/' . $page . '.cache', $page);
44 }
45 file_put_contents(self::$testCacheDir . '/intru.der', 'ShouldNotBeThere');
46 }
47
48 /**
49 * Remove dummycache folder after each tests.
50 */
51 public function tearDown()
52 {
53 array_map('unlink', glob(self::$testCacheDir . '/*'));
54 rmdir(self::$testCacheDir);
55 }
56
57 /**
58 * Purge cached pages
59 */
60 public function testPurgeCachedPages()
61 {
62 $this->cacheManager->purgeCachedPages();
63 foreach (self::$pages as $page) {
64 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
65 }
66
67 $this->assertFileExists(self::$testCacheDir . '/intru.der');
68 }
69
70 /**
71 * Purge cached pages - missing directory
72 */
73 public function testPurgeCachedPagesMissingDir()
74 {
75 $this->cacheManager = new PageCacheManager(self::$testCacheDir . '_missing', true);
76
77 $oldlog = ini_get('error_log');
78 ini_set('error_log', '/dev/null');
79 $this->assertEquals(
80 'Cannot purge sandbox/dummycache_missing: no directory',
81 $this->cacheManager->purgeCachedPages()
82 );
83 ini_set('error_log', $oldlog);
84 }
85}