Skip to content

Commit

Permalink
Update flash tests for options array
Browse files Browse the repository at this point in the history
  • Loading branch information
bcrowe committed Jun 5, 2014
1 parent 2db0ba9 commit 00632a9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 23 deletions.
46 changes: 38 additions & 8 deletions tests/TestCase/Controller/Component/FlashComponentTest.php
Expand Up @@ -96,22 +96,46 @@ public function testSet() {
$this->assertNull($this->Session->read('Message.flash'));

$this->Flash->set('This is a test message');
$expected = ['message' => 'This is a test message', 'params' => ['element' => null], 'type' => 'info'];
$expected = [
'message' => 'This is a test message',
'key' => 'flash',
'element' => null,
'class' => 'info',
'params' => []
];
$result = $this->Session->read('Message.flash');
$this->assertEquals($expected, $result);

$this->Flash->set('This is a test message', 'test', ['foo' => 'bar']);
$expected = ['message' => 'This is a test message','params' => ['foo' => 'bar', 'element' => 'test'], 'type' => 'info'];
$this->Flash->set('This is a test message', ['element' => 'test', 'params' => ['foo' => 'bar']]);
$expected = [
'message' => 'This is a test message',
'key' => 'flash',
'element' => 'test',
'class' => 'info',
'params' => ['foo' => 'bar']
];
$result = $this->Session->read('Message.flash');
$this->assertEquals($expected, $result);

$this->Flash->set('This is a test message', 'MyPlugin.alert');
$expected = ['message' => 'This is a test message', 'params' => ['element' => 'MyPlugin.alert'], 'type' => 'info'];
$this->Flash->set('This is a test message', ['element' => 'MyPlugin.alert']);
$expected = [
'message' => 'This is a test message',
'key' => 'flash',
'element' => 'MyPlugin.alert',
'class' => 'info',
'params' => []
];
$result = $this->Session->read('Message.flash');
$this->assertEquals($expected, $result);

$this->Flash->set('This is a test message', null, [], 'foobar');
$expected = ['message' => 'This is a test message', 'params' => ['element' => null], 'type' => 'info'];
$this->Flash->set('This is a test message', ['key' => 'foobar']);
$expected = [
'message' => 'This is a test message',
'key' => 'foobar',
'element' => null,
'class' => 'info',
'params' => []
];
$result = $this->Session->read('Message.foobar');
$this->assertEquals($expected, $result);
}
Expand All @@ -126,7 +150,13 @@ public function testSetWithException() {
$this->assertNull($this->Session->read('Message.flash'));

$this->Flash->set(new \Exception('This is a test message'));
$expected = ['message' => 'This is a test message', 'params' => ['element' => null], 'type' => 'info'];
$expected = [
'message' => 'This is a test message',
'key' => 'flash',
'element' => null,
'class' => 'info',
'params' => []
];
$result = $this->Session->read('Message.flash');
$this->assertEquals($expected, $result);
}
Expand Down
35 changes: 20 additions & 15 deletions tests/TestCase/View/Helper/FlashHelperTest.php
Expand Up @@ -44,23 +44,28 @@ public function setUp() {
$session->write(array(
'Message' => array(
'flash' => array(
'type' => 'info',
'params' => array(),
'message' => 'This is a calling'
'key' => 'flash',
'message' => 'This is a calling',
'element' => null,
'class' => 'info',
'params' => array()
),
'notification' => array(
'type' => 'info',
'key' => 'notification',
'message' => 'This is a test of the emergency broadcasting system',
'element' => 'flash_helper',
'class' => 'info',
'params' => array(
'title' => 'Notice!',
'name' => 'Alert!',
'element' => 'session_helper'
),
'message' => 'This is a test of the emergency broadcasting system',
'name' => 'Alert!'
)
),
'classy' => array(
'type' => 'success',
'params' => array('class' => 'positive'),
'message' => 'Recorded'
'key' => 'classy',
'message' => 'Recorded',
'element' => null,
'class' => 'positive',
'params' => array()
)
)
));
Expand Down Expand Up @@ -88,7 +93,7 @@ public function testFlash() {
$expected = '<div id="flash-message" class="message-info">This is a calling</div>';
$this->assertEquals($expected, $result);

$expected = '<div id="classy-message" class="message-success">Recorded</div>';
$expected = '<div id="classy-message" class="message-positive">Recorded</div>';
$result = $this->Flash->out('classy');
$this->assertEquals($expected, $result);

Expand All @@ -115,11 +120,11 @@ public function testFlashAttributes() {
* @return void
*/
public function testFlashElementInAttrs() {
$result = $this->Flash->out('flash', array(
'element' => 'session_helper',
$result = $this->Flash->out('notification', array(
'element' => 'flash_helper',
'params' => array('title' => 'Notice!', 'name' => 'Alert!')
));
$expected = "<div id=\"notificationLayout\">\n\t<h1>Alert!</h1>\n\t<h3>Notice!</h3>\n\t<p>This is a calling</p>\n</div>";
$expected = "<div id=\"notificationLayout\">\n\t<h1>Alert!</h1>\n\t<h3>Notice!</h3>\n\t<p>This is a test of the emergency broadcasting system</p>\n</div>";
$this->assertTextEquals($expected, $result);
}

Expand Down

0 comments on commit 00632a9

Please sign in to comment.