Browse Source

Make SessionHelper more accepting of bad data.

The SessionHelper needs to gracefully accept data that does not match
its expectations. By setting all the keys we can avoid any potential
warnings.

Refs #3813
mark_story 11 years ago
parent
commit
c468679f48

+ 2 - 1
src/View/Helper/SessionHelper.php

@@ -123,8 +123,9 @@ class SessionHelper extends Helper {
 		$this->request->session()->delete('Flash.' . $key);
 
 		if (!empty($attrs)) {
-			$flash = array_merge($flash, $attrs);
+			$flash = $attrs + $flash;
 		}
+		$flash += ['message' => '', 'type' => 'info', 'params' => []];
 
 		$message = $flash['message'];
 		$class = $flash['type'];

+ 14 - 1
tests/TestCase/View/Helper/SessionHelperTest.php

@@ -64,7 +64,10 @@ class SessionHelperTest extends TestCase {
 					'type' => 'success',
 					'params' => array('class' => 'positive'),
 					'message' => 'Recorded'
-				)
+				),
+				'incomplete' => [
+					'message' => 'A thing happened',
+				]
 			),
 			'Deeply' => array('nested' => array('key' => 'value')),
 		));
@@ -130,6 +133,16 @@ class SessionHelperTest extends TestCase {
 	}
 
 /**
+ * Test rendering a flash message for incomplete data.
+ *
+ * @return void
+ */
+	public function testFlashIncomplete() {
+		$result = $this->Session->flash('incomplete');
+		$expected = '<div id="flash-message" class="message-info">A thing happened</div>';
+	}
+
+/**
  * test flash() with the attributes.
  *
  * @return void