diff --git a/src/Template.php b/src/Template.php index a81a81f8..1e0122a2 100644 --- a/src/Template.php +++ b/src/Template.php @@ -420,7 +420,7 @@ class Template extends TemplateBase { * @throws Exception */ public function getCachedContent() { - return $this->getCachedContent($this); + return $this->getCached()->handler->getCachedContent($this); } /** @@ -739,7 +739,7 @@ class Template extends TemplateBase { $savedTplVars = $this->tpl_vars; $savedConfigVars = $this->config_vars; - // Start output-buffering. @TODO keep all ob_* calls together + // Start output-buffering. ob_start(); $result = $this->render(false, $function); diff --git a/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php b/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php index 3b1ebaa1..98dc7308 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php +++ b/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php @@ -91,7 +91,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar'); $tpl->writeCachedContent('hello world'); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent()); // Custom CacheResources may return -1 if they can't tell the number of deleted elements //$this->assertEquals(-1, $this->smarty->clearAllCache()); } @@ -112,15 +112,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world 3'); // test cached content - $this->assertEquals('hello world 1', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world 2', $tpl2->getCachedContent($tpl2)); - $this->assertEquals('hello world 3', $tpl3->getCachedContent($tpl3)); + $this->assertEquals('hello world 1', $tpl->getCachedContent()); + $this->assertEquals('hello world 2', $tpl2->getCachedContent()); + $this->assertEquals('hello world 3', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, 'foo|bar')); // test that caches are deleted properly - $this->assertNull($tpl->getCachedContent($tpl)); - $this->assertEquals('hello world 2', $tpl->getCachedContent($tpl2)); - $this->assertNull($tpl->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent()); + $this->assertEquals('hello world 2', $tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId2() @@ -136,15 +136,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->getCachedContent($tpl)); - $this->assertNull($tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId2Sub() @@ -160,15 +160,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->getCachedContent($tpl)); - $this->assertNull($tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId3() @@ -184,15 +184,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertNull($tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId3Sub() @@ -208,15 +208,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertNull($tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId4() @@ -232,15 +232,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertNull($tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId4Sub() @@ -256,15 +256,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertNull($tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId5() @@ -280,15 +280,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar')); // test that caches are deleted properly - $this->assertNull($tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertNull($tpl->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId5Sub() @@ -304,15 +304,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar')); // test that caches are deleted properly - $this->assertNull($tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertNull($tpl->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); } public function testClearCacheCacheFile() @@ -330,17 +330,17 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl4)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); + $this->assertEquals('hello world', $tpl4->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->getCachedContent($tpl)); - $this->assertNull($tpl->getCachedContent($tpl2)); - $this->assertNull($tpl->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl4)); + $this->assertNull($tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); + $this->assertEquals('hello world', $tpl4->getCachedContent()); } /** @@ -359,19 +359,19 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); sleep(10); $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4->writeCachedContent('hello world'); // test number of deleted caches $this->doClearCacheAssertion(3,$this->smarty->clearAllCache(5)); // test that caches are deleted properly - $this->assertNull($tpl->getCachedContent($tpl)); - $this->assertNull($tpl->getCachedContent($tpl2)); - $this->assertNull($tpl->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl4)); + $this->assertNull($tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); + $this->assertEquals('hello world', $tpl4->getCachedContent()); } public function testClearCacheCacheFileSub() @@ -389,17 +389,17 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl4)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); + $this->assertEquals('hello world', $tpl4->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->getCachedContent($tpl)); - $this->assertNull($tpl->getCachedContent($tpl2)); - $this->assertNull($tpl->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->getCachedContent($tpl4)); + $this->assertNull($tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); + $this->assertEquals('hello world', $tpl4->getCachedContent()); } /** * Test caching