Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 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 --yes option
429
 *
430
 * @return void
431
 */
432
	public function testCreateOptionYes() {
433
		$this->Shell = $this->getMock(
434
			'SchemaShell',
435
			array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
436
			array(&$this->Dispatcher)
437
		);
438
 
439
		$this->Shell->params = array(
440
			'connection' => 'test',
441
			'yes' => true,
442
		);
443
		$this->Shell->args = array('i18n');
444
		$this->Shell->expects($this->never())->method('in');
445
		$this->Shell->expects($this->exactly(2))->method('_run');
446
		$this->Shell->startup();
447
		$this->Shell->create();
448
	}
449
 
450
/**
451
 * Test schema run create with no table args.
452
 *
453
 * @return void
454
 */
455
	public function testCreateNoArgs() {
456
		$this->Shell->params = array(
457
			'connection' => 'test'
458
		);
459
		$this->Shell->args = array('i18n');
460
		$this->Shell->startup();
461
		$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
462
		$this->Shell->create();
463
 
464
		$db = ConnectionManager::getDataSource('test');
465
 
466
		$db->cacheSources = false;
467
		$sources = $db->listSources();
468
		$this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources));
469
 
470
		$schema = new i18nSchema();
471
		$db->execute($db->dropSchema($schema));
472
	}
473
 
474
/**
475
 * Test schema run create with no table args.
476
 *
477
 * @return void
478
 */
479
	public function testCreateWithTableArgs() {
480
		$db = ConnectionManager::getDataSource('test');
481
		$sources = $db->listSources();
482
		if (in_array('i18n', $sources)) {
483
			$this->markTestSkipped('i18n table already exists, cannot try to create it again.');
484
		}
485
		$this->Shell->params = array(
486
			'connection' => 'test',
487
			'name' => 'I18n',
488
			'path' => APP . 'Config' . DS . 'Schema'
489
		);
490
		$this->Shell->args = array('I18n', 'i18n');
491
		$this->Shell->startup();
492
		$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
493
		$this->Shell->create();
494
 
495
		$db = ConnectionManager::getDataSource('test');
496
		$db->cacheSources = false;
497
		$sources = $db->listSources();
498
		$this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources), 'i18n should be present.');
499
 
500
		$schema = new I18nSchema();
501
		$db->execute($db->dropSchema($schema, 'i18n'));
502
	}
503
 
504
/**
505
 * test run update with a table arg.
506
 *
507
 * @return void
508
 */
509
	public function testUpdateWithTable() {
510
		$this->Shell = $this->getMock(
511
			'SchemaShell',
512
			array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
513
			array(&$this->Dispatcher)
514
		);
515
 
516
		$this->Shell->params = array(
517
			'connection' => 'test',
518
			'force' => true
519
		);
520
		$this->Shell->args = array('SchemaShellTest', 'articles');
521
		$this->Shell->startup();
522
		$this->Shell->expects($this->any())
523
			->method('in')
524
			->will($this->returnValue('y'));
525
		$this->Shell->expects($this->once())
526
			->method('_run')
527
			->with($this->arrayHasKey('articles'), 'update', $this->isInstanceOf('CakeSchema'));
528
 
529
		$this->Shell->update();
530
	}
531
 
532
/**
533
 * test run update with a table arg. and checks that a CREATE statement is issued
534
 * table creation
535
 * @return void
536
 */
537
	public function testUpdateWithTableCreate() {
538
		$this->Shell = $this->getMock(
539
			'SchemaShell',
540
			array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
541
			array(&$this->Dispatcher)
542
		);
543
 
544
		$this->Shell->params = array(
545
			'connection' => 'test',
546
			'force' => true
547
		);
548
		$this->Shell->args = array('SchemaShellTest', 'newone');
549
		$this->Shell->startup();
550
		$this->Shell->expects($this->any())
551
			->method('in')
552
			->will($this->returnValue('y'));
553
		$this->Shell->expects($this->once())
554
			->method('_run')
555
			->with($this->arrayHasKey('newone'), 'update', $this->isInstanceOf('CakeSchema'));
556
 
557
		$this->Shell->update();
558
	}
559
 
560
/**
561
 * test run update with --yes option
562
 *
563
 * @return void
564
 */
