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 22 $this->cache = new cache_renderer($ID, $file, 'xhtml'); 23 $this->cache->storeCache('Test'); 24 25 // set the modification times explicitly (overcome Issue #694) 26 $time = time(); 27 touch($file, $time-1); 28 touch($this->cache->cache, $time); 29 } 30 31 function test_use() { 32 $this->assertTrue($this->cache->useCache()); 33 } 34 35 /** 36 * In all the following tests the cache should not be usable 37 * as such, they are meaningless if test_use didn't pass. 38 * 39 * @depends test_use 40 */ 41 function test_purge() { 42 /* @var Input $INPUT */ 43 global $INPUT; 44 $INPUT->set('purge',1); 45 46 $this->assertFalse($this->cache->useCache()); 47 $this->assertNotEmpty($this->cache->depends['purge']); 48 } 49 50 /** 51 * @depends test_use 52 */ 53 function test_filedependency() { 54 // give the dependent src file the same mtime as the cache 55 touch($this->cache->file, filemtime($this->cache->cache)); 56 $this->assertFalse($this->cache->useCache()); 57 } 58 59 /** 60 * @depends test_use 61 */ 62 function test_age() { 63 // need to age both our source file & the cache 64 $age = 10; 65 $time = time() - $age - 1; // older than age 66 67 touch($this->cache->file, $time - 1); 68 touch($this->cache->cache, $time); 69 70 $this->assertFalse($this->cache->useCache(array('age' => $age))); 71 } 72 73 /** 74 * @depends test_use 75 */ 76 function test_confnocaching() { 77 global $conf; 78 $conf['cachetime'] = -1; // disables renderer caching 79 80 $this->assertFalse($this->cache->useCache()); 81 $this->assertNotEmpty($this->cache->_nocache); 82 } 83}