xref: /dokuwiki/_test/tests/inc/cache_use.test.php (revision b23560022e3a99310a04296b3c385325e7abb747)
116ca217dSMichael Hamann<?php
216ca217dSMichael Hamann
316ca217dSMichael Hamann/**
416ca217dSMichael Hamann * Class cache_use_test
516ca217dSMichael Hamann *
616ca217dSMichael Hamann * Tests if caching can actually be used
716ca217dSMichael Hamann */
816ca217dSMichael Hamannclass cache_use_test extends DokuWikiTest {
9*b2356002SChristopher Smith    /** @var cache_parser $cache */
1016ca217dSMichael Hamann    private $cache;
1116ca217dSMichael Hamann
1216ca217dSMichael Hamann    function setUp() {
13*b2356002SChristopher Smith        global $ID, $conf;
1416ca217dSMichael Hamann        parent::setUp();
1516ca217dSMichael Hamann
1616ca217dSMichael Hamann        $ID = 'cached';
1716ca217dSMichael Hamann        $file = wikiFN($ID);
18*b2356002SChristopher Smith        $conf['cachetime'] = 0;  // ensure the value is not -1, which disables caching
1916ca217dSMichael Hamann
2016ca217dSMichael Hamann        saveWikiText($ID, 'Content', 'Created');
2116ca217dSMichael Hamann        // set the modification time a second in the past in order to ensure that the cache is newer than the page
2216ca217dSMichael Hamann        touch($file, time()-1);
2316ca217dSMichael Hamann
24*b2356002SChristopher Smith        $this->cache = new cache_renderer($ID, $file, 'xhtml');
2516ca217dSMichael Hamann        $this->cache->storeCache('Test');
2616ca217dSMichael Hamann    }
2716ca217dSMichael Hamann
2816ca217dSMichael Hamann    function test_use() {
2916ca217dSMichael Hamann        $this->assertTrue($this->cache->useCache());
3016ca217dSMichael Hamann    }
3116ca217dSMichael Hamann
32*b2356002SChristopher Smith    /**
33*b2356002SChristopher Smith     * In all the following tests the cache should not be usable
34*b2356002SChristopher Smith     * as such, they are meaningless if test_use didn't pass.
35*b2356002SChristopher Smith     *
36*b2356002SChristopher Smith     * @depends test_use
37*b2356002SChristopher Smith     */
3816ca217dSMichael Hamann    function test_purge() {
39*b2356002SChristopher Smith        /* @var Input $INPUT */
40*b2356002SChristopher Smith        global $INPUT;
41*b2356002SChristopher Smith        $INPUT->set('purge',1);
42*b2356002SChristopher Smith
43*b2356002SChristopher Smith        $this->assertFalse($this->cache->useCache());
44*b2356002SChristopher Smith        $this->assertNotEmpty($this->cache->depends['purge']);
45*b2356002SChristopher Smith    }
46*b2356002SChristopher Smith
47*b2356002SChristopher Smith    /**
48*b2356002SChristopher Smith     * @depends test_use
49*b2356002SChristopher Smith     */
50*b2356002SChristopher Smith    function test_filedependency() {
51*b2356002SChristopher Smith        // give the dependent src file the same mtime as the cache
52*b2356002SChristopher Smith        touch($this->cache->file, filemtime($this->cache->cache));
53*b2356002SChristopher Smith        $this->assertFalse($this->cache->useCache());
54*b2356002SChristopher Smith    }
55*b2356002SChristopher Smith
56*b2356002SChristopher Smith    /**
57*b2356002SChristopher Smith     * @depends test_use
58*b2356002SChristopher Smith     */
59*b2356002SChristopher Smith    function test_age() {
60*b2356002SChristopher Smith        // need to age both our source file & the cache
61*b2356002SChristopher Smith        $age = 10;
62*b2356002SChristopher Smith        $time = time() - $age - 1;  // older than age
63*b2356002SChristopher Smith
64*b2356002SChristopher Smith        touch($this->cache->file, $time - 1);
65*b2356002SChristopher Smith        touch($this->cache->cache, $time);
66*b2356002SChristopher Smith
67*b2356002SChristopher Smith        $this->assertFalse($this->cache->useCache(array('age' => $age)));
68*b2356002SChristopher Smith    }
69*b2356002SChristopher Smith
70*b2356002SChristopher Smith    /**
71*b2356002SChristopher Smith     * @depends test_use
72*b2356002SChristopher Smith     */
73*b2356002SChristopher Smith    function test_confnocaching() {
74*b2356002SChristopher Smith        global $conf;
75*b2356002SChristopher Smith        $conf['cachetime'] = -1;   // disables renderer caching
76*b2356002SChristopher Smith
77*b2356002SChristopher Smith        $this->assertFalse($this->cache->useCache());
78*b2356002SChristopher Smith        $this->assertNotEmpty($this->cache->_nocache);
7916ca217dSMichael Hamann    }
8016ca217dSMichael Hamann}