xref: /dokuwiki/_test/tests/inc/cache_use.test.php (revision 0db5771e6b5f779df34a039ad49d4652eaf21893)
116ca217dSMichael Hamann<?php
216ca217dSMichael Hamann
3*0db5771eSMichael Großeuse dokuwiki\Cache\CacheRenderer;
4*0db5771eSMichael Große
516ca217dSMichael Hamann/**
616ca217dSMichael Hamann * Class cache_use_test
716ca217dSMichael Hamann *
816ca217dSMichael Hamann * Tests if caching can actually be used
9bd8c2ebfSAndreas Gohr *
10bd8c2ebfSAndreas Gohr * @todo tests marked as flaky until Ticket #694 has been fixed
1116ca217dSMichael Hamann */
1216ca217dSMichael Hamannclass cache_use_test extends DokuWikiTest {
13*0db5771eSMichael Große    /** @var CacheRenderer $cache */
1416ca217dSMichael Hamann    private $cache;
1516ca217dSMichael Hamann
1616ca217dSMichael Hamann    function setUp() {
17b2356002SChristopher Smith        global $ID, $conf;
1816ca217dSMichael Hamann        parent::setUp();
1916ca217dSMichael Hamann
2016ca217dSMichael Hamann        $ID = 'cached';
2116ca217dSMichael Hamann        $file = wikiFN($ID);
22b2356002SChristopher Smith        $conf['cachetime'] = 0;  // ensure the value is not -1, which disables caching
2316ca217dSMichael Hamann
2416ca217dSMichael Hamann        saveWikiText($ID, 'Content', 'Created');
2516ca217dSMichael Hamann
26*0db5771eSMichael Große        $this->cache = new CacheRenderer($ID, $file, 'xhtml');
2716ca217dSMichael Hamann        $this->cache->storeCache('Test');
289d60a747SChristopher Smith
299d60a747SChristopher Smith        // set the modification times explicitly (overcome Issue #694)
309d60a747SChristopher Smith        $time = time();
319d60a747SChristopher Smith        touch($file, $time-1);
329d60a747SChristopher Smith        touch($this->cache->cache, $time);
3316ca217dSMichael Hamann    }
3416ca217dSMichael Hamann
35b2356002SChristopher Smith    /**
36b2356002SChristopher Smith     * In all the following tests the cache should not be usable
37b2356002SChristopher Smith     * as such, they are meaningless if test_use didn't pass.
38b2356002SChristopher Smith     *
39bd8c2ebfSAndreas Gohr     * @group flaky
40b2356002SChristopher Smith     */
4116ca217dSMichael Hamann    function test_purge() {
42b2356002SChristopher Smith        /* @var Input $INPUT */
43b2356002SChristopher Smith        global $INPUT;
44b2356002SChristopher Smith        $INPUT->set('purge',1);
45b2356002SChristopher Smith
46b2356002SChristopher Smith        $this->assertFalse($this->cache->useCache());
47b2356002SChristopher Smith        $this->assertNotEmpty($this->cache->depends['purge']);
48b2356002SChristopher Smith    }
49b2356002SChristopher Smith
50b2356002SChristopher Smith    /**
51bd8c2ebfSAndreas Gohr     * @group flaky
52b2356002SChristopher Smith     */
53b2356002SChristopher Smith    function test_filedependency() {
54b2356002SChristopher Smith        // give the dependent src file the same mtime as the cache
55b2356002SChristopher Smith        touch($this->cache->file, filemtime($this->cache->cache));
56b2356002SChristopher Smith        $this->assertFalse($this->cache->useCache());
57b2356002SChristopher Smith    }
58b2356002SChristopher Smith
59b2356002SChristopher Smith    /**
60bd8c2ebfSAndreas Gohr     * @group flaky
61b2356002SChristopher Smith     */
62b2356002SChristopher Smith    function test_age() {
63b2356002SChristopher Smith        // need to age both our source file & the cache
64b2356002SChristopher Smith        $age = 10;
65b2356002SChristopher Smith        $time = time() - $age - 1;  // older than age
66b2356002SChristopher Smith
67b2356002SChristopher Smith        touch($this->cache->file, $time - 1);
68b2356002SChristopher Smith        touch($this->cache->cache, $time);
69b2356002SChristopher Smith
70b2356002SChristopher Smith        $this->assertFalse($this->cache->useCache(array('age' => $age)));
71b2356002SChristopher Smith    }
72b2356002SChristopher Smith
73b2356002SChristopher Smith    /**
74bd8c2ebfSAndreas Gohr     * @group flaky
75b2356002SChristopher Smith     */
76b2356002SChristopher Smith    function test_confnocaching() {
77b2356002SChristopher Smith        global $conf;
78b2356002SChristopher Smith        $conf['cachetime'] = -1;   // disables renderer caching
79b2356002SChristopher Smith
80b2356002SChristopher Smith        $this->assertFalse($this->cache->useCache());
81b2356002SChristopher Smith        $this->assertNotEmpty($this->cache->_nocache);
8216ca217dSMichael Hamann    }
8316ca217dSMichael Hamann}
84