Skip to content

Commit

Permalink
fixes #5904, changing email component to use initialize instead of st…
Browse files Browse the repository at this point in the history
…artup, so it can be used in other components more easily

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7969 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
gwoo committed Jan 2, 2009
1 parent 7421729 commit 4f0256f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cake/libs/controller/components/email.php
Expand Up @@ -262,11 +262,12 @@ class EmailComponent extends Object{
* @param object $controller Instantiating controller
* @access public
*/
function startup(&$controller) {
function initialize(&$controller, $settings) {
$this->Controller =& $controller;
if (Configure::read('App.encoding') !== null) {
$this->charset = Configure::read('App.encoding');
}
$this->_set($settings);
}
/**
* Send an email using the specified content, template and layout
Expand Down
39 changes: 39 additions & 0 deletions cake/tests/cases/libs/controller/component.test.php
Expand Up @@ -181,6 +181,7 @@ class OrangeComponent extends Object {
* @return void
*/
function initialize(&$controller, $settings) {
$this->Controller = $controller;
$this->Banana->testField = 'OrangeField';
$this->settings = $settings;
}
Expand Down Expand Up @@ -226,6 +227,16 @@ class MutuallyReferencingOneComponent extends Object {
class MutuallyReferencingTwoComponent extends Object {
var $components = array('MutuallyReferencingOne');
}

/**
* SomethingWithEmailComponent class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller
*/
class SomethingWithEmailComponent extends Object {
var $components = array('Email');
}
/**
* ComponentTest class
*
Expand Down Expand Up @@ -308,6 +319,8 @@ function testNestedComponentLoading() {
$this->assertTrue(is_a($Controller->Apple, 'AppleComponent'));
$this->assertTrue(is_a($Controller->Apple->Orange, 'OrangeComponent'));
$this->assertTrue(is_a($Controller->Apple->Orange->Banana, 'BananaComponent'));
$this->assertTrue(is_a($Controller->Apple->Orange->Controller, 'ComponentTestController'));

}
/**
* Tests Component::startup() and only running callbacks for components directly attached to
Expand Down Expand Up @@ -404,6 +417,32 @@ function testMutuallyReferencingComponents() {
'MutuallyReferencingOneComponent'
));
}
/**
* Test mutually referencing components.
*
* @return void
*/
function testSomethingReferencingEmailComponent() {
$Controller =& new ComponentTestController();
$Controller->components = array('SomethingWithEmail');
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
$Controller->beforeFilter();
$Controller->Component->startup($Controller);

$this->assertTrue(is_a(
$Controller->SomethingWithEmail,
'SomethingWithEmailComponent'
));
$this->assertTrue(is_a(
$Controller->SomethingWithEmail->Email,
'EmailComponent'
));
$this->assertTrue(is_a(
$Controller->SomethingWithEmail->Email->Controller,
'ComponentTestController'
));
}
}

?>

0 comments on commit 4f0256f

Please sign in to comment.