File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
tests/TestCase/View/Helper Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -59,14 +59,23 @@ class FlashHelper extends Helper {
59
59
* @param string $key The [Flash.]key you are rendering in the view.
60
60
* @param array $options Additional options to use for the creation of this flash message.
61
61
* Supports the 'params', and 'element' keys that are used in the helper.
62
- * @return string
62
+ * @return string|null Rendered flash message or null if flash key does not exist
63
+ * in session.
64
+ * @throws \UnexpectedValueException If value for flash settings key is not an array.
63
65
*/
64
66
public function render ($ key = 'flash ' , array $ options = []) {
65
67
if (!$ this ->request ->session ()->check ("Flash. $ key " )) {
66
- return '' ;
68
+ return ;
67
69
}
68
70
69
- $ flash = $ options + $ this ->request ->session ()->read ("Flash. $ key " );
71
+ $ flash = $ this ->request ->session ()->read ("Flash. $ key " );
72
+ if (!is_array ($ flash )) {
73
+ throw new \UnexpectedValueException (sprintf (
74
+ 'Value for flash setting key "%s" must be an array. ' ,
75
+ $ key
76
+ ));
77
+ }
78
+ $ flash = $ options + $ flash ;
70
79
$ this ->request ->session ()->delete ("Flash. $ key " );
71
80
72
81
return $ this ->_View ->element ($ flash ['element ' ], $ flash );
Original file line number Diff line number Diff line change @@ -107,6 +107,18 @@ public function testFlash() {
107
107
108
108
$ expected ['child ' ] = ['tag ' => 'p ' , 'content ' => 'This is a test of the emergency broadcasting system ' ];
109
109
$ this ->assertTag ($ expected , $ result );
110
+
111
+ $ this ->assertNull ($ this ->Flash ->render ('non-existent ' ));
112
+ }
113
+
114
+ /**
115
+ * testFlashThrowsException
116
+ *
117
+ * @expectedException \UnexpectedValueException
118
+ */
119
+ public function testFlashThrowsException () {
120
+ $ this ->View ->request ->session ()->write ('Flash.foo ' , 'bar ' );
121
+ $ this ->Flash ->render ('foo ' );
110
122
}
111
123
112
124
/**
You can’t perform that action at this time.
0 commit comments