summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/tests/inc/cache_use.test.php36
-rw-r--r--inc/cache.php8
2 files changed, 41 insertions, 3 deletions
diff --git a/_test/tests/inc/cache_use.test.php b/_test/tests/inc/cache_use.test.php
new file mode 100644
index 000000000..f5349df13
--- /dev/null
+++ b/_test/tests/inc/cache_use.test.php
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * Class cache_use_test
+ *
+ * Tests if caching can actually be used
+ */
+class cache_use_test extends DokuWikiTest {
+ /** @var cache_renderer $cache */
+ private $cache;
+
+ function setUp() {
+ global $ID;
+ parent::setUp();
+
+ $ID = 'cached';
+ $file = wikiFN($ID);
+
+ saveWikiText($ID, 'Content', 'Created');
+ // set the modification time a second in the past in order to ensure that the cache is newer than the page
+ touch($file, time()-1);
+
+ # Create cache. Note that the metadata cache is used as the xhtml cache triggers metadata rendering
+ $this->cache = new cache_renderer($ID, $file, 'metadata');
+ $this->cache->storeCache('Test');
+ }
+
+ function test_use() {
+ $this->assertTrue($this->cache->useCache());
+ }
+
+
+ function test_purge() {
+ $this->assertFalse($this->cache->useCache(array('purge' => true)));
+ }
+} \ No newline at end of file
diff --git a/inc/cache.php b/inc/cache.php
index 5f54a34a9..56c5b65f2 100644
--- a/inc/cache.php
+++ b/inc/cache.php
@@ -63,11 +63,13 @@ class cache {
* age - expire cache if older than age (seconds)
* files - expire cache if any file in this array was updated more recently than the cache
*
+ * Note that this function needs to be public as it is used as callback for the event handler
+ *
* can be overridden
*
* @return bool see useCache()
*/
- protected function _useCache() {
+ public function _useCache() {
if (!empty($this->depends['purge'])) return false; // purge requested?
if (!($this->_time = @filemtime($this->cache))) return false; // cache exists?
@@ -194,7 +196,7 @@ class cache_parser extends cache {
*
* @return bool see useCache()
*/
- protected function _useCache() {
+ public function _useCache() {
if (!@file_exists($this->file)) return false; // source exists?
return parent::_useCache();
@@ -229,7 +231,7 @@ class cache_renderer extends cache_parser {
*
* @return bool see useCache()
*/
- protected function _useCache() {
+ public function _useCache() {
global $conf;
if (!parent::_useCache()) return false;