2015-02-04 15:05:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* FlashComponentTest file
|
|
|
|
*
|
|
|
|
* Series of tests for flash component.
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
|
|
|
* @package Cake.Test.Case.Controller.Component
|
|
|
|
* @since CakePHP(tm) v 2.7.0-dev
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
|
*/
|
|
|
|
|
|
|
|
App::uses('FlashComponent', 'Controller/Component');
|
|
|
|
App::uses('ComponentCollection', 'Controller');
|
|
|
|
|
|
|
|
/**
|
2015-02-04 15:31:50 +00:00
|
|
|
* FlashComponentTest class
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.Controller.Component
|
|
|
|
*/
|
2015-02-04 15:05:40 +00:00
|
|
|
class FlashComponentTest extends CakeTestCase {
|
|
|
|
|
|
|
|
/**
|
2015-02-04 15:31:50 +00:00
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-02-04 15:05:40 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->Components = new ComponentCollection();
|
|
|
|
$this->Flash = new FlashComponent($this->Components);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-04 15:31:50 +00:00
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-02-04 15:05:40 +00:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
|
|
|
CakeSession::destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-04 15:31:50 +00:00
|
|
|
* testSet method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-02-04 15:05:40 +00:00
|
|
|
public function testSet() {
|
2015-06-24 11:06:35 +00:00
|
|
|
$this->assertNull(CakeSession::read('Message.flash'));
|
2015-02-04 15:05:40 +00:00
|
|
|
|
|
|
|
$this->Flash->set('This is a test message');
|
|
|
|
$expected = array(
|
|
|
|
'message' => 'This is a test message',
|
|
|
|
'key' => 'flash',
|
|
|
|
'element' => 'Flash/default',
|
|
|
|
'params' => array()
|
|
|
|
);
|
2015-06-24 11:06:35 +00:00
|
|
|
$result = CakeSession::read('Message.flash');
|
2015-02-04 15:05:40 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$this->Flash->set('This is a test message', array(
|
|
|
|
'element' => 'test',
|
|
|
|
'params' => array('foo' => 'bar')
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'message' => 'This is a test message',
|
|
|
|
'key' => 'flash',
|
|
|
|
'element' => 'Flash/test',
|
|
|
|
'params' => array('foo' => 'bar')
|
|
|
|
);
|
2015-06-24 11:06:35 +00:00
|
|
|
$result = CakeSession::read('Message.flash');
|
2015-02-04 15:05:40 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$this->Flash->set('This is a test message', array('element' => 'MyPlugin.alert'));
|
|
|
|
$expected = array(
|
|
|
|
'message' => 'This is a test message',
|
|
|
|
'key' => 'flash',
|
|
|
|
'element' => 'MyPlugin.Flash/alert',
|
|
|
|
'params' => array()
|
|
|
|
);
|
2015-06-24 11:06:35 +00:00
|
|
|
$result = CakeSession::read('Message.flash');
|
2015-02-04 15:05:40 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$this->Flash->set('This is a test message', array('key' => 'foobar'));
|
|
|
|
$expected = array(
|
|
|
|
'message' => 'This is a test message',
|
|
|
|
'key' => 'foobar',
|
|
|
|
'element' => 'Flash/default',
|
|
|
|
'params' => array()
|
|
|
|
);
|
2015-06-24 11:06:35 +00:00
|
|
|
$result = CakeSession::read('Message.foobar');
|
2015-02-04 15:05:40 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-04 15:31:50 +00:00
|
|
|
* testSetWithException method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-02-04 15:05:40 +00:00
|
|
|
public function testSetWithException() {
|
2015-06-24 11:06:35 +00:00
|
|
|
$this->assertNull(CakeSession::read('Message.flash'));
|
2015-02-04 15:05:40 +00:00
|
|
|
|
|
|
|
$this->Flash->set(new Exception('This is a test message', 404));
|
|
|
|
$expected = array(
|
|
|
|
'message' => 'This is a test message',
|
|
|
|
'key' => 'flash',
|
|
|
|
'element' => 'Flash/default',
|
|
|
|
'params' => array('code' => 404)
|
|
|
|
);
|
2015-06-24 11:06:35 +00:00
|
|
|
$result = CakeSession::read('Message.flash');
|
2015-02-04 15:05:40 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-04 15:31:50 +00:00
|
|
|
* testSetWithComponentConfiguration method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-02-04 15:05:40 +00:00
|
|
|
public function testSetWithComponentConfiguration() {
|
2015-06-24 11:06:35 +00:00
|
|
|
$this->assertNull(CakeSession::read('Message.flash'));
|
2015-02-04 15:05:40 +00:00
|
|
|
|
|
|
|
$FlashWithSettings = $this->Components->load('Flash', array('element' => 'test'));
|
|
|
|
$FlashWithSettings->set('This is a test message');
|
|
|
|
$expected = array(
|
|
|
|
'message' => 'This is a test message',
|
|
|
|
'key' => 'flash',
|
|
|
|
'element' => 'Flash/test',
|
|
|
|
'params' => array()
|
|
|
|
);
|
2015-06-24 11:06:35 +00:00
|
|
|
$result = CakeSession::read('Message.flash');
|
2015-02-04 15:05:40 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-04 15:31:50 +00:00
|
|
|
* Test magic call method.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-02-04 15:05:40 +00:00
|
|
|
public function testCall() {
|
2015-06-24 11:06:35 +00:00
|
|
|
$this->assertNull(CakeSession::read('Message.flash'));
|
2015-02-04 15:05:40 +00:00
|
|
|
|
|
|
|
$this->Flash->success('It worked');
|
|
|
|
$expected = array(
|
|
|
|
'message' => 'It worked',
|
|
|
|
'key' => 'flash',
|
|
|
|
'element' => 'Flash/success',
|
|
|
|
'params' => array()
|
|
|
|
);
|
2015-06-24 11:06:35 +00:00
|
|
|
$result = CakeSession::read('Message.flash');
|
2015-02-04 15:05:40 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$this->Flash->error('It did not work', array('element' => 'error_thing'));
|
|
|
|
$expected = array(
|
|
|
|
'message' => 'It did not work',
|
|
|
|
'key' => 'flash',
|
|
|
|
'element' => 'Flash/error',
|
|
|
|
'params' => array()
|
|
|
|
);
|
2015-06-24 11:06:35 +00:00
|
|
|
$result = CakeSession::read('Message.flash');
|
2015-02-04 15:05:40 +00:00
|
|
|
$this->assertEquals($expected, $result, 'Element is ignored in magic call.');
|
|
|
|
}
|
|
|
|
}
|