comparison cake/tests/cases/console/libs/tasks/plugin.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 * PluginTask Test file
4 *
5 * Test Case for plugin generation shell task
6 *
7 * PHP versions 4 and 5
8 *
9 * CakePHP : Rapid Development Framework (http://cakephp.org)
10 * Copyright 2006-2010, Cake Software Foundation, Inc.
11 *
12 * Licensed under The MIT License
13 * Redistributions of files must retain the above copyright notice.
14 *
15 * @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
16 * @link http://cakephp.org CakePHP Project
17 * @package cake
18 * @subpackage cake.tests.cases.console.libs.tasks
19 * @since CakePHP v 1.3.0
20 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
21 */
22 App::import('Shell', 'Shell', false);
23
24 if (!defined('DISABLE_AUTO_DISPATCH')) {
25 define('DISABLE_AUTO_DISPATCH', true);
26 }
27
28 if (!class_exists('ShellDispatcher')) {
29 ob_start();
30 $argv = false;
31 require CAKE . 'console' . DS . 'cake.php';
32 ob_end_clean();
33 }
34
35 require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'plugin.php';
36 require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
37
38 Mock::generatePartial(
39 'ShellDispatcher', 'TestPluginTaskMockShellDispatcher',
40 array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
41 );
42 Mock::generatePartial(
43 'PluginTask', 'MockPluginTask',
44 array('in', '_stop', 'err', 'out', 'createFile')
45 );
46
47 Mock::generate('ModelTask', 'PluginTestMockModelTask');
48
49 /**
50 * PluginTaskPlugin class
51 *
52 * @package cake
53 * @subpackage cake.tests.cases.console.libs.tasks
54 */
55 class PluginTaskTest extends CakeTestCase {
56
57 /**
58 * startTest method
59 *
60 * @return void
61 * @access public
62 */
63 function startTest() {
64 $this->Dispatcher =& new TestPluginTaskMockShellDispatcher();
65 $this->Dispatcher->shellPaths = App::path('shells');
66 $this->Task =& new MockPluginTask($this->Dispatcher);
67 $this->Task->Dispatch =& $this->Dispatcher;
68 $this->Task->path = TMP . 'tests' . DS;
69 }
70
71 /**
72 * startCase methods
73 *
74 * @return void
75 * @access public
76 */
77 function startCase() {
78 $this->_paths = $paths = App::path('plugins');
79 $this->_testPath = array_push($paths, TMP . 'tests' . DS);
80 App::build(array('plugins' => $paths));
81 }
82
83 /**
84 * endCase
85 *
86 * @return void
87 * @access public
88 */
89 function endCase() {
90 App::build(array('plugins' => $this->_paths));
91 }
92
93 /**
94 * endTest method
95 *
96 * @return void
97 * @access public
98 */
99 function endTest() {
100 ClassRegistry::flush();
101 }
102
103 /**
104 * test bake()
105 *
106 * @return void
107 * @access public
108 */
109 function testBakeFoldersAndFiles() {
110 $this->Task->setReturnValueAt(0, 'in', $this->_testPath);
111 $this->Task->setReturnValueAt(1, 'in', 'y');
112 $this->Task->bake('BakeTestPlugin');
113
114 $path = $this->Task->path . 'bake_test_plugin';
115 $this->assertTrue(is_dir($path), 'No plugin dir %s');
116
117 $this->assertTrue(is_dir($path . DS . 'config'), 'No config dir %s');
118 $this->assertTrue(is_dir($path . DS . 'config' . DS . 'schema'), 'No schema dir %s');
119 $this->assertTrue(file_exists($path . DS . 'config' . DS . 'schema' . DS . 'empty'), 'No empty file %s');
120
121 $this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
122 $this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
123 $this->assertTrue(file_exists($path . DS . 'controllers' . DS . 'components' . DS . 'empty'), 'No empty file %s');
124
125 $this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
126 $this->assertTrue(file_exists($path . DS . 'models' . DS . 'behaviors' . DS . 'empty'), 'No empty file %s');
127 $this->assertTrue(is_dir($path . DS . 'models' . DS . 'datasources'), 'No datasources dir %s');
128 $this->assertTrue(file_exists($path . DS . 'models' . DS . 'datasources' . DS . 'empty'), 'No empty file %s');
129
130 $this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
131 $this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
132 $this->assertTrue(file_exists($path . DS . 'views' . DS . 'helpers' . DS . 'empty'), 'No empty file %s');
133
134 $this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
135 $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
136
137 $this->assertTrue(
138 is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'components'), 'No components cases dir %s'
139 );
140 $this->assertTrue(
141 file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'components' . DS . 'empty'), 'No empty file %s'
142 );
143
144 $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors'), 'No behaviors cases dir %s');
145 $this->assertTrue(
146 file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors' . DS . 'empty'), 'No empty file %s'
147 );
148
149 $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'helpers'), 'No helpers cases dir %s');
150 $this->assertTrue(
151 file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'empty'), 'No empty file %s'
152 );
153
154 $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'models'), 'No models cases dir %s');
155 $this->assertTrue(
156 file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'models' . DS . 'empty'), 'No empty file %s'
157 );
158
159 $this->assertTrue(
160 is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'controllers'),
161 'No controllers cases dir %s'
162 );
163 $this->assertTrue(
164 file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'controllers' . DS . 'empty'), 'No empty file %s'
165 );
166
167 $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
168 $this->assertTrue(file_exists($path . DS . 'tests' . DS . 'groups' . DS . 'empty'), 'No empty file %s');
169
170 $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
171 $this->assertTrue(file_exists($path . DS . 'tests' . DS . 'fixtures' . DS . 'empty'), 'No empty file %s');
172
173 $this->assertTrue(is_dir($path . DS . 'vendors'), 'No vendors dir %s');
174
175 $this->assertTrue(is_dir($path . DS . 'vendors' . DS . 'shells'), 'No vendors shells dir %s');
176 $this->assertTrue(is_dir($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks'), 'No vendors shells tasks dir %s');
177 $this->assertTrue(file_exists($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks' . DS . 'empty'), 'No empty file %s');
178 $this->assertTrue(is_dir($path . DS . 'libs'), 'No libs dir %s');
179 $this->assertTrue(is_dir($path . DS . 'webroot'), 'No webroot dir %s');
180
181 $file = $path . DS . 'bake_test_plugin_app_controller.php';
182 $this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
183
184 $file = $path . DS . 'bake_test_plugin_app_model.php';
185 $this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
186
187 $Folder =& new Folder($this->Task->path . 'bake_test_plugin');
188 $Folder->delete();
189 }
190
191 /**
192 * test execute with no args, flowing into interactive,
193 *
194 * @return void
195 * @access public
196 */
197 function testExecuteWithNoArgs() {
198 $this->Task->setReturnValueAt(0, 'in', 'TestPlugin');
199 $this->Task->setReturnValueAt(1, 'in', '3');
200 $this->Task->setReturnValueAt(2, 'in', 'y');
201 $this->Task->setReturnValueAt(3, 'in', 'n');
202
203 $path = $this->Task->path . 'test_plugin';
204 $file = $path . DS . 'test_plugin_app_controller.php';
205 $this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
206
207 $file = $path . DS . 'test_plugin_app_model.php';
208 $this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
209
210 $this->Task->args = array();
211 $this->Task->execute();
212
213 $Folder =& new Folder($path);
214 $Folder->delete();
215 }
216
217 /**
218 * Test Execute
219 *
220 * @return void
221 * @access public
222 */
223 function testExecuteWithOneArg() {
224 $this->Task->setReturnValueAt(0, 'in', $this->_testPath);
225 $this->Task->setReturnValueAt(1, 'in', 'y');
226 $this->Task->Dispatch->args = array('BakeTestPlugin');
227 $this->Task->args =& $this->Task->Dispatch->args;
228
229 $path = $this->Task->path . 'bake_test_plugin';
230 $file = $path . DS . 'bake_test_plugin_app_controller.php';
231 $this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
232
233 $file = $path . DS . 'bake_test_plugin_app_model.php';
234 $this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
235
236 $this->Task->execute();
237
238 $Folder =& new Folder($this->Task->path . 'bake_test_plugin');
239 $Folder->delete();
240 }
241
242 /**
243 * test execute chaining into MVC parts
244 *
245 * @return void
246 * @access public
247 */
248 function testExecuteWithTwoArgs() {
249 $this->Task->Model =& new PluginTestMockModelTask();
250 $this->Task->setReturnValueAt(0, 'in', $this->_testPath);
251 $this->Task->setReturnValueAt(1, 'in', 'y');
252
253 $Folder =& new Folder($this->Task->path . 'bake_test_plugin', true);
254
255 $this->Task->Dispatch->args = array('BakeTestPlugin', 'model');
256 $this->Task->args =& $this->Task->Dispatch->args;
257
258 $this->Task->Model->expectOnce('loadTasks');
259 $this->Task->Model->expectOnce('execute');
260 $this->Task->execute();
261 $Folder->delete();
262 }
263 }