| 13532 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* SchemaShellTest Test file
|
|
|
4 |
*
|
|
|
5 |
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
|
|
6 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
7 |
*
|
|
|
8 |
* Licensed under The MIT License
|
|
|
9 |
* For full copyright and license information, please see the LICENSE.txt
|
|
|
10 |
* Redistributions of files must retain the above copyright notice.
|
|
|
11 |
*
|
|
|
12 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
13 |
* @link http://cakephp.org CakePHP Project
|
|
|
14 |
* @package Cake.Test.Case.Console.Command
|
|
|
15 |
* @since CakePHP v 1.3
|
|
|
16 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
App::uses('ShellDispatcher', 'Console');
|
|
|
20 |
App::uses('ConsoleOutput', 'Console');
|
|
|
21 |
App::uses('ConsoleInput', 'Console');
|
|
|
22 |
App::uses('Shell', 'Console');
|
|
|
23 |
App::uses('CakeSchema', 'Model');
|
|
|
24 |
App::uses('SchemaShell', 'Console/Command');
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Test for Schema database management
|
|
|
28 |
*
|
|
|
29 |
* @package Cake.Test.Case.Console.Command
|
|
|
30 |
*/
|
|
|
31 |
class SchemaShellTestSchema extends CakeSchema {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* connection property
|
|
|
35 |
*
|
|
|
36 |
* @var string
|
|
|
37 |
*/
|
|
|
38 |
public $connection = 'test';
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* comments property
|
|
|
42 |
*
|
|
|
43 |
* @var array
|
|
|
44 |
*/
|
|
|
45 |
public $comments = array(
|
|
|
46 |
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
47 |
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
|
|
|
48 |
'user_id' => array('type' => 'integer', 'null' => false),
|
|
|
49 |
'title' => array('type' => 'string', 'null' => false, 'length' => 100),
|
|
|
50 |
'comment' => array('type' => 'text', 'null' => false, 'default' => null),
|
|
|
51 |
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
|
|
|
52 |
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
53 |
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
54 |
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
|
|
55 |
);
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* posts property
|
|
|
59 |
*
|
|
|
60 |
* @var array
|
|
|
61 |
*/
|
|
|
62 |
public $articles = array(
|
|
|
63 |
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
64 |
'user_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
|
|
|
65 |
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
|
|
|
66 |
'body' => array('type' => 'text', 'null' => true, 'default' => null),
|
|
|
67 |
'summary' => array('type' => 'text', 'null' => true),
|
|
|
68 |
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1),
|
|
|
69 |
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
70 |
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
71 |
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
|
|
72 |
);
|
|
|
73 |
|
|
|
74 |
public $newone = array(
|
|
|
75 |
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
76 |
'testit' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
|
|
|
77 |
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
78 |
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
79 |
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
|
|
80 |
);
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* SchemaShellTest class
|
|
|
85 |
*
|
|
|
86 |
* @package Cake.Test.Case.Console.Command
|
|
|
87 |
*/
|
|
|
88 |
class SchemaShellTest extends CakeTestCase {
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Fixtures
|
|
|
92 |
*
|
|
|
93 |
* @var array
|
|
|
94 |
*/
|
|
|
95 |
public $fixtures = array(
|
|
|
96 |
'core.article', 'core.user', 'core.post', 'core.auth_user', 'core.author',
|
|
|
97 |
'core.comment', 'core.test_plugin_comment', 'core.aco', 'core.aro', 'core.aros_aco',
|
|
|
98 |
);
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* setUp method
|
|
|
102 |
*
|
|
|
103 |
* @return void
|
|
|
104 |
*/
|
|
|
105 |
public function setUp() {
|
|
|
106 |
parent::setUp();
|
|
|
107 |
|
|
|
108 |
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
109 |
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
110 |
$this->Shell = $this->getMock(
|
|
|
111 |
'SchemaShell',
|
|
|
112 |
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop'),
|
|
|
113 |
array($out, $out, $in)
|
|
|
114 |
);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* tearDown method
|
|
|
119 |
*
|
|
|
120 |
* @return void
|
|
|
121 |
*/
|
|
|
122 |
public function tearDown() {
|
|
|
123 |
parent::tearDown();
|
|
|
124 |
if (!empty($this->file) && $this->file instanceof File) {
|
|
|
125 |
$this->file->delete();
|
|
|
126 |
unset($this->file);
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
/**
|
|
|
131 |
* test startup method
|
|
|
132 |
*
|
|
|
133 |
* @return void
|
|
|
134 |
*/
|
|
|
135 |
public function testStartup() {
|
|
|
136 |
$this->Shell->startup();
|
|
|
137 |
$this->assertTrue(isset($this->Shell->Schema));
|
|
|
138 |
$this->assertInstanceOf('CakeSchema', $this->Shell->Schema);
|
|
|
139 |
$this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $this->Shell->Schema->name);
|
|
|
140 |
$this->assertEquals('schema.php', $this->Shell->Schema->file);
|
|
|
141 |
|
|
|
142 |
$this->Shell->Schema = null;
|
|
|
143 |
$this->Shell->params = array(
|
|
|
144 |
'name' => 'TestSchema'
|
|
|
145 |
);
|
|
|
146 |
$this->Shell->startup();
|
|
|
147 |
$this->assertEquals('TestSchema', $this->Shell->Schema->name);
|
|
|
148 |
$this->assertEquals('test_schema.php', $this->Shell->Schema->file);
|
|
|
149 |
$this->assertEquals('default', $this->Shell->Schema->connection);
|
|
|
150 |
$this->assertEquals(APP . 'Config' . DS . 'Schema', $this->Shell->Schema->path);
|
|
|
151 |
|
|
|
152 |
$this->Shell->Schema = null;
|
|
|
153 |
$this->Shell->params = array(
|
|
|
154 |
'file' => 'other_file.php',
|
|
|
155 |
'connection' => 'test',
|
|
|
156 |
'path' => '/test/path'
|
|
|
157 |
);
|
|
|
158 |
$this->Shell->startup();
|
|
|
159 |
$this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $this->Shell->Schema->name);
|
|
|
160 |
$this->assertEquals('other_file.php', $this->Shell->Schema->file);
|
|
|
161 |
$this->assertEquals('test', $this->Shell->Schema->connection);
|
|
|
162 |
$this->assertEquals('/test/path', $this->Shell->Schema->path);
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
/**
|
|
|
166 |
* Test View - and that it dumps the schema file to stdout
|
|
|
167 |
*
|
|
|
168 |
* @return void
|
|
|
169 |
*/
|
|
|
170 |
public function testView() {
|
|
|
171 |
$this->Shell->startup();
|
|
|
172 |
$this->Shell->Schema->path = APP . 'Config' . DS . 'Schema';
|
|
|
173 |
$this->Shell->params['file'] = 'i18n.php';
|
|
|
174 |
$this->Shell->expects($this->once())->method('_stop');
|
|
|
175 |
$this->Shell->expects($this->once())->method('out');
|
|
|
176 |
$this->Shell->view();
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
/**
|
|
|
180 |
* test that view() can find plugin schema files.
|
|
|
181 |
*
|
|
|
182 |
* @return void
|
|
|
183 |
*/
|
|
|
184 |
public function testViewWithPlugins() {
|
|
|
185 |
App::build(array(
|
|
|
186 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
187 |
));
|
|
|
188 |
CakePlugin::load('TestPlugin');
|
|
|
189 |
$this->Shell->args = array('TestPlugin.schema');
|
|
|
190 |
$this->Shell->startup();
|
|
|
191 |
$this->Shell->expects($this->exactly(2))->method('_stop');
|
|
|
192 |
$this->Shell->expects($this->atLeastOnce())->method('out');
|
|
|
193 |
$this->Shell->view();
|
|
|
194 |
|
|
|
195 |
$this->Shell->args = array();
|
|
|
196 |
$this->Shell->params = array('plugin' => 'TestPlugin');
|
|
|
197 |
$this->Shell->startup();
|
|
|
198 |
$this->Shell->view();
|
|
|
199 |
|
|
|
200 |
App::build();
|
|
|
201 |
CakePlugin::unload();
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
/**
|
|
|
205 |
* test dump() with sql file generation
|
|
|
206 |
*
|
|
|
207 |
* @return void
|
|
|
208 |
*/
|
|
|
209 |
public function testDumpWithFileWriting() {
|
|
|
210 |
$this->Shell->params = array(
|
|
|
211 |
'name' => 'i18n',
|
|
|
212 |
'connection' => 'test',
|
|
|
213 |
'write' => TMP . 'tests' . DS . 'i18n.sql'
|
|
|
214 |
);
|
|
|
215 |
$this->Shell->expects($this->once())->method('_stop');
|
|
|
216 |
$this->Shell->startup();
|
|
|
217 |
$this->Shell->dump();
|
|
|
218 |
|
|
|
219 |
$this->file = new File(TMP . 'tests' . DS . 'i18n.sql');
|
|
|
220 |
$contents = $this->file->read();
|
|
|
221 |
$this->assertRegExp('/DROP TABLE/', $contents);
|
|
|
222 |
$this->assertRegExp('/CREATE TABLE.*?i18n/', $contents);
|
|
|
223 |
$this->assertRegExp('/id/', $contents);
|
|
|
224 |
$this->assertRegExp('/model/', $contents);
|
|
|
225 |
$this->assertRegExp('/field/', $contents);
|
|
|
226 |
$this->assertRegExp('/locale/', $contents);
|
|
|
227 |
$this->assertRegExp('/foreign_key/', $contents);
|
|
|
228 |
$this->assertRegExp('/content/', $contents);
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
/**
|
|
|
232 |
* test that dump() can find and work with plugin schema files.
|
|
|
233 |
*
|
|
|
234 |
* @return void
|
|
|
235 |
*/
|
|
|
236 |
public function testDumpFileWritingWithPlugins() {
|
|
|
237 |
App::build(array(
|
|
|
238 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
239 |
));
|
|
|
240 |
CakePlugin::load('TestPlugin');
|
|
|
241 |
$this->Shell->args = array('TestPlugin.TestPluginApp');
|
|
|
242 |
$this->Shell->params = array(
|
|
|
243 |
'connection' => 'test',
|
|
|
244 |
'write' => TMP . 'tests' . DS . 'dump_test.sql'
|
|
|
245 |
);
|
|
|
246 |
$this->Shell->startup();
|
|
|
247 |
$this->Shell->expects($this->once())->method('_stop');
|
|
|
248 |
$this->Shell->dump();
|
|
|
249 |
|
|
|
250 |
$this->file = new File(TMP . 'tests' . DS . 'dump_test.sql');
|
|
|
251 |
$contents = $this->file->read();
|
|
|
252 |
|
|
|
253 |
$this->assertRegExp('/CREATE TABLE.*?test_plugin_acos/', $contents);
|
|
|
254 |
$this->assertRegExp('/id/', $contents);
|
|
|
255 |
$this->assertRegExp('/model/', $contents);
|
|
|
256 |
|
|
|
257 |
$this->file->delete();
|
|
|
258 |
App::build();
|
|
|
259 |
CakePlugin::unload();
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
/**
|
|
|
263 |
* test generate with snapshot generation
|
|
|
264 |
*
|
|
|
265 |
* @return void
|
|
|
266 |
*/
|
|
|
267 |
public function testGenerateSnapshot() {
|
|
|
268 |
$this->Shell->path = TMP;
|
|
|
269 |
$this->Shell->params['file'] = 'schema.php';
|
|
|
270 |
$this->Shell->params['force'] = false;
|
|
|
271 |
$this->Shell->args = array('snapshot');
|
|
|
272 |
$this->Shell->Schema = $this->getMock('CakeSchema');
|
|
|
273 |
$this->Shell->Schema->expects($this->at(0))->method('read')->will($this->returnValue(array('schema data')));
|
|
|
274 |
$this->Shell->Schema->expects($this->at(0))->method('write')->will($this->returnValue(true));
|
|
|
275 |
|
|
|
276 |
$this->Shell->Schema->expects($this->at(1))->method('read');
|
|
|
277 |
$this->Shell->Schema->expects($this->at(1))->method('write')->with(array('schema data', 'file' => 'schema_0.php'));
|
|
|
278 |
|
|
|
279 |
$this->Shell->generate();
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
/**
|
|
|
283 |
* test generate without a snapshot.
|
|
|
284 |
*
|
|
|
285 |
* @return void
|
|
|
286 |
*/
|
|
|
287 |
public function testGenerateNoOverwrite() {
|
|
|
288 |
touch(TMP . 'schema.php');
|
|
|
289 |
$this->Shell->params['file'] = 'schema.php';
|
|
|
290 |
$this->Shell->params['force'] = false;
|
|
|
291 |
$this->Shell->args = array();
|
|
|
292 |
|
|
|
293 |
$this->Shell->expects($this->once())->method('in')->will($this->returnValue('q'));
|
|
|
294 |
$this->Shell->Schema = $this->getMock('CakeSchema');
|
|
|
295 |
$this->Shell->Schema->path = TMP;
|
|
|
296 |
$this->Shell->Schema->expects($this->never())->method('read');
|
|
|
297 |
|
|
|
298 |
$this->Shell->generate();
|
|
|
299 |
unlink(TMP . 'schema.php');
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
/**
|
|
|
303 |
* test generate with overwriting of the schema files.
|
|
|
304 |
*
|
|
|
305 |
* @return void
|
|
|
306 |
*/
|
|
|
307 |
public function testGenerateOverwrite() {
|
|
|
308 |
touch(TMP . 'schema.php');
|
|
|
309 |
$this->Shell->params['file'] = 'schema.php';
|
|
|
310 |
$this->Shell->params['force'] = false;
|
|
|
311 |
$this->Shell->args = array();
|
|
|
312 |
|
|
|
313 |
$this->Shell->expects($this->once())->method('in')->will($this->returnValue('o'));
|
|
|
314 |
|
|
|
315 |
$this->Shell->expects($this->at(2))->method('out')
|
|
|
316 |
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Schema file:\s[a-z\.]+\sgenerated/'));
|
|
|
317 |
|
|
|
318 |
$this->Shell->Schema = $this->getMock('CakeSchema');
|
|
|
319 |
$this->Shell->Schema->path = TMP;
|
|
|
320 |
$this->Shell->Schema->expects($this->once())->method('read')->will($this->returnValue(array('schema data')));
|
|
|
321 |
$this->Shell->Schema->expects($this->once())->method('write')->will($this->returnValue(true));
|
|
|
322 |
|
|
|
323 |
$this->Shell->Schema->expects($this->once())->method('read');
|
|
|
324 |
$this->Shell->Schema->expects($this->once())->method('write')
|
|
|
325 |
->with(array('schema data', 'file' => 'schema.php'));
|
|
|
326 |
|
|
|
327 |
$this->Shell->generate();
|
|
|
328 |
unlink(TMP . 'schema.php');
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
/**
|
|
|
332 |
* test that generate() can read plugin dirs and generate schema files for the models
|
|
|
333 |
* in a plugin.
|
|
|
334 |
*
|
|
|
335 |
* @return void
|
|
|
336 |
*/
|
|
|
337 |
public function testGenerateWithPlugins() {
|
|
|
338 |
App::build(array(
|
|
|
339 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
340 |
), App::RESET);
|
|
|
341 |
CakePlugin::load('TestPlugin');
|
|
|
342 |
|
|
|
343 |
$this->db->cacheSources = false;
|
|
|
344 |
$this->Shell->params = array(
|
|
|
345 |
'plugin' => 'TestPlugin',
|
|
|
346 |
'connection' => 'test',
|
|
|
347 |
'force' => false
|
|
|
348 |
);
|
|
|
349 |
$this->Shell->startup();
|
|
|
350 |
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
|
|
351 |
|
|
|
352 |
$this->Shell->generate();
|
|
|
353 |
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
|
|
|
354 |
$contents = $this->file->read();
|
|
|
355 |
|
|
|
356 |
$this->assertRegExp('/class TestPluginSchema/', $contents);
|
|
|
357 |
$this->assertRegExp('/public \$posts/', $contents);
|
|
|
358 |
$this->assertRegExp('/public \$auth_users/', $contents);
|
|
|
359 |
$this->assertRegExp('/public \$authors/', $contents);
|
|
|
360 |
$this->assertRegExp('/public \$test_plugin_comments/', $contents);
|
|
|
361 |
$this->assertNotRegExp('/public \$users/', $contents);
|
|
|
362 |
$this->assertNotRegExp('/public \$articles/', $contents);
|
|
|
363 |
CakePlugin::unload();
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
/**
|
|
|
367 |
* test generate with specific models
|
|
|
368 |
*
|
|
|
369 |
* @return void
|
|
|
370 |
*/
|
|
|
371 |
public function testGenerateModels() {
|
|
|
372 |
App::build(array(
|
|
|
373 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
374 |
), App::RESET);
|
|
|
375 |
CakePlugin::load('TestPlugin');
|
|
|
376 |
|
|
|
377 |
$this->db->cacheSources = false;
|
|
|
378 |
$this->Shell->params = array(
|
|
|
379 |
'plugin' => 'TestPlugin',
|
|
|
380 |
'connection' => 'test',
|
|
|
381 |
'models' => 'TestPluginComment',
|
|
|
382 |
'force' => false,
|
|
|
383 |
'overwrite' => true
|
|
|
384 |
);
|
|
|
385 |
$this->Shell->startup();
|
|
|
386 |
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
|
|
387 |
|
|
|
388 |
$this->Shell->generate();
|
|
|
389 |
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
|
|
|
390 |
$contents = $this->file->read();
|
|
|
391 |
|
|
|
392 |
$this->assertRegExp('/class TestPluginSchema/', $contents);
|
|
|
393 |
$this->assertRegExp('/public \$test_plugin_comments/', $contents);
|
|
|
394 |
$this->assertNotRegExp('/public \$authors/', $contents);
|
|
|
395 |
$this->assertNotRegExp('/public \$auth_users/', $contents);
|
|
|
396 |
$this->assertNotRegExp('/public \$posts/', $contents);
|
|
|
397 |
CakePlugin::unload();
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
/**
|
|
|
401 |
* test generate with excluded tables
|
|
|
402 |
*
|
|
|
403 |
* @return void
|
|
|
404 |
*/
|
|
|
405 |
public function testGenerateExclude() {
|
|
|
406 |
Configure::write('Acl.database', 'test');
|
|
|
407 |
$this->db->cacheSources = false;
|
|
|
408 |
$this->Shell->params = array(
|
|
|
409 |
'connection' => 'test',
|
|
|
410 |
'force' => false,
|
|
|
411 |
'models' => 'Aro, Aco, Permission',
|
|
|
412 |
'overwrite' => true,
|
|
|
413 |
'exclude' => 'acos, aros',
|
|
|
414 |
);
|
|
|
415 |
$this->Shell->startup();
|
|
|
416 |
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
|
|
417 |
|
|
|
418 |
$this->Shell->generate();
|
|
|
419 |
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
|
|
|
420 |
$contents = $this->file->read();
|
|
|
421 |
|
|
|
422 |
$this->assertNotContains('public $acos = array(', $contents);
|
|
|
423 |
$this->assertNotContains('public $aros = array(', $contents);
|
|
|
424 |
$this->assertContains('public $aros_acos = array(', $contents);
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
/**
|
|
|
428 |
* Test schema run create with no table args.
|
|
|
429 |
*
|
|
|
430 |
* @return void
|
|
|
431 |
*/
|
|
|
432 |
public function testCreateNoArgs() {
|
|
|
433 |
$this->Shell->params = array(
|
|
|
434 |
'connection' => 'test'
|
|
|
435 |
);
|
|
|
436 |
$this->Shell->args = array('i18n');
|
|
|
437 |
$this->Shell->startup();
|
|
|
438 |
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
|
|
439 |
$this->Shell->create();
|
|
|
440 |
|
|
|
441 |
$db = ConnectionManager::getDataSource('test');
|
|
|
442 |
|
|
|
443 |
$db->cacheSources = false;
|
|
|
444 |
$sources = $db->listSources();
|
|
|
445 |
$this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources));
|
|
|
446 |
|
|
|
447 |
$schema = new i18nSchema();
|
|
|
448 |
$db->execute($db->dropSchema($schema));
|
|
|
449 |
}
|
|
|
450 |
|
|
|
451 |
/**
|
|
|
452 |
* Test schema run create with no table args.
|
|
|
453 |
*
|
|
|
454 |
* @return void
|
|
|
455 |
*/
|
|
|
456 |
public function testCreateWithTableArgs() {
|
|
|
457 |
$db = ConnectionManager::getDataSource('test');
|
|
|
458 |
$sources = $db->listSources();
|
|
|
459 |
if (in_array('i18n', $sources)) {
|
|
|
460 |
$this->markTestSkipped('i18n table already exists, cannot try to create it again.');
|
|
|
461 |
}
|
|
|
462 |
$this->Shell->params = array(
|
|
|
463 |
'connection' => 'test',
|
|
|
464 |
'name' => 'I18n',
|
|
|
465 |
'path' => APP . 'Config' . DS . 'Schema'
|
|
|
466 |
);
|
|
|
467 |
$this->Shell->args = array('I18n', 'i18n');
|
|
|
468 |
$this->Shell->startup();
|
|
|
469 |
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
|
|
470 |
$this->Shell->create();
|
|
|
471 |
|
|
|
472 |
$db = ConnectionManager::getDataSource('test');
|
|
|
473 |
$db->cacheSources = false;
|
|
|
474 |
$sources = $db->listSources();
|
|
|
475 |
$this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources), 'i18n should be present.');
|
|
|
476 |
|
|
|
477 |
$schema = new I18nSchema();
|
|
|
478 |
$db->execute($db->dropSchema($schema, 'i18n'));
|
|
|
479 |
}
|
|
|
480 |
|
|
|
481 |
/**
|
|
|
482 |
* test run update with a table arg.
|
|
|
483 |
*
|
|
|
484 |
* @return void
|
|
|
485 |
*/
|
|
|
486 |
public function testUpdateWithTable() {
|
|
|
487 |
$this->Shell = $this->getMock(
|
|
|
488 |
'SchemaShell',
|
|
|
489 |
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
|
|
|
490 |
array(&$this->Dispatcher)
|
|
|
491 |
);
|
|
|
492 |
|
|
|
493 |
$this->Shell->params = array(
|
|
|
494 |
'connection' => 'test',
|
|
|
495 |
'force' => true
|
|
|
496 |
);
|
|
|
497 |
$this->Shell->args = array('SchemaShellTest', 'articles');
|
|
|
498 |
$this->Shell->startup();
|
|
|
499 |
$this->Shell->expects($this->any())
|
|
|
500 |
->method('in')
|
|
|
501 |
->will($this->returnValue('y'));
|
|
|
502 |
$this->Shell->expects($this->once())
|
|
|
503 |
->method('_run')
|
|
|
504 |
->with($this->arrayHasKey('articles'), 'update', $this->isInstanceOf('CakeSchema'));
|
|
|
505 |
|
|
|
506 |
$this->Shell->update();
|
|
|
507 |
}
|
|
|
508 |
|
|
|
509 |
/**
|
|
|
510 |
* test run update with a table arg. and checks that a CREATE statement is issued
|
|
|
511 |
* table creation
|
|
|
512 |
* @return void
|
|
|
513 |
*/
|
|
|
514 |
public function testUpdateWithTableCreate() {
|
|
|
515 |
$this->Shell = $this->getMock(
|
|
|
516 |
'SchemaShell',
|
|
|
517 |
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
|
|
|
518 |
array(&$this->Dispatcher)
|
|
|
519 |
);
|
|
|
520 |
|
|
|
521 |
$this->Shell->params = array(
|
|
|
522 |
'connection' => 'test',
|
|
|
523 |
'force' => true
|
|
|
524 |
);
|
|
|
525 |
$this->Shell->args = array('SchemaShellTest', 'newone');
|
|
|
526 |
$this->Shell->startup();
|
|
|
527 |
$this->Shell->expects($this->any())
|
|
|
528 |
->method('in')
|
|
|
529 |
->will($this->returnValue('y'));
|
|
|
530 |
$r = $this->Shell->expects($this->once())
|
|
|
531 |
->method('_run')
|
|
|
532 |
->with($this->arrayHasKey('newone'), 'update', $this->isInstanceOf('CakeSchema'));
|
|
|
533 |
|
|
|
534 |
$this->Shell->update();
|
|
|
535 |
}
|
|
|
536 |
|
|
|
537 |
/**
|
|
|
538 |
* test that the plugin param creates the correct path in the schema object.
|
|
|
539 |
*
|
|
|
540 |
* @return void
|
|
|
541 |
*/
|
|
|
542 |
public function testPluginParam() {
|
|
|
543 |
App::build(array(
|
|
|
544 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
545 |
));
|
|
|
546 |
CakePlugin::load('TestPlugin');
|
|
|
547 |
$this->Shell->params = array(
|
|
|
548 |
'plugin' => 'TestPlugin',
|
|
|
549 |
'connection' => 'test'
|
|
|
550 |
);
|
|
|
551 |
$this->Shell->startup();
|
|
|
552 |
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Config' . DS . 'Schema';
|
|
|
553 |
$this->assertEquals($expected, $this->Shell->Schema->path);
|
|
|
554 |
CakePlugin::unload();
|
|
|
555 |
}
|
|
|
556 |
|
|
|
557 |
/**
|
|
|
558 |
* test that underscored names also result in CamelCased class names
|
|
|
559 |
*
|
|
|
560 |
* @return void
|
|
|
561 |
*/
|
|
|
562 |
public function testName() {
|
|
|
563 |
App::build(array(
|
|
|
564 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
565 |
));
|
|
|
566 |
CakePlugin::load('TestPlugin');
|
|
|
567 |
$this->Shell->params = array(
|
|
|
568 |
'plugin' => 'TestPlugin',
|
|
|
569 |
'connection' => 'test',
|
|
|
570 |
'name' => 'custom_name',
|
|
|
571 |
'force' => false,
|
|
|
572 |
'overwrite' => true,
|
|
|
573 |
);
|
|
|
574 |
$this->Shell->startup();
|
|
|
575 |
if (file_exists($this->Shell->Schema->path . DS . 'custom_name.php')) {
|
|
|
576 |
unlink($this->Shell->Schema->path . DS . 'custom_name.php');
|
|
|
577 |
}
|
|
|
578 |
$this->Shell->generate();
|
|
|
579 |
|
|
|
580 |
$contents = file_get_contents($this->Shell->Schema->path . DS . 'custom_name.php');
|
|
|
581 |
$this->assertRegExp('/class CustomNameSchema/', $contents);
|
|
|
582 |
unlink($this->Shell->Schema->path . DS . 'custom_name.php');
|
|
|
583 |
CakePlugin::unload();
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
/**
|
|
|
587 |
* test that passing name and file creates the passed filename with the
|
|
|
588 |
* passed class name
|
|
|
589 |
*
|
|
|
590 |
* @return void
|
|
|
591 |
*/
|
|
|
592 |
public function testNameAndFile() {
|
|
|
593 |
App::build(array(
|
|
|
594 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
595 |
));
|
|
|
596 |
CakePlugin::load('TestPlugin');
|
|
|
597 |
$this->Shell->params = array(
|
|
|
598 |
'plugin' => 'TestPlugin',
|
|
|
599 |
'connection' => 'test',
|
|
|
600 |
'name' => 'custom_name',
|
|
|
601 |
'file' => 'other_name',
|
|
|
602 |
'force' => false,
|
|
|
603 |
'overwrite' => true,
|
|
|
604 |
);
|
|
|
605 |
$this->Shell->startup();
|
|
|
606 |
$file = $this->Shell->Schema->path . DS . 'other_name.php';
|
|
|
607 |
if (file_exists($file)) {
|
|
|
608 |
unlink($file);
|
|
|
609 |
}
|
|
|
610 |
$this->Shell->generate();
|
|
|
611 |
|
|
|
612 |
$this->assertFileExists($file);
|
|
|
613 |
$contents = file_get_contents($file);
|
|
|
614 |
$this->assertRegExp('/class CustomNameSchema/', $contents);
|
|
|
615 |
|
|
|
616 |
if (file_exists($file)) {
|
|
|
617 |
unlink($file);
|
|
|
618 |
}
|
|
|
619 |
CakePlugin::unload();
|
|
|
620 |
}
|
|
|
621 |
|
|
|
622 |
/**
|
|
|
623 |
* test that using Plugin.name with write.
|
|
|
624 |
*
|
|
|
625 |
* @return void
|
|
|
626 |
*/
|
|
|
627 |
public function testPluginDotSyntaxWithCreate() {
|
|
|
628 |
App::build(array(
|
|
|
629 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
630 |
));
|
|
|
631 |
CakePlugin::load('TestPlugin');
|
|
|
632 |
$this->Shell->params = array(
|
|
|
633 |
'connection' => 'test'
|
|
|
634 |
);
|
|
|
635 |
$this->Shell->args = array('TestPlugin.TestPluginApp');
|
|
|
636 |
$this->Shell->startup();
|
|
|
637 |
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
|
|
638 |
$this->Shell->create();
|
|
|
639 |
|
|
|
640 |
$db = ConnectionManager::getDataSource('test');
|
|
|
641 |
$sources = $db->listSources();
|
|
|
642 |
$this->assertTrue(in_array($db->config['prefix'] . 'test_plugin_acos', $sources));
|
|
|
643 |
|
|
|
644 |
$schema = new TestPluginAppSchema();
|
|
|
645 |
$db->execute($db->dropSchema($schema, 'test_plugin_acos'));
|
|
|
646 |
CakePlugin::unload();
|
|
|
647 |
}
|
|
|
648 |
}
|