summaryrefslogtreecommitdiff
path: root/_test/tests/inc/cache_use.test.php
blob: c0c12580a2a240a33e4ba083f5df8fd5dcb00a67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php

/**
 * Class cache_use_test
 *
 * Tests if caching can actually be used
 *
 * @todo tests marked as flaky until Ticket #694 has been fixed
 */
class cache_use_test extends DokuWikiTest {
    /** @var cache_renderer $cache */
    private $cache;

    function setUp() {
        global $ID, $conf;
        parent::setUp();

        $ID = 'cached';
        $file = wikiFN($ID);
        $conf['cachetime'] = 0;  // ensure the value is not -1, which disables caching

        saveWikiText($ID, 'Content', 'Created');

        $this->cache = new cache_renderer($ID, $file, 'xhtml');
        $this->cache->storeCache('Test');

        // set the modification times explicitly (overcome Issue #694)
        $time = time();
        touch($file, $time-1);
        touch($this->cache->cache, $time);
    }

    /**
     * In all the following tests the cache should not be usable
     * as such, they are meaningless if test_use didn't pass.
     *
     * @group flaky
     */
    function test_purge() {
        /* @var Input $INPUT */
        global $INPUT;
        $INPUT->set('purge',1);

        $this->assertFalse($this->cache->useCache());
        $this->assertNotEmpty($this->cache->depends['purge']);
    }

    /**
     * @group flaky
     */
    function test_filedependency() {
        // give the dependent src file the same mtime as the cache
        touch($this->cache->file, filemtime($this->cache->cache));
        $this->assertFalse($this->cache->useCache());
    }

    /**
     * @group flaky
     */
    function test_age() {
        // need to age both our source file & the cache
        $age = 10;
        $time = time() - $age - 1;  // older than age

        touch($this->cache->file, $time - 1);
        touch($this->cache->cache, $time);

        $this->assertFalse($this->cache->useCache(array('age' => $age)));
    }

    /**
     * @group flaky
     */
    function test_confnocaching() {
        global $conf;
        $conf['cachetime'] = -1;   // disables renderer caching

        $this->assertFalse($this->cache->useCache());
        $this->assertNotEmpty($this->cache->_nocache);
    }
}