From a6342a15f511f2abe0c5d3aaa8f1670d6c1727ef Mon Sep 17 00:00:00 2001 From: Alex Bogdanov Date: Tue, 6 Dec 2016 04:55:32 +0100 Subject: [PATCH] Added strict comparison & created new testcase for duplicate Flash messages --- src/Controller/Component/FlashComponent.php | 2 +- .../TestCase/Controller/Component/FlashComponentTest.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Controller/Component/FlashComponent.php b/src/Controller/Component/FlashComponent.php index a043f9dffa5..a1e8f900c23 100644 --- a/src/Controller/Component/FlashComponent.php +++ b/src/Controller/Component/FlashComponent.php @@ -114,7 +114,7 @@ public function set($message, array $options = []) if ($options['duplicate'] === false) { foreach ($messages as $existingMessage) { - if ($existingMessage['message'] == $message) { + if ($existingMessage['message'] === $message) { return; } } diff --git a/tests/TestCase/Controller/Component/FlashComponentTest.php b/tests/TestCase/Controller/Component/FlashComponentTest.php index bba21e7fef3..f6d06444bb4 100644 --- a/tests/TestCase/Controller/Component/FlashComponentTest.php +++ b/tests/TestCase/Controller/Component/FlashComponentTest.php @@ -109,12 +109,17 @@ public function testSet() $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); } /**