Skip to content

Commit

Permalink
Remove flash string template and class option, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bcrowe committed Jun 10, 2014
1 parent ef108a7 commit daf6b06
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 48 deletions.
19 changes: 1 addition & 18 deletions src/View/Helper/FlashHelper.php
Expand Up @@ -26,19 +26,6 @@
*/
class FlashHelper extends Helper {

use StringTemplateTrait;

/**
* Default config for this class
*
* @var array
*/
protected $_defaultConfig = [
'templates' => [
'flash' => '<div id="{{key}}-message" class="message-{{class}}">{{message}}</div>'
]
];

/**
* Used to render the message set in FlashComponent::set()
*
Expand Down Expand Up @@ -95,11 +82,7 @@ public function render($key = 'flash', $attrs = []) {
$flash = array_merge($flash, $attrs);

if ($flash['element'] === null) {
return $this->formatTemplate('flash', [
'key' => $key,
'class' => $flash['class'],
'message' => $flash['message']
]);
return $flash['message'];
}

return $this->_View->element($flash['element'], $flash);
Expand Down
33 changes: 3 additions & 30 deletions tests/TestCase/View/Helper/FlashHelperTest.php
Expand Up @@ -47,14 +47,12 @@ public function setUp() {
'key' => 'flash',
'message' => 'This is a calling',
'element' => null,
'class' => 'info',
'params' => array()
),
'notification' => array(
'key' => 'notification',
'message' => 'This is a test of the emergency broadcasting system',
'element' => 'flash_helper',
'class' => 'info',
'params' => array(
'title' => 'Notice!',
'name' => 'Alert!'
Expand All @@ -63,8 +61,7 @@ public function setUp() {
'classy' => array(
'key' => 'classy',
'message' => 'Recorded',
'element' => null,
'class' => 'positive',
'element' => 'flash_classy',
'params' => array()
)
)
Expand All @@ -90,21 +87,14 @@ public function tearDown() {
*/
public function testFlash() {
$result = $this->Flash->render();
$expected = '<div id="flash-message" class="message-info">This is a calling</div>';
$expected = 'This is a calling';
$this->assertEquals($expected, $result);

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

$result = $this->Flash->render('notification');

$children = [
['tag' => 'h1', 'content' => 'Alert!'],
['tag' => 'h3', 'content' => 'Notice!'],
['tag' => 'p', 'content' => 'This is a test of the emergency broadcasting system']
];

$expected = [
'tag' => 'div',
'id' => 'notificationLayout',
Expand All @@ -121,17 +111,6 @@ public function testFlash() {
$this->assertTag($expected, $result);
}

/**
* test flash() with the attributes.
*
* @return void
*/
public function testFlashAttributes() {
$result = $this->Flash->render('flash', array('class' => 'crazy'));
$expected = '<div id="flash-message" class="message-crazy">This is a calling</div>';
$this->assertEquals($expected, $result);
}

/**
* test setting the element from the attrs.
*
Expand All @@ -143,12 +122,6 @@ public function testFlashElementInAttrs() {
'params' => array('title' => 'Notice!', 'name' => 'Alert!')
));

$children = [
['tag' => 'h1', 'content' => 'Alert!'],
['tag' => 'h3', 'content' => 'Notice!'],
['tag' => 'p', 'content' => 'This is a test of the emergency broadcasting system']
];

$expected = [
'tag' => 'div',
'id' => 'notificationLayout',
Expand Down
1 change: 1 addition & 0 deletions tests/test_app/TestApp/Template/Element/flash_classy.ctp
@@ -0,0 +1 @@
<div id="<?= $key ?>-message"><?= $message; ?></div>

0 comments on commit daf6b06

Please sign in to comment.