| 16591 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* FlashHelperTest file
|
|
|
4 |
*
|
|
|
5 |
* Series of tests for flash helper.
|
|
|
6 |
*
|
|
|
7 |
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
|
|
8 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
9 |
*
|
|
|
10 |
* Licensed under The MIT License
|
|
|
11 |
* For full copyright and license information, please see the LICENSE.txt
|
|
|
12 |
* Redistributions of files must retain the above copyright notice
|
|
|
13 |
*
|
|
|
14 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
15 |
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
|
|
16 |
* @package Cake.Test.Case.View.Helper
|
|
|
17 |
* @since CakePHP(tm) v 2.7.0-dev
|
|
|
18 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
19 |
*/
|
|
|
20 |
|
|
|
21 |
App::uses('FlashHelper', 'View/Helper');
|
|
|
22 |
App::uses('View', 'View');
|
|
|
23 |
App::uses('CakePlugin', 'Core');
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* FlashHelperTest class
|
|
|
27 |
*
|
|
|
28 |
* @package Cake.Test.Case.View.Helper
|
|
|
29 |
*/
|
|
|
30 |
class FlashHelperTest extends CakeTestCase {
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* setupBeforeClass method
|
|
|
34 |
*
|
|
|
35 |
* @return void
|
|
|
36 |
*/
|
|
|
37 |
public static function setupBeforeClass() {
|
|
|
38 |
App::build(array(
|
|
|
39 |
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
|
|
40 |
));
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* setUp method
|
|
|
45 |
*
|
|
|
46 |
* @return void
|
|
|
47 |
*/
|
|
|
48 |
public function setUp() {
|
|
|
49 |
parent::setUp();
|
|
|
50 |
$controller = null;
|
|
|
51 |
$this->View = new View($controller);
|
|
|
52 |
$this->Flash = new FlashHelper($this->View);
|
|
|
53 |
|
|
|
54 |
if (!CakeSession::started()) {
|
|
|
55 |
CakeSession::start();
|
|
|
56 |
}
|
|
|
57 |
CakeSession::write(array(
|
|
|
58 |
'Message' => array(
|
|
|
59 |
'flash' => array(
|
|
|
60 |
'key' => 'flash',
|
|
|
61 |
'message' => 'This is a calling',
|
|
|
62 |
'element' => 'Flash/default',
|
|
|
63 |
'params' => array()
|
|
|
64 |
),
|
|
|
65 |
'notification' => array(
|
|
|
66 |
'key' => 'notification',
|
|
|
67 |
'message' => 'Broadcast message testing',
|
|
|
68 |
'element' => 'flash_helper',
|
|
|
69 |
'params' => array(
|
|
|
70 |
'title' => 'Notice!',
|
|
|
71 |
'name' => 'Alert!'
|
|
|
72 |
)
|
|
|
73 |
),
|
|
|
74 |
'classy' => array(
|
|
|
75 |
'key' => 'classy',
|
|
|
76 |
'message' => 'Recorded',
|
|
|
77 |
'element' => 'flash_classy',
|
|
|
78 |
'params' => array()
|
|
|
79 |
)
|
|
|
80 |
)
|
|
|
81 |
));
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* tearDown method
|
|
|
86 |
*
|
|
|
87 |
* @return void
|
|
|
88 |
*/
|
|
|
89 |
public function tearDown() {
|
|
|
90 |
parent::tearDown();
|
|
|
91 |
unset($this->View, $this->Flash);
|
|
|
92 |
CakeSession::destroy();
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* testFlash method
|
|
|
97 |
*
|
|
|
98 |
* @return void
|
|
|
99 |
*/
|
|
|
100 |
public function testFlash() {
|
|
|
101 |
$result = $this->Flash->render();
|
|
|
102 |
$expected = '<div class="message">This is a calling</div>';
|
|
|
103 |
$this->assertContains($expected, $result);
|
|
|
104 |
|
|
|
105 |
$expected = '<div id="classy-message">Recorded</div>';
|
|
|
106 |
$result = $this->Flash->render('classy');
|
|
|
107 |
$this->assertContains($expected, $result);
|
|
|
108 |
|
|
|
109 |
$result = $this->Flash->render('notification');
|
|
|
110 |
$expected = "<div id=\"notificationLayout\">\n\t<h1>Alert!</h1>\n\t<h3>Notice!</h3>\n\t<p>Broadcast message testing</p>\n</div>";
|
|
|
111 |
$this->assertContains($expected, $result);
|
|
|
112 |
|
|
|
113 |
$this->assertNull($this->Flash->render('non-existent'));
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/**
|
|
|
117 |
* testFlashThrowsException
|
|
|
118 |
*
|
|
|
119 |
* @expectedException UnexpectedValueException
|
|
|
120 |
*/
|
|
|
121 |
public function testFlashThrowsException() {
|
|
|
122 |
CakeSession::write('Message.foo', 'bar');
|
|
|
123 |
$this->Flash->render('foo');
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* test setting the element from the attrs.
|
|
|
128 |
*
|
|
|
129 |
* @return void
|
|
|
130 |
*/
|
|
|
131 |
public function testFlashElementInAttrs() {
|
|
|
132 |
$result = $this->Flash->render('notification', array(
|
|
|
133 |
'element' => 'flash_helper',
|
|
|
134 |
'params' => array('title' => 'Alert!', 'name' => 'Notice!')
|
|
|
135 |
));
|
|
|
136 |
|
|
|
137 |
$expected = "<div id=\"notificationLayout\">\n\t<h1>Notice!</h1>\n\t<h3>Alert!</h3>\n\t<p>Broadcast message testing</p>\n</div>";
|
|
|
138 |
|
|
|
139 |
$this->assertContains($expected, $result);
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
/**
|
|
|
143 |
* test using elements in plugins.
|
|
|
144 |
*
|
|
|
145 |
* @return void
|
|
|
146 |
*/
|
|
|
147 |
public function testFlashWithPluginElement() {
|
|
|
148 |
App::build(array(
|
|
|
149 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
150 |
));
|
|
|
151 |
CakePlugin::load('TestPlugin');
|
|
|
152 |
|
|
|
153 |
$result = $this->Flash->render('flash', array('element' => 'TestPlugin.plugin_element'));
|
|
|
154 |
$expected = 'this is the plugin element';
|
|
|
155 |
$this->assertContains($expected, $result);
|
|
|
156 |
}
|
|
|
157 |
}
|