Skip to content

Commit

Permalink
Adding tests for Component::triggerCallback(). Deprecating other Comp…
Browse files Browse the repository at this point in the history
…onent methods, as they are just wrappers for triggerCallback().
  • Loading branch information
markstory committed Feb 28, 2010
1 parent 70c4c05 commit 37cf554
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cake/libs/controller/component.php
Expand Up @@ -107,6 +107,7 @@ function initialize(&$controller) {
* @return void * @return void
* @access public * @access public
* @link http://book.cakephp.org/view/65/MVC-Class-Access-Within-Components * @link http://book.cakephp.org/view/65/MVC-Class-Access-Within-Components
* @deprecated See Component::triggerCallback()
*/ */
function startup(&$controller) { function startup(&$controller) {
$this->triggerCallback('startup', $controller); $this->triggerCallback('startup', $controller);
Expand All @@ -119,6 +120,7 @@ function startup(&$controller) {
* @param object $controller Controller with components to beforeRender * @param object $controller Controller with components to beforeRender
* @return void * @return void
* @access public * @access public
* @deprecated See Component::triggerCallback()
*/ */
function beforeRender(&$controller) { function beforeRender(&$controller) {
$this->triggerCallback('beforeRender', $controller); $this->triggerCallback('beforeRender', $controller);
Expand Down Expand Up @@ -154,6 +156,7 @@ function beforeRedirect(&$controller, $url, $status = null, $exit = true) {
* @param object $controller Controller with components to shutdown * @param object $controller Controller with components to shutdown
* @return void * @return void
* @access public * @access public
* @deprecated See Component::triggerCallback()
*/ */
function shutdown(&$controller) { function shutdown(&$controller) {
$this->triggerCallback('shutdown', $controller); $this->triggerCallback('shutdown', $controller);
Expand Down
20 changes: 20 additions & 0 deletions cake/tests/cases/libs/controller/component.test.php
Expand Up @@ -290,6 +290,8 @@ class SomethingWithEmailComponent extends Object {
var $components = array('Email'); var $components = array('Email');
} }


Mock::generate('Object', 'ComponentMockComponent', array('startup', 'beforeFilter', 'beforeRender', 'other'));

/** /**
* ComponentTest class * ComponentTest class
* *
Expand Down Expand Up @@ -416,6 +418,24 @@ function testComponentStartup() {
$this->assertFalse(isset($Controller->bar)); $this->assertFalse(isset($Controller->bar));
} }


/**
* test that triggerCallbacks fires methods on all the components, and can trigger any method.
*
* @return void
*/
function testTriggerCallback() {
$Controller =& new ComponentTestController();
$Controller->components = array('ComponentMock');
$Controller->constructClasses();

$Controller->ComponentMock->expectOnce('beforeRender');
$Controller->Component->triggerCallback('beforeRender', $Controller);

$Controller->ComponentMock->expectNever('beforeFilter');
$Controller->ComponentMock->enabled = false;
$Controller->Component->triggerCallback('beforeFilter', $Controller);
}

/** /**
* test a component being used more than once. * test a component being used more than once.
* *
Expand Down

0 comments on commit 37cf554

Please sign in to comment.