Skip to content

Commit

Permalink
Fixed overwriting existing flash messages if none were retained
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyharris committed May 23, 2017
1 parent f9eb00b commit bcf1ced
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TestSuite/IntegrationTestCase.php
Expand Up @@ -452,7 +452,7 @@ protected function _sendRequest($url, $method, $data = [])
$request = $this->_buildRequest($url, $method, $data);
$response = $dispatcher->execute($request);
$this->_requestSession = $request['session'];
if ($this->_retainFlashMessages) {
if ($this->_retainFlashMessages && $this->_flashMessages) {
$this->_requestSession->write('Flash', $this->_flashMessages);
}
$this->_response = $response;
Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -419,6 +419,21 @@ public function testFlashAssertionsAfterRender()
$this->assertSession('An error message', 'Flash.flash.0.message');
}

/**
* Test flash assertions stored with enableRememberFlashMessages() even if
* no view is rendered
*
* @return void
*/
public function testFlashAssertionsWithNoRender()
{
$this->enableRetainFlashMessages();
$this->get('/posts/flashNoRender');
$this->assertRedirect();

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

/**
* Tests the failure message for assertCookieNotSet
*
Expand Down
11 changes: 11 additions & 0 deletions tests/test_app/TestApp/Controller/PostsController.php
Expand Up @@ -62,6 +62,17 @@ public function index($layout = 'default')
$this->viewBuilder()->setLayout($layout);
}

/**
* Sets a flash message and redirects (no rendering)
*
* @return \Cake\Network\Response
*/
public function flashNoRender()
{
$this->Flash->error('An error message');
return $this->redirect(['action' => 'index']);
}

/**
* Stub get method
*
Expand Down

0 comments on commit bcf1ced

Please sign in to comment.