Browse Source

Move initialize logic to __construct().

Fixes #2582
mark_story 14 years ago
parent
commit
6fda055a1e

+ 2 - 9
lib/Cake/Controller/Component/CookieComponent.php

@@ -172,16 +172,9 @@ class CookieComponent extends Component {
 		if (isset($this->time)) {
 			$this->_expire($this->time);
 		}
-	}
 
-/**
- * Initialize CookieComponent
- * 
- * @param Controller $controller
- * @return void
- */
-	public function initialize($controller) {
-		if (is_object($controller) && isset($controller->response)) {
+		$controller = $collection->getController();
+		if ($controller && isset($controller->response)) {
 			$this->_response = $controller->response;
 		} else {
 			$this->_response = new CakeResponse(array('charset' => Configure::read('App.encoding')));

+ 4 - 5
lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php

@@ -72,10 +72,9 @@ class CookieComponentTest extends CakeTestCase {
  */
 	public function setUp() {
 		$_COOKIE = array();
-		$Collection = new ComponentCollection();
-		$this->Cookie = new CookieComponent($Collection);
 		$this->Controller = new CookieComponentTestController(new CakeRequest(), new CakeResponse());
-		$this->Cookie->initialize($this->Controller);
+		$this->Controller->constructClasses();
+		$this->Cookie = $this->Controller->Cookie;
 
 		$this->Cookie->name = 'CakeTestCookie';
 		$this->Cookie->time = 10;
@@ -199,7 +198,7 @@ class CookieComponentTest extends CakeTestCase {
 			'domain' => '',
 			'secure' => false,
 			'httpOnly' => true);
-		$result = $this->Controller->response->cookie($this->Cookie->name.'[Testing]');
+		$result = $this->Controller->response->cookie($this->Cookie->name . '[Testing]');
 		$this->assertEquals($result, $expected);
 	}
 
@@ -220,7 +219,7 @@ class CookieComponentTest extends CakeTestCase {
 			'domain' => '',
 			'secure' => false,
 			'httpOnly' => true);
-		$result = $this->Controller->response->cookie($this->Cookie->name.'[Testing]');
+		$result = $this->Controller->response->cookie($this->Cookie->name . '[Testing]');
 		$this->assertEquals($result, $expected);
 	}