Skip to content

Commit 4f0256f

Browse files
author
gwoo
committed
fixes #5904, changing email component to use initialize instead of startup, 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
1 parent 7421729 commit 4f0256f

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

cake/libs/controller/components/email.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,12 @@ class EmailComponent extends Object{
262262
* @param object $controller Instantiating controller
263263
* @access public
264264
*/
265-
function startup(&$controller) {
265+
function initialize(&$controller, $settings) {
266266
$this->Controller =& $controller;
267267
if (Configure::read('App.encoding') !== null) {
268268
$this->charset = Configure::read('App.encoding');
269269
}
270+
$this->_set($settings);
270271
}
271272
/**
272273
* Send an email using the specified content, template and layout

cake/tests/cases/libs/controller/component.test.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class OrangeComponent extends Object {
181181
* @return void
182182
*/
183183
function initialize(&$controller, $settings) {
184+
$this->Controller = $controller;
184185
$this->Banana->testField = 'OrangeField';
185186
$this->settings = $settings;
186187
}
@@ -226,6 +227,16 @@ class MutuallyReferencingOneComponent extends Object {
226227
class MutuallyReferencingTwoComponent extends Object {
227228
var $components = array('MutuallyReferencingOne');
228229
}
230+
231+
/**
232+
* SomethingWithEmailComponent class
233+
*
234+
* @package cake
235+
* @subpackage cake.tests.cases.libs.controller
236+
*/
237+
class SomethingWithEmailComponent extends Object {
238+
var $components = array('Email');
239+
}
229240
/**
230241
* ComponentTest class
231242
*
@@ -308,6 +319,8 @@ function testNestedComponentLoading() {
308319
$this->assertTrue(is_a($Controller->Apple, 'AppleComponent'));
309320
$this->assertTrue(is_a($Controller->Apple->Orange, 'OrangeComponent'));
310321
$this->assertTrue(is_a($Controller->Apple->Orange->Banana, 'BananaComponent'));
322+
$this->assertTrue(is_a($Controller->Apple->Orange->Controller, 'ComponentTestController'));
323+
311324
}
312325
/**
313326
* Tests Component::startup() and only running callbacks for components directly attached to
@@ -404,6 +417,32 @@ function testMutuallyReferencingComponents() {
404417
'MutuallyReferencingOneComponent'
405418
));
406419
}
420+
/**
421+
* Test mutually referencing components.
422+
*
423+
* @return void
424+
*/
425+
function testSomethingReferencingEmailComponent() {
426+
$Controller =& new ComponentTestController();
427+
$Controller->components = array('SomethingWithEmail');
428+
$Controller->constructClasses();
429+
$Controller->Component->initialize($Controller);
430+
$Controller->beforeFilter();
431+
$Controller->Component->startup($Controller);
432+
433+
$this->assertTrue(is_a(
434+
$Controller->SomethingWithEmail,
435+
'SomethingWithEmailComponent'
436+
));
437+
$this->assertTrue(is_a(
438+
$Controller->SomethingWithEmail->Email,
439+
'EmailComponent'
440+
));
441+
$this->assertTrue(is_a(
442+
$Controller->SomethingWithEmail->Email->Controller,
443+
'ComponentTestController'
444+
));
445+
}
407446
}
408447

409448
?>

0 commit comments

Comments
 (0)