Browse Source

Added strict comparison & created new testcase for duplicate Flash messages

Alex Bogdanov 9 years ago
parent
commit
a6342a15f5

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

@@ -114,7 +114,7 @@ class FlashComponent extends Component
 
         if ($options['duplicate'] === false) {
             foreach ($messages as $existingMessage) {
-                if ($existingMessage['message'] == $message) {
+                if ($existingMessage['message'] === $message) {
                     return;
                 }
             }

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

@@ -109,12 +109,17 @@ class FlashComponentTest extends TestCase
         $result = $this->Session->read('Flash.foobar');
         $this->assertEquals($expected, $result);
 
+    }
+
+    public function testDuplicateIgnored()
+    {
+        $this->assertNull($this->Session->read('Flash.flash'));
 
         $this->Flash->config('duplicate', false);
         $this->Flash->set('This test message should appear once only');
         $this->Flash->set('This test message should appear once only');
-        $result = array_slice($this->Session->read('Flash.flash'), -2);
-        $this->assertNotEquals($result[0], $result[1]);
+        $result = $this->Session->read('Flash.flash');
+        $this->assertCount(1, $result);
     }
 
     /**