Skip to content

Commit a33cb7f

Browse files
committed
Added test for asserting flash after they're rendered
1 parent 1995447 commit a33cb7f

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

tests/TestCase/TestSuite/IntegrationTestCaseTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,20 @@ public function testFlashSessionAndCookieAssertsHttpServer()
405405
$this->assertCookie(1, 'remember_me');
406406
}
407407

408+
/**
409+
* Test flash assertions stored with enableRememberFlashMessages() after they
410+
* are rendered
411+
*
412+
* @return void
413+
*/
414+
public function testFlashAssertionsAfterRender()
415+
{
416+
$this->enableRememberFlashMessages();
417+
$this->get('/posts/index/with_flash');
418+
419+
$this->assertSession('An error message', 'Flash.flash.0.message');
420+
}
421+
408422
/**
409423
* Tests the failure message for assertCookieNotSet
410424
*

tests/test_app/TestApp/Controller/PostsController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,18 @@ public function beforeFilter(Event $event)
4848
/**
4949
* Index method.
5050
*
51+
* @param string $layout
5152
* @return void
5253
*/
53-
public function index()
54+
public function index($layout = 'default')
5455
{
5556
$this->Flash->error('An error message');
5657
$this->response->cookie([
5758
'name' => 'remember_me',
5859
'value' => 1
5960
]);
6061
$this->set('test', 'value');
62+
$this->viewBuilder()->setLayout($layout);
6163
}
6264

6365
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="message"><?= h($message); ?></div>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
$this->loadHelper('Html');
3+
4+
$cakeDescription = 'CakePHP: the rapid development php framework';
5+
?>
6+
<!DOCTYPE html>
7+
<html xmlns="http://www.w3.org/1999/xhtml">
8+
<head>
9+
<?= $this->Html->charset(); ?>
10+
<title>
11+
<?= $cakeDescription ?>:
12+
<?= $this->fetch('title'); ?>
13+
</title>
14+
<?php
15+
echo $this->Html->meta('icon');
16+
17+
echo $this->Html->css('cake.generic');
18+
19+
echo $this->fetch('script');
20+
?>
21+
</head>
22+
<body>
23+
<div id="container">
24+
<div id="header">
25+
<h1><?= $this->Html->link($cakeDescription, 'http://cakephp.org'); ?></h1>
26+
</div>
27+
<div id="content">
28+
29+
<?= $this->Flash->render(); ?>
30+
<?= $this->fetch('content'); ?>
31+
32+
</div>
33+
<div id="footer">
34+
<?= $this->Html->link(
35+
$this->Html->image('cake.power.gif', ['alt' => $cakeDescription, 'border' => '0']),
36+
'http://www.cakephp.org/',
37+
['target' => '_blank', 'escape' => false]
38+
);
39+
?>
40+
</div>
41+
</div>
42+
</body>
43+
</html>

0 commit comments

Comments
 (0)