diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-01-23 21:13:41 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | b0428aa9b02b058b72c40b6e8dc2298d55bf692f (patch) | |
tree | c57176b24d76836a73608fb273b1094fcb8de785 /tests | |
parent | 485b168a9677d160b0c0426e4f282b9bd0c632c1 (diff) | |
download | Shaarli-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.php | 1 | ||||
-rw-r--r-- | tests/legacy/LegacyLinkDBTest.php | 1 | ||||
-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'; | |||
18 | require_once 'application/Utils.php'; | 18 | require_once 'application/Utils.php'; |
19 | require_once 'application/http/UrlUtils.php'; | 19 | require_once 'application/http/UrlUtils.php'; |
20 | require_once 'application/http/HttpUtils.php'; | 20 | require_once 'application/http/HttpUtils.php'; |
21 | require_once 'application/feed/Cache.php'; | ||
22 | require_once 'tests/utils/ReferenceLinkDB.php'; | 21 | require_once 'tests/utils/ReferenceLinkDB.php'; |
23 | require_once 'tests/utils/ReferenceHistory.php'; | 22 | require_once 'tests/utils/ReferenceHistory.php'; |
24 | require_once 'tests/utils/FakeBookmarkService.php'; | 23 | require_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; | |||
11 | use Shaarli; | 11 | use Shaarli; |
12 | use Shaarli\Bookmark\Bookmark; | 12 | use Shaarli\Bookmark\Bookmark; |
13 | 13 | ||
14 | require_once 'application/feed/Cache.php'; | ||
15 | require_once 'application/Utils.php'; | 14 | require_once 'application/Utils.php'; |
16 | require_once 'tests/utils/ReferenceLinkDB.php'; | 15 | require_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 | */ |
5 | namespace Shaarli\Feed; | 5 | namespace Shaarli\Render; |
6 | |||
7 | use PHPUnit\Framework\TestCase; | ||
8 | use Shaarli\Security\SessionManager; | ||
6 | 9 | ||
7 | // required to access $_SESSION array | 10 | // required to access $_SESSION array |
8 | session_start(); | 11 | session_start(); |
9 | 12 | ||
10 | require_once 'application/feed/Cache.php'; | ||
11 | |||
12 | /** | 13 | /** |
13 | * Unitary tests for cached pages | 14 | * Unitary tests for cached pages |
14 | */ | 15 | */ |
15 | class CacheTest extends \PHPUnit\Framework\TestCase | 16 | class 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 | } |