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