116ca217dSMichael Hamann<?php 216ca217dSMichael Hamann 316ca217dSMichael Hamann/** 416ca217dSMichael Hamann * Class cache_use_test 516ca217dSMichael Hamann * 616ca217dSMichael Hamann * Tests if caching can actually be used 7*bd8c2ebfSAndreas Gohr * 8*bd8c2ebfSAndreas Gohr * @todo tests marked as flaky until Ticket #694 has been fixed 916ca217dSMichael Hamann */ 1016ca217dSMichael Hamannclass cache_use_test extends DokuWikiTest { 115f3da53eSChristopher Smith /** @var cache_renderer $cache */ 1216ca217dSMichael Hamann private $cache; 1316ca217dSMichael Hamann 1416ca217dSMichael Hamann function setUp() { 15b2356002SChristopher Smith global $ID, $conf; 1616ca217dSMichael Hamann parent::setUp(); 1716ca217dSMichael Hamann 1816ca217dSMichael Hamann $ID = 'cached'; 1916ca217dSMichael Hamann $file = wikiFN($ID); 20b2356002SChristopher Smith $conf['cachetime'] = 0; // ensure the value is not -1, which disables caching 2116ca217dSMichael Hamann 2216ca217dSMichael Hamann saveWikiText($ID, 'Content', 'Created'); 2316ca217dSMichael Hamann 24b2356002SChristopher Smith $this->cache = new cache_renderer($ID, $file, 'xhtml'); 2516ca217dSMichael Hamann $this->cache->storeCache('Test'); 269d60a747SChristopher Smith 279d60a747SChristopher Smith // set the modification times explicitly (overcome Issue #694) 289d60a747SChristopher Smith $time = time(); 299d60a747SChristopher Smith touch($file, $time-1); 309d60a747SChristopher Smith touch($this->cache->cache, $time); 3116ca217dSMichael Hamann } 3216ca217dSMichael Hamann 33b2356002SChristopher Smith /** 34b2356002SChristopher Smith * In all the following tests the cache should not be usable 35b2356002SChristopher Smith * as such, they are meaningless if test_use didn't pass. 36b2356002SChristopher Smith * 37*bd8c2ebfSAndreas Gohr * @group flaky 38b2356002SChristopher Smith */ 3916ca217dSMichael Hamann function test_purge() { 40b2356002SChristopher Smith /* @var Input $INPUT */ 41b2356002SChristopher Smith global $INPUT; 42b2356002SChristopher Smith $INPUT->set('purge',1); 43b2356002SChristopher Smith 44b2356002SChristopher Smith $this->assertFalse($this->cache->useCache()); 45b2356002SChristopher Smith $this->assertNotEmpty($this->cache->depends['purge']); 46b2356002SChristopher Smith } 47b2356002SChristopher Smith 48b2356002SChristopher Smith /** 49*bd8c2ebfSAndreas Gohr * @group flaky 50b2356002SChristopher Smith */ 51b2356002SChristopher Smith function test_filedependency() { 52b2356002SChristopher Smith // give the dependent src file the same mtime as the cache 53b2356002SChristopher Smith touch($this->cache->file, filemtime($this->cache->cache)); 54b2356002SChristopher Smith $this->assertFalse($this->cache->useCache()); 55b2356002SChristopher Smith } 56b2356002SChristopher Smith 57b2356002SChristopher Smith /** 58*bd8c2ebfSAndreas Gohr * @group flaky 59b2356002SChristopher Smith */ 60b2356002SChristopher Smith function test_age() { 61b2356002SChristopher Smith // need to age both our source file & the cache 62b2356002SChristopher Smith $age = 10; 63b2356002SChristopher Smith $time = time() - $age - 1; // older than age 64b2356002SChristopher Smith 65b2356002SChristopher Smith touch($this->cache->file, $time - 1); 66b2356002SChristopher Smith touch($this->cache->cache, $time); 67b2356002SChristopher Smith 68b2356002SChristopher Smith $this->assertFalse($this->cache->useCache(array('age' => $age))); 69b2356002SChristopher Smith } 70b2356002SChristopher Smith 71b2356002SChristopher Smith /** 72*bd8c2ebfSAndreas Gohr * @group flaky 73b2356002SChristopher Smith */ 74b2356002SChristopher Smith function test_confnocaching() { 75b2356002SChristopher Smith global $conf; 76b2356002SChristopher Smith $conf['cachetime'] = -1; // disables renderer caching 77b2356002SChristopher Smith 78b2356002SChristopher Smith $this->assertFalse($this->cache->useCache()); 79b2356002SChristopher Smith $this->assertNotEmpty($this->cache->_nocache); 8016ca217dSMichael Hamann } 8116ca217dSMichael Hamann} 82