Skip to content

Commit

Permalink
Added strict comparison & created new testcase for duplicate Flash me…
Browse files Browse the repository at this point in the history
…ssages
  • Loading branch information
visualex committed Dec 6, 2016
1 parent 08e17ed commit a6342a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Component/FlashComponent.php
Expand Up @@ -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;
}
}
Expand Down
9 changes: 7 additions & 2 deletions tests/TestCase/Controller/Component/FlashComponentTest.php
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit a6342a1

Please sign in to comment.