1<?php 2 3/** 4 * Class cache_use_test 5 * 6 * Tests if caching can actually be used 7 */ 8class cache_use_test extends DokuWikiTest { 9 /** @var cache_renderer $cache */ 10 private $cache; 11 12 function setUp() { 13 global $ID, $conf; 14 parent::setUp(); 15 16 $ID = 'cached'; 17 $file = wikiFN($ID); 18 $conf['cachetime'] = 0; // ensure the value is not -1, which disables caching 19 20 saveWikiText($ID, 'Content', 'Created'); 21 // set the modification time a second in the past in order to ensure that the cache is newer than the page 22 touch($file, time()-1); 23 24 $this->cache = new cache_renderer($ID, $file, 'xhtml'); 25 $this->cache->storeCache('Test'); 26 } 27 28 function test_use() { 29 $this->assertTrue($this->cache->useCache()); 30 } 31 32 /** 33 * In all the following tests the cache should not be usable 34 * as such, they are meaningless if test_use didn't pass. 35 * 36 * @depends test_use 37 */ 38 function test_purge() { 39 /* @var Input $INPUT */ 40 global $INPUT; 41 $INPUT->set('purge',1); 42 43 $this->assertFalse($this->cache->useCache()); 44 $this->assertNotEmpty($this->cache->depends['purge']); 45 } 46 47 /** 48 * @depends test_use 49 */ 50 function test_filedependency() { 51 // give the dependent src file the same mtime as the cache 52 touch($this->cache->file, filemtime($this->cache->cache)); 53 $this->assertFalse($this->cache->useCache()); 54 } 55 56 /** 57 * @depends test_use 58 */ 59 function test_age() { 60 // need to age both our source file & the cache 61 $age = 10; 62 $time = time() - $age - 1; // older than age 63 64 touch($this->cache->file, $time - 1); 65 touch($this->cache->cache, $time); 66 67 $this->assertFalse($this->cache->useCache(array('age' => $age))); 68 } 69 70 /** 71 * @depends test_use 72 */ 73 function test_confnocaching() { 74 global $conf; 75 $conf['cachetime'] = -1; // disables renderer caching 76 77 $this->assertFalse($this->cache->useCache()); 78 $this->assertNotEmpty($this->cache->_nocache); 79 } 80}