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 { 95f3da53eSChristopher Smith /** @var cache_renderer $cache */ 1016ca217dSMichael Hamann private $cache; 1116ca217dSMichael Hamann 1216ca217dSMichael Hamann function setUp() { 13b2356002SChristopher Smith global $ID, $conf; 1416ca217dSMichael Hamann parent::setUp(); 1516ca217dSMichael Hamann 1616ca217dSMichael Hamann $ID = 'cached'; 1716ca217dSMichael Hamann $file = wikiFN($ID); 18b2356002SChristopher Smith $conf['cachetime'] = 0; // ensure the value is not -1, which disables caching 1916ca217dSMichael Hamann 2016ca217dSMichael Hamann saveWikiText($ID, 'Content', 'Created'); 2116ca217dSMichael Hamann 22b2356002SChristopher Smith $this->cache = new cache_renderer($ID, $file, 'xhtml'); 2316ca217dSMichael Hamann $this->cache->storeCache('Test'); 24*9d60a747SChristopher Smith 25*9d60a747SChristopher Smith // set the modification times explicitly (overcome Issue #694) 26*9d60a747SChristopher Smith $time = time(); 27*9d60a747SChristopher Smith touch($file, $time-1); 28*9d60a747SChristopher Smith touch($this->cache->cache, $time); 2916ca217dSMichael Hamann } 3016ca217dSMichael Hamann 3116ca217dSMichael Hamann function test_use() { 3216ca217dSMichael Hamann $this->assertTrue($this->cache->useCache()); 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 * 39b2356002SChristopher Smith * @depends test_use 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 /** 51b2356002SChristopher Smith * @depends test_use 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 /** 60b2356002SChristopher Smith * @depends test_use 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 /** 74b2356002SChristopher Smith * @depends test_use 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}