From 91200dd0cd4c4724e5e185ac5326baeafeb1b63b Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 7 Oct 2012 22:22:22 -0400 Subject: [PATCH] Update CacheHelper tests There were a few CacheHelper tests depending on removed properties in Controller. Also update CacheHelper to not use deprecated properties on View as well. --- .../TestCase/View/Helper/CacheHelperTest.php | 49 +++++++++---------- lib/Cake/View/Helper/CacheHelper.php | 32 ++++++++---- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/lib/Cake/Test/TestCase/View/Helper/CacheHelperTest.php b/lib/Cake/Test/TestCase/View/Helper/CacheHelperTest.php index bf610928170..40f5c5203fb 100644 --- a/lib/Cake/Test/TestCase/View/Helper/CacheHelperTest.php +++ b/lib/Cake/Test/TestCase/View/Helper/CacheHelperTest.php @@ -1,9 +1,5 @@ * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * @@ -12,7 +8,6 @@ * * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @package Cake.Test.Case.View.Helper * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -31,7 +26,7 @@ /** * CacheTestController class * - * @package Cake.Test.Case.View.Helper + * @package Cake.Test.Case.View.Helper */ class CacheTestController extends Controller { @@ -72,7 +67,7 @@ class CacheHelperTest extends TestCase { */ public function skip() { if (!is_writable(TMP . 'cache/views/')) { - $this->markTestSkipped('TMP/views is not writable %s'); + $this->markTestSkipped('TMP/views is not writable.'); } } @@ -83,16 +78,16 @@ public function skip() { */ public function setUp() { parent::setUp(); - $_GET = array(); + $_GET = []; $request = new Request(); $this->Controller = new CacheTestController($request); $View = new View($this->Controller); $this->Cache = new CacheHelper($View); Configure::write('Cache.check', true); Configure::write('Cache.disable', false); - App::build(array( - 'View' => array(CAKE . 'Test/TestApp/View/') - ), App::RESET); + App::build([ + 'View' => [CAKE . 'Test/TestApp/View/'] + ], App::RESET); } /** @@ -514,14 +509,14 @@ public function testCacheBaseNameControllerName() { $this->Controller->cacheAction = array( 'cache_name' => 21600 ); - $this->Controller->params = array( + $request = $this->Controller->request; + $request->params = array( 'controller' => 'cacheTest', 'action' => 'cache_name', 'pass' => array(), ); - $this->Controller->here = '/cache/cacheTest/cache_name'; - $this->Controller->action = 'cache_name'; - $this->Controller->base = '/cache'; + $request->here = '/cache/cacheTest/cache_name'; + $request->base = '/cache'; $View = new View($this->Controller); $result = $View->render('index'); @@ -543,7 +538,7 @@ public function testAfterRenderConditions() { Configure::write('Cache.check', true); $View = new View($this->Controller); $View->cacheAction = '+1 day'; - $View->output = 'test'; + $View->assign('content', 'test'); $Cache = $this->getMock('Cake\View\Helper\CacheHelper', array('_parseContent'), array($View)); $Cache->expects($this->once()) @@ -570,12 +565,12 @@ public function testAfterLayoutConditions() { Configure::write('Cache.check', true); $View = new View($this->Controller); $View->cacheAction = '+1 day'; - $View->output = 'test'; + $View->set('content', 'test'); $Cache = $this->getMock('Cake\View\Helper\CacheHelper', array('cache'), array($View)); $Cache->expects($this->once()) ->method('cache') - ->with('posts/index', $View->output) + ->with('posts/index', $View->fetch('content')) ->will($this->returnValue('')); $Cache->afterLayout('posts/index'); @@ -596,22 +591,22 @@ public function testAfterLayoutConditions() { * @return void */ public function testCacheEmptySections() { + Configure::write('Cache.check', true); $this->Controller->cache_parsing(); - $this->Controller->params = array( + $this->Controller->request->addParams([ 'controller' => 'cacheTest', 'action' => 'cache_empty_sections', - 'pass' => array(), - ); - $this->Controller->cacheAction = array('cache_empty_sections' => 21600); - $this->Controller->here = '/cacheTest/cache_empty_sections'; - $this->Controller->action = 'cache_empty_sections'; + 'pass' => [], + ]); + $this->Controller->request->here = '/cacheTest/cache_empty_sections'; + $this->Controller->cacheAction = ['cache_empty_sections' => 21600]; $this->Controller->layout = 'cache_empty_sections'; $this->Controller->viewPath = 'Posts'; $View = new View($this->Controller); $result = $View->render('cache_empty_sections'); - $this->assertNotRegExp('/nocache/', $result); - $this->assertNotRegExp('/php echo/', $result); + $this->assertNotContains('nocache', $result); + $this->assertNotContains('assertRegExp( '@\s*\s*' . '\s*' . @@ -622,7 +617,7 @@ public function testCacheEmptySections() { $filename = CACHE . 'views/cachetest_cache_empty_sections.php'; $this->assertTrue(file_exists($filename)); $contents = file_get_contents($filename); - $this->assertNotRegExp('/nocache/', $contents); + $this->assertNotContains('nocache', $contents); $this->assertRegExp( '@\s*Posts\s*' . '<\?php \$x \= 1; \?>\s*' . diff --git a/lib/Cake/View/Helper/CacheHelper.php b/lib/Cake/View/Helper/CacheHelper.php index 303b90c111b..cfd51e332ef 100644 --- a/lib/Cake/View/Helper/CacheHelper.php +++ b/lib/Cake/View/Helper/CacheHelper.php @@ -1,9 +1,5 @@ _enabled()) { - $this->_View->output = $this->cache($layoutFile, $this->_View->output); + $this->_View->assign( + 'content', + $this->cache($layoutFile, $this->_View->fetch('content')) + ); } - $this->_View->output = preg_replace('//', '', $this->_View->output); + $this->_View->assign( + 'content', + preg_replace('//', '', $this->_View->fetch('content')) + ); } /** @@ -181,8 +183,18 @@ protected function _parseFile($file, $cache) { } elseif ($file = fileExistsInPath($file)) { $file = file_get_contents($file); } - preg_match_all('/((?<=)[\\s\\S]*?(?=))/i', $cache, $outputResult, PREG_PATTERN_ORDER); - preg_match_all('/(?<=)([\\s\\S]*?)(?=)/i', $file, $fileResult, PREG_PATTERN_ORDER); + preg_match_all( + '/((?<=)[\\s\\S]*?(?=))/i', + $cache, + $outputResult, + PREG_PATTERN_ORDER + ); + preg_match_all( + '/(?<=)([\\s\\S]*?)(?=)/i', + $file, + $fileResult, + PREG_PATTERN_ORDER + ); $fileResult = $fileResult[0]; $outputResult = $outputResult[0];