aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/feed
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/feed
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/feed')
-rw-r--r--tests/feed/CacheTest.php92
1 files changed, 0 insertions, 92 deletions
diff --git a/tests/feed/CacheTest.php b/tests/feed/CacheTest.php
deleted file mode 100644
index c0a9f26f..00000000
--- a/tests/feed/CacheTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
1<?php
2/**
3 * Cache tests
4 */
5namespace Shaarli\Feed;
6
7// required to access $_SESSION array
8session_start();
9
10require_once 'application/feed/Cache.php';
11
12/**
13 * Unitary tests for cached pages
14 */
15class CacheTest extends \PHPUnit\Framework\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
24 /**
25 * Populate the cache with dummy files
26 */
27 public function setUp()
28 {
29 if (!is_dir(self::$testCacheDir)) {
30 mkdir(self::$testCacheDir);
31 } else {
32 array_map('unlink', glob(self::$testCacheDir . '/*'));
33 }
34
35 foreach (self::$pages as $page) {
36 file_put_contents(self::$testCacheDir . '/' . $page . '.cache', $page);
37 }
38 file_put_contents(self::$testCacheDir . '/intru.der', 'ShouldNotBeThere');
39 }
40
41 /**
42 * Remove dummycache folder after each tests.
43 */
44 public function tearDown()
45 {
46 array_map('unlink', glob(self::$testCacheDir . '/*'));
47 rmdir(self::$testCacheDir);
48 }
49
50 /**
51 * Purge cached pages
52 */
53 public function testPurgeCachedPages()
54 {
55 purgeCachedPages(self::$testCacheDir);
56 foreach (self::$pages as $page) {
57 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
58 }
59
60 $this->assertFileExists(self::$testCacheDir . '/intru.der');
61 }
62
63 /**
64 * Purge cached pages - missing directory
65 */
66 public function testPurgeCachedPagesMissingDir()
67 {
68 $oldlog = ini_get('error_log');
69 ini_set('error_log', '/dev/null');
70 $this->assertEquals(
71 'Cannot purge sandbox/dummycache_missing: no directory',
72 purgeCachedPages(self::$testCacheDir . '_missing')
73 );
74 ini_set('error_log', $oldlog);
75 }
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}