| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- /**
- * 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
- * @since 3.0.0
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\Controller\Component;
- use Cake\Controller\ComponentRegistry;
- use Cake\Controller\Component\FlashComponent;
- use Cake\Controller\Controller;
- use Cake\Core\Configure;
- use Cake\Event\Event;
- use Cake\Network\Request;
- use Cake\Network\Session;
- use Cake\TestSuite\TestCase;
- /**
- * FlashComponentTest class
- */
- class FlashComponentTest extends TestCase {
- /**
- * setUp method
- *
- * @return void
- */
- public function setUp() {
- parent::setUp();
- Configure::write('App.namespace', 'TestApp');
- $controller = new Controller(new Request(['session' => new Session()]));
- $this->ComponentRegistry = new ComponentRegistry($controller);
- $this->Flash = new FlashComponent($this->ComponentRegistry);
- $this->Session = new Session();
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- $this->Session->destroy();
- }
- /**
- * testSet method
- *
- * @return void
- * @covers \Cake\Controller\Component\FlashComponent::set
- */
- public function testSet() {
- $this->assertNull($this->Session->read('Flash.flash'));
- $this->Flash->set('This is a test message');
- $expected = [
- 'message' => 'This is a test message',
- 'key' => 'flash',
- 'element' => null,
- 'params' => []
- ];
- $result = $this->Session->read('Flash.flash');
- $this->assertEquals($expected, $result);
- $this->Flash->set('This is a test message', ['element' => 'test', 'params' => ['foo' => 'bar']]);
- $expected = [
- 'message' => 'This is a test message',
- 'key' => 'flash',
- 'element' => 'Flash/test',
- 'params' => ['foo' => 'bar']
- ];
- $result = $this->Session->read('Flash.flash');
- $this->assertEquals($expected, $result);
- $this->Flash->set('This is a test message', ['element' => 'MyPlugin.alert']);
- $expected = [
- 'message' => 'This is a test message',
- 'key' => 'flash',
- 'element' => 'MyPlugin.Flash/alert',
- 'params' => []
- ];
- $result = $this->Session->read('Flash.flash');
- $this->assertEquals($expected, $result);
- $this->Flash->set('This is a test message', ['key' => 'foobar']);
- $expected = [
- 'message' => 'This is a test message',
- 'key' => 'foobar',
- 'element' => null,
- 'params' => []
- ];
- $result = $this->Session->read('Flash.foobar');
- $this->assertEquals($expected, $result);
- }
- /**
- * testSetWithException method
- *
- * @return void
- * @covers \Cake\Controller\Component\FlashComponent::set
- */
- public function testSetWithException() {
- $this->assertNull($this->Session->read('Flash.flash'));
- $this->Flash->set(new \Exception('This is a test message'));
- $expected = [
- 'message' => 'This is a test message',
- 'key' => 'flash',
- 'element' => null,
- 'params' => []
- ];
- $result = $this->Session->read('Flash.flash');
- $this->assertEquals($expected, $result);
- }
- }
|