aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-23 21:13:41 +0100
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commitb0428aa9b02b058b72c40b6e8dc2298d55bf692f (patch)
treec57176b24d76836a73608fb273b1094fcb8de785 /tests
parent485b168a9677d160b0c0426e4f282b9bd0c632c1 (diff)
downloadShaarli-b0428aa9b02b058b72c40b6e8dc2298d55bf692f.tar.gz
Shaarli-b0428aa9b02b058b72c40b6e8dc2298d55bf692f.tar.zst
Shaarli-b0428aa9b02b058b72c40b6e8dc2298d55bf692f.zip
Migrate cache purge function to a proper class
And update dependencies and tests. Note that SESSION['tags'] has been removed a log ago
Diffstat (limited to 'tests')
-rw-r--r--tests/bootstrap.php1
-rw-r--r--tests/legacy/LegacyLinkDBTest.php1
-rw-r--r--tests/render/PageCacheManagerTest.php (renamed from tests/feed/CacheTest.php)38
3 files changed, 16 insertions, 24 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 0afbcba6..c80bcb33 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -18,7 +18,6 @@ require_once 'application/bookmark/LinkUtils.php';
18require_once 'application/Utils.php'; 18require_once 'application/Utils.php';
19require_once 'application/http/UrlUtils.php'; 19require_once 'application/http/UrlUtils.php';
20require_once 'application/http/HttpUtils.php'; 20require_once 'application/http/HttpUtils.php';
21require_once 'application/feed/Cache.php';
22require_once 'tests/utils/ReferenceLinkDB.php'; 21require_once 'tests/utils/ReferenceLinkDB.php';
23require_once 'tests/utils/ReferenceHistory.php'; 22require_once 'tests/utils/ReferenceHistory.php';
24require_once 'tests/utils/FakeBookmarkService.php'; 23require_once 'tests/utils/FakeBookmarkService.php';
diff --git a/tests/legacy/LegacyLinkDBTest.php b/tests/legacy/LegacyLinkDBTest.php
index 17b2b0e6..0884ad03 100644
--- a/tests/legacy/LegacyLinkDBTest.php
+++ b/tests/legacy/LegacyLinkDBTest.php
@@ -11,7 +11,6 @@ use ReflectionClass;
11use Shaarli; 11use Shaarli;
12use Shaarli\Bookmark\Bookmark; 12use Shaarli\Bookmark\Bookmark;
13 13
14require_once 'application/feed/Cache.php';
15require_once 'application/Utils.php'; 14require_once 'application/Utils.php';
16require_once 'tests/utils/ReferenceLinkDB.php'; 15require_once 'tests/utils/ReferenceLinkDB.php';
17 16
diff --git a/tests/feed/CacheTest.php b/tests/render/PageCacheManagerTest.php
index c0a9f26f..991515d0 100644
--- a/tests/feed/CacheTest.php
+++ b/tests/render/PageCacheManagerTest.php
@@ -2,17 +2,18 @@
2/** 2/**
3 * Cache tests 3 * Cache tests
4 */ 4 */
5namespace Shaarli\Feed; 5namespace Shaarli\Render;
6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Security\SessionManager;
6 9
7// required to access $_SESSION array 10// required to access $_SESSION array
8session_start(); 11session_start();
9 12
10require_once 'application/feed/Cache.php';
11
12/** 13/**
13 * Unitary tests for cached pages 14 * Unitary tests for cached pages
14 */ 15 */
15class CacheTest extends \PHPUnit\Framework\TestCase 16class PageCacheManagerTest extends TestCase
16{ 17{
17 // test cache directory 18 // test cache directory
18 protected static $testCacheDir = 'sandbox/dummycache'; 19 protected static $testCacheDir = 'sandbox/dummycache';
@@ -20,12 +21,19 @@ class CacheTest extends \PHPUnit\Framework\TestCase
20 // dummy cached file names / content 21 // dummy cached file names / content
21 protected static $pages = array('a', 'toto', 'd7b59c'); 22 protected static $pages = array('a', 'toto', 'd7b59c');
22 23
24 /** @var PageCacheManager */
25 protected $cacheManager;
26
27 /** @var SessionManager */
28 protected $sessionManager;
23 29
24 /** 30 /**
25 * Populate the cache with dummy files 31 * Populate the cache with dummy files
26 */ 32 */
27 public function setUp() 33 public function setUp()
28 { 34 {
35 $this->cacheManager = new PageCacheManager(static::$testCacheDir);
36
29 if (!is_dir(self::$testCacheDir)) { 37 if (!is_dir(self::$testCacheDir)) {
30 mkdir(self::$testCacheDir); 38 mkdir(self::$testCacheDir);
31 } else { 39 } else {
@@ -52,7 +60,7 @@ class CacheTest extends \PHPUnit\Framework\TestCase
52 */ 60 */
53 public function testPurgeCachedPages() 61 public function testPurgeCachedPages()
54 { 62 {
55 purgeCachedPages(self::$testCacheDir); 63 $this->cacheManager->purgeCachedPages();
56 foreach (self::$pages as $page) { 64 foreach (self::$pages as $page) {
57 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache'); 65 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
58 } 66 }
@@ -65,28 +73,14 @@ class CacheTest extends \PHPUnit\Framework\TestCase
65 */ 73 */
66 public function testPurgeCachedPagesMissingDir() 74 public function testPurgeCachedPagesMissingDir()
67 { 75 {
76 $this->cacheManager = new PageCacheManager(self::$testCacheDir . '_missing');
77
68 $oldlog = ini_get('error_log'); 78 $oldlog = ini_get('error_log');
69 ini_set('error_log', '/dev/null'); 79 ini_set('error_log', '/dev/null');
70 $this->assertEquals( 80 $this->assertEquals(
71 'Cannot purge sandbox/dummycache_missing: no directory', 81 'Cannot purge sandbox/dummycache_missing: no directory',
72 purgeCachedPages(self::$testCacheDir . '_missing') 82 $this->cacheManager->purgeCachedPages()
73 ); 83 );
74 ini_set('error_log', $oldlog); 84 ini_set('error_log', $oldlog);
75 } 85 }
76
77 /**
78 * Purge cached pages and session cache
79 */
80 public function testInvalidateCaches()
81 {
82 $this->assertArrayNotHasKey('tags', $_SESSION);
83 $_SESSION['tags'] = array('goodbye', 'cruel', 'world');
84
85 invalidateCaches(self::$testCacheDir);
86 foreach (self::$pages as $page) {
87 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
88 }
89
90 $this->assertArrayNotHasKey('tags', $_SESSION);
91 }
92} 86}