From 16ca217de8ce72a9c736f35f1a62718437369d88 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Fri, 14 Mar 2014 13:08:32 +0100 Subject: Add a basic test case for the cache This very basic test ensures that the useCache method works as expected for simple scenarios. This test case fails without commit a8795974051a91137b01ff88dbf5586a647b24ce and then also triggers the warning that was introduced in bc2ddb548f71b1a822dd03c3bc7c3c0e7cd9b152 --- _test/tests/inc/cache_use.test.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 _test/tests/inc/cache_use.test.php (limited to '_test/tests/inc/cache_use.test.php') 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 @@ +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 -- cgit v1.2.3 From b23560022e3a99310a04296b3c385325e7abb747 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 16 Mar 2014 18:32:07 +0000 Subject: Fix longstanding issue with cache class & cachetime setting 1. cachetime setting should only be applied to the cache_renderer class. Previously it was applied to cache_parser (and by extension cache_handler). 2. two special cachetime values, -1 & 0, weren't handled, per FS#2183 To handle the cachetime setting, -1, disable caching, a new property _nocache is added. When that property is true, any cache file must not be used and storecache() should not store any values --- _test/tests/inc/cache_use.test.php | 56 ++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) (limited to '_test/tests/inc/cache_use.test.php') diff --git a/_test/tests/inc/cache_use.test.php b/_test/tests/inc/cache_use.test.php index f5349df13..292f5c975 100644 --- a/_test/tests/inc/cache_use.test.php +++ b/_test/tests/inc/cache_use.test.php @@ -6,22 +6,22 @@ * Tests if caching can actually be used */ class cache_use_test extends DokuWikiTest { - /** @var cache_renderer $cache */ + /** @var cache_parser $cache */ private $cache; function setUp() { - global $ID; + global $ID, $conf; parent::setUp(); $ID = 'cached'; $file = wikiFN($ID); + $conf['cachetime'] = 0; // ensure the value is not -1, which disables caching 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 = new cache_renderer($ID, $file, 'xhtml'); $this->cache->storeCache('Test'); } @@ -29,8 +29,52 @@ class cache_use_test extends DokuWikiTest { $this->assertTrue($this->cache->useCache()); } - + /** + * In all the following tests the cache should not be usable + * as such, they are meaningless if test_use didn't pass. + * + * @depends test_use + */ function test_purge() { - $this->assertFalse($this->cache->useCache(array('purge' => true))); + /* @var Input $INPUT */ + global $INPUT; + $INPUT->set('purge',1); + + $this->assertFalse($this->cache->useCache()); + $this->assertNotEmpty($this->cache->depends['purge']); + } + + /** + * @depends test_use + */ + function test_filedependency() { + // give the dependent src file the same mtime as the cache + touch($this->cache->file, filemtime($this->cache->cache)); + $this->assertFalse($this->cache->useCache()); + } + + /** + * @depends test_use + */ + function test_age() { + // need to age both our source file & the cache + $age = 10; + $time = time() - $age - 1; // older than age + + touch($this->cache->file, $time - 1); + touch($this->cache->cache, $time); + + $this->assertFalse($this->cache->useCache(array('age' => $age))); + } + + /** + * @depends test_use + */ + function test_confnocaching() { + global $conf; + $conf['cachetime'] = -1; // disables renderer caching + + $this->assertFalse($this->cache->useCache()); + $this->assertNotEmpty($this->cache->_nocache); } } \ No newline at end of file -- cgit v1.2.3 From 5f3da53e253bc878946671173feef853a48604b8 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 16 Mar 2014 19:43:40 +0000 Subject: put PHPDocs comment back the way it should be --- _test/tests/inc/cache_use.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test/tests/inc/cache_use.test.php') diff --git a/_test/tests/inc/cache_use.test.php b/_test/tests/inc/cache_use.test.php index 292f5c975..c54a472a3 100644 --- a/_test/tests/inc/cache_use.test.php +++ b/_test/tests/inc/cache_use.test.php @@ -6,7 +6,7 @@ * Tests if caching can actually be used */ class cache_use_test extends DokuWikiTest { - /** @var cache_parser $cache */ + /** @var cache_renderer $cache */ private $cache; function setUp() { -- cgit v1.2.3