xref: /dokuwiki/_test/tests/inc/cache_use.test.php (revision db9faf025cf129d15a086a803e8056e977975d76)
1<?php
2
3/**
4 * Class cache_use_test
5 *
6 * Tests if caching can actually be used
7 *
8 * @todo tests marked as flaky until Ticket #694 has been fixed
9 */
10class cache_use_test extends DokuWikiTest {
11    /** @var cache_renderer $cache */
12    private $cache;
13
14    function setUp() {
15        global $ID, $conf;
16        parent::setUp();
17
18        $ID = 'cached';
19        $file = wikiFN($ID);
20        $conf['cachetime'] = 0;  // ensure the value is not -1, which disables caching
21
22        saveWikiText($ID, 'Content', 'Created');
23
24        $this->cache = new cache_renderer($ID, $file, 'xhtml');
25        $this->cache->storeCache('Test');
26
27        // set the modification times explicitly (overcome Issue #694)
28        $time = time();
29        touch($file, $time-1);
30        touch($this->cache->cache, $time);
31    }
32
33    /**
34     * In all the following tests the cache should not be usable
35     * as such, they are meaningless if test_use didn't pass.
36     *
37     * @group flaky
38     */
39    function test_purge() {
40        /* @var Input $INPUT */
41        global $INPUT;
42        $INPUT->set('purge',1);
43
44        $this->assertFalse($this->cache->useCache());
45        $this->assertNotEmpty($this->cache->depends['purge']);
46    }
47
48    /**
49     * @group flaky
50     */
51    function test_filedependency() {
52        // give the dependent src file the same mtime as the cache
53        touch($this->cache->file, filemtime($this->cache->cache));
54        $this->assertFalse($this->cache->useCache());
55    }
56
57    /**
58     * @group flaky
59     */
60    function test_age() {
61        // need to age both our source file & the cache
62        $age = 10;
63        $time = time() - $age - 1;  // older than age
64
65        touch($this->cache->file, $time - 1);
66        touch($this->cache->cache, $time);
67
68        $this->assertFalse($this->cache->useCache(array('age' => $age)));
69    }
70
71    /**
72     * @group flaky
73     */
74    function test_confnocaching() {
75        global $conf;
76        $conf['cachetime'] = -1;   // disables renderer caching
77
78        $this->assertFalse($this->cache->useCache());
79        $this->assertNotEmpty($this->cache->_nocache);
80    }
81}
82