Mercurial > hg > Members > shoshi > webvirt
comparison cake/tests/cases/libs/controller/controller_merge_vars.test.php @ 0:261e66bd5a0c
hg init
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jul 2011 21:08:31 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:261e66bd5a0c |
---|---|
1 <?php | |
2 /** | |
3 * Controller Merge vars Test file | |
4 * | |
5 * Isolated from the Controller and Component test as to not pollute their AppController class | |
6 * | |
7 * PHP versions 4 and 5 | |
8 * | |
9 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing> | |
10 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
11 * | |
12 * Licensed under The Open Group Test Suite License | |
13 * Redistributions of files must retain the above copyright notice. | |
14 * | |
15 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
16 * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests | |
17 * @package cake | |
18 * @subpackage cake.tests.cases.libs.controller | |
19 * @since CakePHP(tm) v 1.2.3 | |
20 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License | |
21 */ | |
22 if (!class_exists('AppController')) { | |
23 | |
24 /** | |
25 * Test case AppController | |
26 * | |
27 * @package cake | |
28 * @subpackage cake.tests.cases.libs.controller | |
29 */ | |
30 class AppController extends Controller { | |
31 | |
32 /** | |
33 * components | |
34 * | |
35 * @var array | |
36 */ | |
37 var $components = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false)); | |
38 /** | |
39 * helpers | |
40 * | |
41 * @var array | |
42 */ | |
43 var $helpers = array('MergeVar' => array('format' => 'html', 'terse')); | |
44 } | |
45 } elseif (!defined('APP_CONTROLLER_EXISTS')) { | |
46 define('APP_CONTROLLER_EXISTS', true); | |
47 } | |
48 | |
49 /** | |
50 * MergeVar Component | |
51 * | |
52 * @package cake.tests.cases.libs.controller | |
53 */ | |
54 class MergeVarComponent extends Object { | |
55 | |
56 } | |
57 | |
58 /** | |
59 * Additional controller for testing | |
60 * | |
61 * @package cake.tests.cases.libs.controller | |
62 */ | |
63 class MergeVariablesController extends AppController { | |
64 | |
65 /** | |
66 * name | |
67 * | |
68 * @var string | |
69 */ | |
70 var $name = 'MergeVariables'; | |
71 | |
72 /** | |
73 * uses | |
74 * | |
75 * @var arrays | |
76 */ | |
77 var $uses = array(); | |
78 } | |
79 | |
80 /** | |
81 * MergeVarPlugin App Controller | |
82 * | |
83 * @package cake.tests.cases.libs.controller | |
84 */ | |
85 class MergeVarPluginAppController extends AppController { | |
86 | |
87 /** | |
88 * components | |
89 * | |
90 * @var array | |
91 */ | |
92 var $components = array('Auth' => array('setting' => 'val', 'otherVal')); | |
93 | |
94 /** | |
95 * helpers | |
96 * | |
97 * @var array | |
98 */ | |
99 var $helpers = array('Javascript'); | |
100 } | |
101 | |
102 /** | |
103 * MergePostsController | |
104 * | |
105 * @package cake.tests.cases.libs.controller | |
106 */ | |
107 class MergePostsController extends MergeVarPluginAppController { | |
108 | |
109 /** | |
110 * name | |
111 * | |
112 * @var string | |
113 */ | |
114 var $name = 'MergePosts'; | |
115 | |
116 /** | |
117 * uses | |
118 * | |
119 * @var array | |
120 */ | |
121 var $uses = array(); | |
122 } | |
123 | |
124 | |
125 /** | |
126 * Test Case for Controller Merging of Vars. | |
127 * | |
128 * @package cake.tests.cases.libs.controller | |
129 */ | |
130 class ControllerMergeVarsTestCase extends CakeTestCase { | |
131 /** | |
132 * Skips the case if APP_CONTROLLER_EXISTS is defined | |
133 * | |
134 * @return void | |
135 */ | |
136 function skip() { | |
137 $this->skipIf(defined('APP_CONTROLLER_EXISTS'), 'APP_CONTROLLER_EXISTS cannot run. %s'); | |
138 } | |
139 /** | |
140 * end test | |
141 * | |
142 * @return void | |
143 */ | |
144 function endTest() { | |
145 ClassRegistry::flush(); | |
146 } | |
147 | |
148 /** | |
149 * test that component settings are not duplicated when merging component settings | |
150 * | |
151 * @return void | |
152 */ | |
153 function testComponentParamMergingNoDuplication() { | |
154 $Controller =& new MergeVariablesController(); | |
155 $Controller->constructClasses(); | |
156 | |
157 $expected = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false)); | |
158 $this->assertEqual($Controller->components, $expected, 'Duplication of settings occured. %s'); | |
159 } | |
160 | |
161 /** | |
162 * test component merges with redeclared components | |
163 * | |
164 * @return void | |
165 */ | |
166 function testComponentMergingWithRedeclarations() { | |
167 $Controller =& new MergeVariablesController(); | |
168 $Controller->components['MergeVar'] = array('remote', 'redirect' => true); | |
169 $Controller->constructClasses(); | |
170 | |
171 $expected = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => true, 'remote')); | |
172 $this->assertEqual($Controller->components, $expected, 'Merging of settings is wrong. %s'); | |
173 } | |
174 | |
175 /** | |
176 * test merging of helpers array, ensure no duplication occurs | |
177 * | |
178 * @return void | |
179 */ | |
180 function testHelperSettingMergingNoDuplication() { | |
181 $Controller =& new MergeVariablesController(); | |
182 $Controller->constructClasses(); | |
183 | |
184 $expected = array('MergeVar' => array('format' => 'html', 'terse')); | |
185 $this->assertEqual($Controller->helpers, $expected, 'Duplication of settings occured. %s'); | |
186 } | |
187 | |
188 /** | |
189 * Test that helpers declared in appcontroller come before those in the subclass | |
190 * orderwise | |
191 * | |
192 * @return void | |
193 */ | |
194 function testHelperOrderPrecedence() { | |
195 $Controller =& new MergeVariablesController(); | |
196 $Controller->helpers = array('Custom', 'Foo' => array('something')); | |
197 $Controller->constructClasses(); | |
198 | |
199 $expected = array( | |
200 'MergeVar' => array('format' => 'html', 'terse'), | |
201 'Custom' => null, | |
202 'Foo' => array('something') | |
203 ); | |
204 $this->assertIdentical($Controller->helpers, $expected, 'Order is incorrect. %s'); | |
205 } | |
206 | |
207 /** | |
208 * test merging of vars with plugin | |
209 * | |
210 * @return void | |
211 */ | |
212 function testMergeVarsWithPlugin() { | |
213 $Controller =& new MergePostsController(); | |
214 $Controller->components = array('Email' => array('ports' => 'open')); | |
215 $Controller->plugin = 'MergeVarPlugin'; | |
216 $Controller->constructClasses(); | |
217 | |
218 $expected = array( | |
219 'MergeVar' => array('flag', 'otherFlag', 'redirect' => false), | |
220 'Auth' => array('setting' => 'val', 'otherVal'), | |
221 'Email' => array('ports' => 'open') | |
222 ); | |
223 $this->assertEqual($Controller->components, $expected, 'Components are unexpected %s'); | |
224 | |
225 $expected = array( | |
226 'MergeVar' => array('format' => 'html', 'terse'), | |
227 'Javascript' => null | |
228 ); | |
229 $this->assertEqual($Controller->helpers, $expected, 'Helpers are unexpected %s'); | |
230 | |
231 $Controller =& new MergePostsController(); | |
232 $Controller->components = array(); | |
233 $Controller->plugin = 'MergeVarPlugin'; | |
234 $Controller->constructClasses(); | |
235 | |
236 $expected = array( | |
237 'MergeVar' => array('flag', 'otherFlag', 'redirect' => false), | |
238 'Auth' => array('setting' => 'val', 'otherVal'), | |
239 ); | |
240 $this->assertEqual($Controller->components, $expected, 'Components are unexpected %s'); | |
241 } | |
242 | |
243 /** | |
244 * Ensure that __mergeVars is not being greedy and merging with | |
245 * AppController when you make an instance of Controller | |
246 * | |
247 * @return void | |
248 */ | |
249 function testMergeVarsNotGreedy() { | |
250 $Controller =& new Controller(); | |
251 $Controller->components = array(); | |
252 $Controller->uses = array(); | |
253 $Controller->constructClasses(); | |
254 | |
255 $this->assertFalse(isset($Controller->Session)); | |
256 } | |
257 } |