aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/render
diff options
context:
space:
mode:
Diffstat (limited to 'tests/render')
-rw-r--r--tests/render/PageCacheManagerTest.php85
-rw-r--r--tests/render/ThemeUtilsTest.php2
2 files changed, 86 insertions, 1 deletions
diff --git a/tests/render/PageCacheManagerTest.php b/tests/render/PageCacheManagerTest.php
new file mode 100644
index 00000000..08d4e5ea
--- /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 Shaarli\Security\SessionManager;
10use Shaarli\TestCase;
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 protected function setUp(): void
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 protected function tearDown(): void
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}
diff --git a/tests/render/ThemeUtilsTest.php b/tests/render/ThemeUtilsTest.php
index 58e3426b..7d841e4d 100644
--- a/tests/render/ThemeUtilsTest.php
+++ b/tests/render/ThemeUtilsTest.php
@@ -7,7 +7,7 @@ namespace Shaarli\Render;
7 * 7 *
8 * @package Shaarli 8 * @package Shaarli
9 */ 9 */
10class ThemeUtilsTest extends \PHPUnit\Framework\TestCase 10class ThemeUtilsTest extends \Shaarli\TestCase
11{ 11{
12 /** 12 /**
13 * Test getThemes() with existing theme directories. 13 * Test getThemes() with existing theme directories.