Skip to content

Commit

Permalink
Added test for asserting flash after they're rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyharris committed May 5, 2017
1 parent 1995447 commit a33cb7f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -405,6 +405,20 @@ public function testFlashSessionAndCookieAssertsHttpServer()
$this->assertCookie(1, 'remember_me');
}

/**
* Test flash assertions stored with enableRememberFlashMessages() after they
* are rendered
*
* @return void
*/
public function testFlashAssertionsAfterRender()
{
$this->enableRememberFlashMessages();
$this->get('/posts/index/with_flash');

$this->assertSession('An error message', 'Flash.flash.0.message');
}

/**
* Tests the failure message for assertCookieNotSet
*
Expand Down
4 changes: 3 additions & 1 deletion tests/test_app/TestApp/Controller/PostsController.php
Expand Up @@ -48,16 +48,18 @@ public function beforeFilter(Event $event)
/**
* Index method.
*
* @param string $layout
* @return void
*/
public function index()
public function index($layout = 'default')
{
$this->Flash->error('An error message');
$this->response->cookie([
'name' => 'remember_me',
'value' => 1
]);
$this->set('test', 'value');
$this->viewBuilder()->setLayout($layout);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/test_app/TestApp/Template/Element/Flash/error.ctp
@@ -0,0 +1 @@
<div class="message"><?= h($message); ?></div>
43 changes: 43 additions & 0 deletions tests/test_app/TestApp/Template/Layout/with_flash.ctp
@@ -0,0 +1,43 @@
<?php
$this->loadHelper('Html');

$cakeDescription = 'CakePHP: the rapid development php framework';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?= $this->Html->charset(); ?>
<title>
<?= $cakeDescription ?>:
<?= $this->fetch('title'); ?>
</title>
<?php
echo $this->Html->meta('icon');

echo $this->Html->css('cake.generic');

echo $this->fetch('script');
?>
</head>
<body>
<div id="container">
<div id="header">
<h1><?= $this->Html->link($cakeDescription, 'http://cakephp.org'); ?></h1>
</div>
<div id="content">

<?= $this->Flash->render(); ?>
<?= $this->fetch('content'); ?>

</div>
<div id="footer">
<?= $this->Html->link(
$this->Html->image('cake.power.gif', ['alt' => $cakeDescription, 'border' => '0']),
'http://www.cakephp.org/',
['target' => '_blank', 'escape' => false]
);
?>
</div>
</div>
</body>
</html>

0 comments on commit a33cb7f

Please sign in to comment.