mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fix a few outstanding issues with blocks.
- Blocks left open after rendering files should trigger an exception. - Fix strict errors. - Correct doc blocks.
This commit is contained in:
parent
bcb8444ab1
commit
f0f3eb9ba9
5 changed files with 40 additions and 7 deletions
|
@ -580,7 +580,7 @@ class ViewTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testHelperCallbackTriggering() {
|
public function testHelperCallbackTriggering() {
|
||||||
$View = new View($this->PostsController);
|
$View = new View($this->PostsController);
|
||||||
$View->helpers = array('Html', 'Session');
|
$View->helpers = array();
|
||||||
$View->Helpers = $this->getMock('HelperCollection', array('trigger'), array($View));
|
$View->Helpers = $this->getMock('HelperCollection', array('trigger'), array($View));
|
||||||
|
|
||||||
$View->Helpers->expects($this->at(0))->method('trigger')
|
$View->Helpers->expects($this->at(0))->method('trigger')
|
||||||
|
@ -588,7 +588,8 @@ class ViewTest extends CakeTestCase {
|
||||||
$View->Helpers->expects($this->at(1))->method('trigger')
|
$View->Helpers->expects($this->at(1))->method('trigger')
|
||||||
->with('beforeRenderFile', $this->anything());
|
->with('beforeRenderFile', $this->anything());
|
||||||
$View->Helpers->expects($this->at(2))->method('trigger')
|
$View->Helpers->expects($this->at(2))->method('trigger')
|
||||||
->with('afterRenderFile', $this->anything());
|
->with('afterRenderFile', $this->anything())
|
||||||
|
->will($this->returnValue(''));
|
||||||
$View->Helpers->expects($this->at(3))->method('trigger')
|
$View->Helpers->expects($this->at(3))->method('trigger')
|
||||||
->with('afterRender', $this->anything());
|
->with('afterRender', $this->anything());
|
||||||
|
|
||||||
|
@ -597,7 +598,8 @@ class ViewTest extends CakeTestCase {
|
||||||
$View->Helpers->expects($this->at(5))->method('trigger')
|
$View->Helpers->expects($this->at(5))->method('trigger')
|
||||||
->with('beforeRenderFile', $this->anything());
|
->with('beforeRenderFile', $this->anything());
|
||||||
$View->Helpers->expects($this->at(6))->method('trigger')
|
$View->Helpers->expects($this->at(6))->method('trigger')
|
||||||
->with('afterRenderFile', $this->anything());
|
->with('afterRenderFile', $this->anything())
|
||||||
|
->will($this->returnValue('')) ;
|
||||||
$View->Helpers->expects($this->at(7))->method('trigger')
|
$View->Helpers->expects($this->at(7))->method('trigger')
|
||||||
->with('afterLayout', $this->anything());
|
->with('afterLayout', $this->anything());
|
||||||
|
|
||||||
|
@ -1034,6 +1036,17 @@ class ViewTest extends CakeTestCase {
|
||||||
$this->assertEquals(array('test', 'test1'), $this->View->blocks());
|
$this->assertEquals(array('test', 'test1'), $this->View->blocks());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that an exception gets thrown when you leave a block open at the end
|
||||||
|
* of a view.
|
||||||
|
*
|
||||||
|
* @expectedException CakeException
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExceptionOnOpenBlock() {
|
||||||
|
$this->View->render('open_block');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test nested extended views.
|
* Test nested extended views.
|
||||||
*
|
*
|
||||||
|
|
3
lib/Cake/Test/test_app/View/Posts/open_block.ctp
Normal file
3
lib/Cake/Test/test_app/View/Posts/open_block.ctp
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
$this->start('no_close');
|
||||||
|
echo 'This block has no close :(';
|
|
@ -754,7 +754,8 @@ class Helper extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before render file callback. Called before any view fragment is rendered.
|
* Before render file callback.
|
||||||
|
* Called before any view fragment is rendered.
|
||||||
*
|
*
|
||||||
* Overridden in subclasses.
|
* Overridden in subclasses.
|
||||||
*
|
*
|
||||||
|
@ -765,14 +766,16 @@ class Helper extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After render file callback. Called before any view fragment is rendered.
|
* After render file callback.
|
||||||
|
* Called after any view fragment is rendered.
|
||||||
*
|
*
|
||||||
* Overridden in subclasses.
|
* Overridden in subclasses.
|
||||||
*
|
*
|
||||||
* @param string $viewFile The file about to be rendered.
|
* @param string $viewFile The file just be rendered.
|
||||||
|
* @param string $content The content that was rendered.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function afterRenderFile($viewfile) {
|
public function afterRenderFile($viewfile, $content) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,6 +43,7 @@ App::uses('ViewBlock', 'View');
|
||||||
* @property SessionHelper $Session
|
* @property SessionHelper $Session
|
||||||
* @property TextHelper $Text
|
* @property TextHelper $Text
|
||||||
* @property TimeHelper $Time
|
* @property TimeHelper $Time
|
||||||
|
* @property ViewBlock $Blocks
|
||||||
*/
|
*/
|
||||||
class View extends Object {
|
class View extends Object {
|
||||||
|
|
||||||
|
@ -755,6 +756,7 @@ class View extends Object {
|
||||||
* @param string $viewFile Filename of the view
|
* @param string $viewFile Filename of the view
|
||||||
* @param array $data Data to include in rendered view. If empty the current View::$viewVars will be used.
|
* @param array $data Data to include in rendered view. If empty the current View::$viewVars will be used.
|
||||||
* @return string Rendered output
|
* @return string Rendered output
|
||||||
|
* @throws CakeException when a block is left open.
|
||||||
*/
|
*/
|
||||||
protected function _render($viewFile, $data = array()) {
|
protected function _render($viewFile, $data = array()) {
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
|
@ -764,6 +766,9 @@ class View extends Object {
|
||||||
|
|
||||||
$this->Helpers->trigger('beforeRenderFile', array($viewFile));
|
$this->Helpers->trigger('beforeRenderFile', array($viewFile));
|
||||||
$content = $this->_evaluate($viewFile, $data);
|
$content = $this->_evaluate($viewFile, $data);
|
||||||
|
if ($this->Blocks->active()) {
|
||||||
|
throw new CakeException(__d('cake_dev', 'The "%s" block was left open.', $this->Blocks->active()));
|
||||||
|
}
|
||||||
$content = $this->Helpers->trigger(
|
$content = $this->Helpers->trigger(
|
||||||
'afterRenderFile',
|
'afterRenderFile',
|
||||||
array($viewFile, $content),
|
array($viewFile, $content),
|
||||||
|
|
|
@ -135,4 +135,13 @@ class ViewBlock {
|
||||||
public function keys() {
|
public function keys() {
|
||||||
return array_keys($this->_blocks);
|
return array_keys($this->_blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the currently open block.
|
||||||
|
*
|
||||||
|
* @return mixed Either null or the name of the open block.
|
||||||
|
*/
|
||||||
|
public function active() {
|
||||||
|
return $this->_active;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue