mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Changed Event names back, added view type getter
Changed `Element.beforeRender` and `Element.afterRender` back to `View.beforeRender` and `View.afterRender` Also added a getter for `View::_currentType`. Added more tests to make sure that things were getting reset right And also that View::render and View::element events were working As expected Changed Event names back, added view type getter Changed `Element.beforeRender` and `Element.afterRender` back to `View.beforeRender` and `View.afterRender` Also added a getter and setter for `View::_currentType`. Added more tests to make sure that things were getting reset right And also that View::render and View::element events were working As expected
This commit is contained in:
parent
7cef19fe96
commit
f9aa954562
2 changed files with 31 additions and 16 deletions
|
@ -240,24 +240,24 @@ class TestObjectWithToString {
|
|||
class TestObjectWithoutToString {
|
||||
}
|
||||
/**
|
||||
* Class TestElementEventListener
|
||||
* Class TestViewEventListener
|
||||
*
|
||||
* An event listener to test cakePHP events
|
||||
*/
|
||||
class TestElementEventListener implements CakeEventListener {
|
||||
public $beforeRenderIsElement = false;
|
||||
public $afterRenderIsElement = false;
|
||||
class TestViewEventListener implements CakeEventListener {
|
||||
public $beforeRenderViewType;
|
||||
public $afterRenderViewType;
|
||||
public function implementedEvents() {
|
||||
return array(
|
||||
"Element.beforeRender"=>"beforeRender",
|
||||
"Element.afterRender" =>"afterRender"
|
||||
"View.beforeRender"=>"beforeRender",
|
||||
"View.afterRender" =>"afterRender",
|
||||
);
|
||||
}
|
||||
public function beforeRender($event) {
|
||||
$this->beforeRenderIsElement = View::TYPE_ELEMENT == PHPUnit_Framework_Assert::readAttribute($event->subject(), "_currentType");
|
||||
$this->beforeRenderViewType = $event->subject()->getCurrentType();
|
||||
}
|
||||
public function afterRender($event) {
|
||||
$this->afterRenderIsElement = View::TYPE_ELEMENT == PHPUnit_Framework_Assert::readAttribute($event->subject(), "_currentType");
|
||||
$this->afterRenderViewType = $event->subject()->getCurrentType();
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -835,15 +835,23 @@ class ViewTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testElementEvent(){
|
||||
public function testViewEvent(){
|
||||
$View = new View($this->PostsController);
|
||||
$listener = new TestElementEventListener();
|
||||
$View->autoLayout = false;
|
||||
$listener = new TestViewEventListener();
|
||||
|
||||
$View->getEventManager()->attach($listener);
|
||||
|
||||
$View->render('index');
|
||||
$this->assertEquals(View::TYPE_VIEW, $listener->beforeRenderViewType);
|
||||
$this->assertEquals(View::TYPE_VIEW, $listener->afterRenderViewType);
|
||||
|
||||
$this->assertEquals($View->getCurrentType(), View::TYPE_VIEW);
|
||||
$View->element('test_element', array(), array("callbacks"=>true));
|
||||
$this->assertEquals(true, $listener->beforeRenderIsElement);
|
||||
$this->assertEquals(true, $listener->afterRenderIsElement);
|
||||
$this->assertEquals($View->getCurrentType(), View::TYPE_VIEW);
|
||||
|
||||
$this->assertEquals(View::TYPE_ELEMENT, $listener->beforeRenderViewType);
|
||||
$this->assertEquals(View::TYPE_ELEMENT, $listener->afterRenderViewType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -813,7 +813,14 @@ class View extends Object {
|
|||
}
|
||||
$this->viewVars = $data + $this->viewVars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreived the current view type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentType(){
|
||||
return $this->_currentType;
|
||||
}
|
||||
/**
|
||||
* Magic accessor for helpers. Provides access to attributes that were deprecated.
|
||||
*
|
||||
|
@ -1207,14 +1214,14 @@ class View extends Object {
|
|||
$this->_currentType = self::TYPE_ELEMENT;
|
||||
|
||||
if ($options['callbacks']) {
|
||||
$this->getEventManager()->dispatch(new CakeEvent('Element.beforeRender', $this, array($file)));
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($file)));
|
||||
}
|
||||
|
||||
$element = $this->_render($file, array_merge($this->viewVars, $data));
|
||||
|
||||
if ($options['callbacks']) {
|
||||
$this->getEventManager()->dispatch(new CakeEvent('Element.afterRender', $this, array($file, $element)));
|
||||
}
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($file, $element)));
|
||||
}
|
||||
|
||||
$this->_currentType = $restore;
|
||||
$this->_current = $current;
|
||||
|
|
Loading…
Reference in a new issue