Adding tests for element callbacks.

This commit is contained in:
mark_story 2010-11-04 23:45:07 -04:00
parent 32587c154c
commit 2e140a9fd3
2 changed files with 16 additions and 1 deletions

View file

@ -360,7 +360,7 @@ class View extends Object {
if ($callbacks) { if ($callbacks) {
$this->Helpers->trigger('beforeRender', array($file)); $this->Helpers->trigger('beforeRender', array($file));
} }
$element = $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers); $element = $this->_render($file, array_merge($this->viewVars, $params));
if ($callbacks) { if ($callbacks) {
$this->Helpers->trigger('afterRender', array($file, $element)); $this->Helpers->trigger('afterRender', array($file, $element));
} }

View file

@ -475,6 +475,21 @@ class ViewTest extends CakeTestCase {
$this->assertPattern('/non_existant_element/', $result); $this->assertPattern('/non_existant_element/', $result);
} }
/**
* test that elements can have callbacks
*
*/
function testElementCallbacks() {
$this->getMock('HtmlHelper', array(), array($this->View), 'ElementCallbackMockHtmlHelper');
$this->View->helpers = array('ElementCallbackMockHtml');
$this->View->loadHelpers();
$this->View->ElementCallbackMockHtml->expects($this->at(0))->method('beforeRender');
$this->View->ElementCallbackMockHtml->expects($this->at(1))->method('afterRender');
$this->View->element('test_element', array(), true);
$this->mockObjects[] = $this->View->ElementCallbackMockHtml;
}
/** /**
* testElementCacheHelperNoCache method * testElementCacheHelperNoCache method
* *