mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding test case for cached view files, and fatal errors caused by the view instance not being registered. View instances are now registered when rendering view caches, and unregistered if the cached view fails. This fixes issues rendering flash messages with custom layouts and fixes FormHelper methods inside nocache blocks.
Fixes #60
This commit is contained in:
parent
c3bf6bc0e8
commit
47a9401d43
3 changed files with 71 additions and 2 deletions
|
@ -678,8 +678,12 @@ class Dispatcher extends Object {
|
|||
App::import('Core', 'View');
|
||||
}
|
||||
$controller = null;
|
||||
$view =& new View($controller, false);
|
||||
return $view->renderCache($filename, getMicrotime());
|
||||
$view =& new View($controller);
|
||||
$return = $view->renderCache($filename, getMicrotime());
|
||||
if (!$return) {
|
||||
ClassRegistry::removeObject('view');
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -448,6 +448,15 @@ class TestCachedPagesController extends AppController {
|
|||
function view($id = null) {
|
||||
$this->render('index');
|
||||
}
|
||||
/**
|
||||
* test cached forms / tests view object being registered
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function cache_form() {
|
||||
$this->cacheAction = 10;
|
||||
$this->helpers[] = 'Form';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* TimesheetsController class
|
||||
|
@ -1899,6 +1908,48 @@ class DispatcherTest extends CakeTestCase {
|
|||
$filename = $this->__cachePath($dispatcher->here);
|
||||
$this->assertTrue(file_exists($filename));
|
||||
unlink($filename);
|
||||
|
||||
$url = 'TestCachedPages/test_nocache_tags';
|
||||
}
|
||||
/**
|
||||
* test that cached() registers a view and un-registers it. Tests
|
||||
* that helpers using ClassRegistry::getObject('view'); don't fail
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testCachedRegisteringViewObject() {
|
||||
Configure::write('Cache.disable', false);
|
||||
Configure::write('Cache.check', true);
|
||||
Configure::write('debug', 2);
|
||||
|
||||
$_POST = array();
|
||||
$_SERVER['PHP_SELF'] = '/';
|
||||
|
||||
Router::reload();
|
||||
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
|
||||
|
||||
$dispatcher =& new Dispatcher();
|
||||
$dispatcher->base = false;
|
||||
|
||||
$url = 'test_cached_pages/cache_form';
|
||||
ob_start();
|
||||
$dispatcher->dispatch($url);
|
||||
$out = ob_get_clean();
|
||||
|
||||
ClassRegistry::flush();
|
||||
|
||||
ob_start();
|
||||
$dispatcher->cached($url);
|
||||
$cached = ob_get_clean();
|
||||
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
|
||||
$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
$filename = $this->__cachePath($dispatcher->here);
|
||||
unlink($filename);
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
/**
|
||||
* testHttpMethodOverrides method
|
||||
|
|
14
cake/tests/test_app/views/posts/cache_form.ctp
Normal file
14
cake/tests/test_app/views/posts/cache_form.ctp
Normal file
|
@ -0,0 +1,14 @@
|
|||
<div class="users form">
|
||||
<cake:nocache>
|
||||
<?php echo $form->create('User');?>
|
||||
<fieldset>
|
||||
<legend><?php __('Add User');?></legend>
|
||||
<?php
|
||||
echo $form->input('username');
|
||||
echo $form->input('email');
|
||||
echo $form->input('password');
|
||||
?>
|
||||
</fieldset>
|
||||
<?php echo $form->end('Submit');?>
|
||||
</cake:nocache>
|
||||
</div>
|
Loading…
Reference in a new issue