Browse Source

flash component bugfix

Stefan Dickmann 11 years ago
parent
commit
2818ee6339

+ 1 - 1
src/Controller/Component/FlashComponent.php

@@ -73,7 +73,7 @@ class FlashComponent extends Component {
  * @return void
  */
 	public function set($message, array $options = []) {
-		$opts = array_merge($this->_defaultConfig, $options);
+		$opts = array_merge($this->config(), $options);
 
 		if ($message instanceof \Exception) {
 			$opts['params'] += ['code' => $message->getCode()];

+ 22 - 2
tests/TestCase/Controller/Component/FlashComponentTest.php

@@ -36,8 +36,8 @@ class FlashComponentTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 		Configure::write('App.namespace', 'TestApp');
-		$controller = new Controller(new Request(['session' => new Session()]));
-		$this->ComponentRegistry = new ComponentRegistry($controller);
+		$this->Controller = new Controller(new Request(['session' => new Session()]));
+		$this->ComponentRegistry = new ComponentRegistry($this->Controller);
 		$this->Flash = new FlashComponent($this->ComponentRegistry);
 		$this->Session = new Session();
 	}
@@ -121,4 +121,24 @@ class FlashComponentTest extends TestCase {
 		$result = $this->Session->read('Flash.flash');
 		$this->assertEquals($expected, $result);
 	}
+
+/**
+ * testSetWithComponentConfiguration method
+ *
+ * @return void
+ */
+	public function testSetWithComponentConfiguration() {
+		$this->assertNull($this->Session->read('Flash.flash'));
+
+		$this->Controller->addComponent('Flash', ['element' => 'test']);
+		$this->Controller->Flash->set('This is a test message');
+		$expected = [
+			'message' => 'This is a test message',
+			'key' => 'flash',
+			'element' => 'Flash/test',
+			'params' => []
+		];
+		$result = $this->Session->read('Flash.flash');
+		$this->assertEquals($expected, $result);
+	}
 }