565
	public function testUpdateWithOptionYes() {
566
		$this->Shell = $this->getMock(
567
			'SchemaShell',
568
			array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
569
			array(&$this->Dispatcher)
570
		);
571
 
572
		$this->Shell->params = array(
573
			'connection' => 'test',
574
			'force' => true,
575
			'yes' => true,
576
		);
577
		$this->Shell->args = array('SchemaShellTest', 'articles');
578
		$this->Shell->startup();
579
		$this->Shell->expects($this->never())->method('in');
580
		$this->Shell->expects($this->once())
581
			->method('_run')
582
			->with($this->arrayHasKey('articles'), 'update', $this->isInstanceOf('CakeSchema'));
583
 
584
		$this->Shell->update();
585
	}
586
 
587
/**
588
 * test that the plugin param creates the correct path in the schema object.
589
 *
590
 * @return void
591
 */
592
	public function testPluginParam() {
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
		);
601
		$this->Shell->startup();
602
		$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Config' . DS . 'Schema';
603
		$this->assertEquals($expected, $this->Shell->Schema->path);
604
		CakePlugin::unload();
605
	}
606
 
607
/**
608
 * test that underscored names also result in CamelCased class names
609
 *
610
 * @return void
611
 */
612
	public function testName() {
613
		App::build(array(
614
			'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
615
		));
616
		CakePlugin::load('TestPlugin');
617
		$this->Shell->params = array(
618
			'plugin' => 'TestPlugin',
619
			'connection' => 'test',
620
			'name' => 'custom_name',
621
			'force' => false,
622
			'overwrite' => true,
623
		);
624
		$this->Shell->startup();
625
		if (file_exists($this->Shell->Schema->path . DS . 'custom_name.php')) {
626
			unlink($this->Shell->Schema->path . DS . 'custom_name.php');
627
		}
628
		$this->Shell->generate();
629
 
630
		$contents = file_get_contents($this->Shell->Schema->path . DS . 'custom_name.php');
631
		$this->assertRegExp('/class CustomNameSchema/', $contents);
632
		unlink($this->Shell->Schema->path . DS . 'custom_name.php');
633
		CakePlugin::unload();
634
	}
635
 
636
/**
637
 * test that passing name and file creates the passed filename with the
638
 * passed class name
639
 *
640
 * @return void
641
 */
642
	public function testNameAndFile() {
643
		App::build(array(
644
			'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
645
		));
646
		CakePlugin::load('TestPlugin');
647
		$this->Shell->params = array(
648
			'plugin' => 'TestPlugin',
649
			'connection' => 'test',
650
			'name' => 'custom_name',
651
			'file' => 'other_name',
652
			'force' => false,
653
			'overwrite' => true,
654
		);
655
		$this->Shell->startup();
656
		$file = $this->Shell->Schema->path . DS . 'other_name.php';
657
		if (file_exists($file)) {
658
			unlink($file);
659
		}
660
		$this->Shell->generate();
661
 
662
		$this->assertFileExists($file);
663
		$contents = file_get_contents($file);
664
		$this->assertRegExp('/class CustomNameSchema/', $contents);
665
 
666
		if (file_exists($file)) {
667
			unlink($file);
668
		}
669
		CakePlugin::unload();
670
	}
671
 
672
/**
673
 * test that using Plugin.name with write.
674
 *
675
 * @return void
676
 */
677
	public function testPluginDotSyntaxWithCreate() {
678
		App::build(array(
679
			'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
680
		));
681
		CakePlugin::load('TestPlugin');
682
		$this->Shell->params = array(
683
			'connection' => 'test'
684
		);
685
		$this->Shell->args = array('TestPlugin.TestPluginApp');
686
		$this->Shell->startup();
687
		$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
688
		$this->Shell->create();
689
 
690
		$db = ConnectionManager::getDataSource('test');
691
		$sources = $db->listSources();
692
		$this->assertTrue(in_array($db->config['prefix'] . 'test_plugin_acos', $sources));
693
 
694
		$schema = new TestPluginAppSchema();
695
		$db->execute($db->dropSchema($schema, 'test_plugin_acos'));
696
		CakePlugin::unload();
697
	}
698
}