Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15403 manish.sha 1
<?php
2
/**
3
 * ModelTaskTest file
4
 *
5
 * Test Case for test generation shell task
6
 *
7
 * CakePHP : Rapid Development Framework (http://cakephp.org)
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://cakephp.org CakePHP Project
16
 * @package       Cake.Test.Case.Console.Command.Task
17
 * @since         CakePHP v 1.2.6
18
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
19
 */
20
 
21
App::uses('ShellDispatcher', 'Console');
22
App::uses('Shell', 'Console');
23
App::uses('ConsoleOutput', 'Console');
24
App::uses('ConsoleInput', 'Console');
25
App::uses('FixtureTask', 'Console/Command/Task');
26
App::uses('TemplateTask', 'Console/Command/Task');
27
App::uses('ModelTask', 'Console/Command/Task');
28
 
29
/**
30
 * ModelTaskTest class
31
 *
32
 * @package	   Cake.Test.Case.Console.Command.Task
33
 * @property   ModelTask $Task
34
 */
35
class ModelTaskTest extends CakeTestCase {
36
 
37
/**
38
 * fixtures
39
 *
40
 * @var array
41
 */
42
	public $fixtures = array(
43
		'core.bake_article', 'core.bake_comment', 'core.bake_articles_bake_tag',
44
		'core.bake_tag', 'core.category_thread', 'core.number_tree'
45
	);
46
 
47
/**
48
 * setUp method
49
 *
50
 * @return void
51
 */
52
	public function setUp() {
53
		parent::setUp();
54
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
55
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
56
 
57
		$this->Task = $this->getMock('ModelTask',
58
			array('in', 'err', 'createFile', '_stop', '_checkUnitTest'),
59
			array($out, $out, $in)
60
		);
61
		$this->_setupOtherMocks();
62
	}
63
 
64
/**
65
 * Setup a mock that has out mocked. Normally this is not used as it makes $this->at() really tricky.
66
 *
67
 * @return void
68
 */
69
	protected function _useMockedOut() {
70
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
71
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
72
 
73
		$this->Task = $this->getMock('ModelTask',
74
			array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
75
			array($out, $out, $in)
76
		);
77
		$this->_setupOtherMocks();
78
	}
79
 
80
/**
81
 * sets up the rest of the dependencies for Model Task
82
 *
83
 * @return void
84
 */
85
	protected function _setupOtherMocks() {
86
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
87
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
88
 
89
		$this->Task->Fixture = $this->getMock('FixtureTask', array(), array($out, $out, $in));
90
		$this->Task->Test = $this->getMock('FixtureTask', array(), array($out, $out, $in));
91
		$this->Task->Template = new TemplateTask($out, $out, $in);
92
 
93
		$this->Task->name = 'Model';
94
		$this->Task->interactive = true;
95
	}
96
 
97
/**
98
 * tearDown method
99
 *
100
 * @return void
101
 */
102
	public function tearDown() {
103
		parent::tearDown();
104
		unset($this->Task);
105
	}
106
 
107
/**
108
 * Test that listAll scans the database connection and lists all the tables in it.s
109
 *
110
 * @return void
111
 */
112
	public function testListAllArgument() {
113
		$this->_useMockedOut();
114
 
115
		$result = $this->Task->listAll('test');
116
		$this->assertContains('bake_articles', $result);
117
		$this->assertContains('bake_articles_bake_tags', $result);
118
		$this->assertContains('bake_tags', $result);
119
		$this->assertContains('bake_comments', $result);
120
		$this->assertContains('category_threads', $result);
121
	}
122
 
123
/**
124
 * Test that listAll uses the connection property
125
 *
126
 * @return void
127
 */
128
	public function testListAllConnection() {
129
		$this->_useMockedOut();
130
 
131
		$this->Task->connection = 'test';
132
		$result = $this->Task->listAll();
133
		$this->assertContains('bake_articles', $result);
134
		$this->assertContains('bake_articles_bake_tags', $result);
135
		$this->assertContains('bake_tags', $result);
136
		$this->assertContains('bake_comments', $result);
137
		$this->assertContains('category_threads', $result);
138
	}
139
 
140
/**
141
 * Test that getName interacts with the user and returns the model name.
142
 *
143
 * @return void
144
 */
145
	public function testGetNameQuit() {
146
		$this->Task->expects($this->once())->method('in')->will($this->returnValue('q'));
147
		$this->Task->expects($this->once())->method('_stop');
148
		$this->Task->getName('test');
149
	}
150
 
151
/**
152
 * test getName with a valid option.
153
 *
154
 * @return void
155
 */
156
	public function testGetNameValidOption() {
157
		$listing = $this->Task->listAll('test');
158
		$this->Task->expects($this->any())->method('in')->will($this->onConsecutiveCalls(1, 4));
159
 
160
		$result = $this->Task->getName('test');
161
		$this->assertEquals(Inflector::classify($listing[0]), $result);
162
 
163
		$result = $this->Task->getName('test');
164
		$this->assertEquals(Inflector::classify($listing[3]), $result);
165
	}
166
 
167
/**
168
 * test that an out of bounds option causes an error.
169
 *
170
 * @return void
171
 */
172
	public function testGetNameWithOutOfBoundsOption() {
173
		$this->Task->expects($this->any())->method('in')->will($this->onConsecutiveCalls(99, 1));
174
		$this->Task->expects($this->once())->method('err');
175
 
176
		$this->Task->getName('test');
177
	}
178
 
179
/**
180
 * Test table name interactions
181
 *
182
 * @return void
183
 */
184
	public function testGetTableName() {
185
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
186
		$result = $this->Task->getTable('BakeArticle', 'test');
187
		$expected = 'bake_articles';
188
		$this->assertEquals($expected, $result);
189
	}
190
 
191
/**
192
 * test getting a custom table name.
193
 *
194
 * @return void
195
 */
196
	public function testGetTableNameCustom() {
197
		$this->Task->expects($this->any())->method('in')->will($this->onConsecutiveCalls('n', 'my_table'));
198
		$result = $this->Task->getTable('BakeArticle', 'test');
199
		$expected = 'my_table';
200
		$this->assertEquals($expected, $result);
201
	}
202
 
203
/**
204
 * test getTable with non-conventional tablenames
205
 *
206
 * @return void
207
 */
208
	public function testGetTableOddTableInteractive() {
209
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
210
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
211
		$this->Task = $this->getMock('ModelTask',
212
			array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables'),
213
			array($out, $out, $in)
214
		);
215
		$this->_setupOtherMocks();
216
 
217
		$this->Task->connection = 'test';
218
		$this->Task->path = '/my/path/';
219
		$this->Task->interactive = true;
220
 
221
		$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
222
		$this->Task->expects($this->any())->method('in')
223
			->will($this->onConsecutiveCalls(
224
				2 // bake_odd
225
			));
226
 
227
		$result = $this->Task->getName();
228
		$expected = 'BakeOdd';
229
		$this->assertEquals($expected, $result);
230
 
231
		$result = $this->Task->getTable($result);
232
		$expected = 'bake_odd';
233
		$this->assertEquals($expected, $result);
234
	}
235
 
236
/**
237
 * test getTable with non-conventional tablenames
238
 *
239
 * @return void
240
 */
241
	public function testGetTableOddTable() {
242
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
243
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
244
		$this->Task = $this->getMock('ModelTask',
245
			array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables'),
246
			array($out, $out, $in)
247
		);
248
		$this->_setupOtherMocks();
249
 
250
		$this->Task->connection = 'test';
251
		$this->Task->path = '/my/path/';
252
		$this->Task->interactive = false;
253
		$this->Task->args = array('BakeOdd');
254
 
255
		$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
256
 
257
		$this->Task->listAll();
258
 
259
		$result = $this->Task->getTable('BakeOdd');
260
		$expected = 'bake_odd';
261
		$this->assertEquals($expected, $result);
262
	}
263
 
264
/**
265
 * test that initializing the validations works.
266
 *
267
 * @return void
268
 */
269
	public function testInitValidations() {
270
		$result = $this->Task->initValidations();
271
		$this->assertTrue(in_array('notEmpty', $result));
272
	}
273
 
274
/**
275
 * test that individual field validation works, with interactive = false
276
 * tests the guessing features of validation
277
 *
278
 * @return void
279
 */
280
	public function testFieldValidationGuessing() {
281
		$this->Task->interactive = false;
282
		$this->Task->initValidations();
283
 
284
		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
285
		$expected = array('notEmpty' => 'notEmpty');
286
		$this->assertEquals($expected, $result);
287
 
288
		$result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false));
289
		$expected = array('date' => 'date');
290
		$this->assertEquals($expected, $result);
291
 
292
		$result = $this->Task->fieldValidation('text', array('type' => 'time', 'length' => 10, 'null' => false));
293
		$expected = array('time' => 'time');
294
		$this->assertEquals($expected, $result);
295
 
296
		$result = $this->Task->fieldValidation('email', array('type' => 'string', 'length' => 10, 'null' => false));
297
		$expected = array('email' => 'email');
298
		$this->assertEquals($expected, $result);
299
 
300
		$result = $this->Task->fieldValidation('test', array('type' => 'integer', 'length' => 10, 'null' => false));
301
		$expected = array('numeric' => 'numeric');
302
		$this->assertEquals($expected, $result);
303
 
304
		$result = $this->Task->fieldValidation('test', array('type' => 'boolean', 'length' => 10, 'null' => false));
305
		$expected = array('boolean' => 'boolean');
306
		$this->assertEquals($expected, $result);
307
	}
308
 
309
/**
310
 * test that interactive field validation works and returns multiple validators.
311
 *
312
 * @return void
313
 */
314
	public function testInteractiveFieldValidation() {
315
		$this->Task->initValidations();
316
		$this->Task->interactive = true;
317
		$this->Task->expects($this->any())->method('in')
318
			->will($this->onConsecutiveCalls('25', 'y', '19', 'n'));
319
 
320
		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
321
		$expected = array('notEmpty' => 'notEmpty', 'maxLength' => 'maxLength');
322
		$this->assertEquals($expected, $result);
323
	}
324
 
325
/**
326
 * test that a bogus response doesn't cause errors to bubble up.
327
 *
328
 * @return void
329
 */
330
	public function testInteractiveFieldValidationWithBogusResponse() {
331
		$this->_useMockedOut();
332
		$this->Task->initValidations();
333
		$this->Task->interactive = true;
334
 
335
		$this->Task->expects($this->any())->method('in')
336
			->will($this->onConsecutiveCalls('999999', '25', 'n'));
337
 
338
		$this->Task->expects($this->at(10))->method('out')
339
			->with($this->stringContains('make a valid'));
340
 
341
		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
342
		$expected = array('notEmpty' => 'notEmpty');
343
		$this->assertEquals($expected, $result);
344
	}
345
 
346
/**
347
 * test that a regular expression can be used for validation.
348
 *
349
 * @return void
350
 */
351
	public function testInteractiveFieldValidationWithRegexp() {
352
		$this->Task->initValidations();
353
		$this->Task->interactive = true;
354
		$this->Task->expects($this->any())->method('in')
355
			->will($this->onConsecutiveCalls('/^[a-z]{0,9}$/', 'n'));
356
 
357
		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
358
		$expected = array('a_z_0_9' => '/^[a-z]{0,9}$/');
359
		$this->assertEquals($expected, $result);
360
	}
361
 
362
/**
363
 * Test that skipping fields during rule choice works when doing interactive field validation.
364
 *
365
 * @return void
366
 */
367
	public function testSkippingChoiceInteractiveFieldValidation() {
368
		$this->Task->initValidations();
369
		$this->Task->interactive = true;
370
		$this->Task->expects($this->any())->method('in')
371
			->will($this->onConsecutiveCalls('25', 'y', 's'));
372
 
373
		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
374
		$expected = array('notEmpty' => 'notEmpty', '_skipFields' => true);
375
		$this->assertEquals($expected, $result);
376
	}
377
 
378
/**
379
 * Test that skipping fields after rule choice works when doing interactive field validation.
380
 *
381
 * @return void
382
 */
383
	public function testSkippingAnotherInteractiveFieldValidation() {
384
		$this->Task->initValidations();
385
		$this->Task->interactive = true;
386
		$this->Task->expects($this->any())->method('in')
387
			->will($this->onConsecutiveCalls('25', 's'));
388
 
389
		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
390
		$expected = array('notEmpty' => 'notEmpty', '_skipFields' => true);
391
		$this->assertEquals($expected, $result);
392
	}
393
 
394
/**
395
 * Test the validation generation routine with skipping the rest of the fields
396
 * when doing interactive field validation.
397
 *
398
 * @return void
399
 */
400
	public function testInteractiveDoValidationWithSkipping() {
401
		$this->Task->expects($this->any())
402
			->method('in')
403
			->will($this->onConsecutiveCalls('36', '25', 'n', '11', 's'));
404
		$this->Task->interactive = true;
405
		$Model = $this->getMock('Model');
406
		$Model->primaryKey = 'id';
407
		$Model->expects($this->any())
408
			->method('schema')
409
			->will($this->returnValue(array(
410
					'id' => array(
411
						'type' => 'integer',
412
						'length' => 11,
413
						'null' => false,
414
						'key' => 'primary',
415
					),
416
					'name' => array(
417
						'type' => 'string',
418
						'length' => 20,
419
						'null' => false,
420
					),
421
					'email' => array(
422
						'type' => 'string',
423
						'length' => 255,
424
						'null' => false,
425
					),
426
					'some_date' => array(
427
						'type' => 'date',
428
						'length' => '',
429
						'null' => false,
430
					),
431
					'some_time' => array(
432
						'type' => 'time',
433
						'length' => '',
434
						'null' => false,
435
					),
436
					'created' => array(
437
						'type' => 'datetime',
438
						'length' => '',
439
						'null' => false,
440
					)
441
				)
442
			));
443
 
444
		$result = $this->Task->doValidation($Model);
445
		$expected = array(
446
			'name' => array(
447
				'notEmpty' => 'notEmpty'
448
			),
449
			'email' => array(
450
				'email' => 'email',
451
			),
452
		);
453
		$this->assertEquals($expected, $result);
454
	}
455
 
456
/**
457
 * test the validation Generation routine
458
 *
459
 * @return void
460
 */
461
	public function testNonInteractiveDoValidation() {
462
		$Model = $this->getMock('Model');
463
		$Model->primaryKey = 'id';
464
		$Model->expects($this->any())
465
			->method('schema')
466
			->will($this->returnValue(array(
467
				'id' => array(
468
					'type' => 'integer',
469
					'length' => 11,
470
					'null' => false,
471
					'key' => 'primary',
472
				),
473
				'name' => array(
474
					'type' => 'string',
475
					'length' => 20,
476
					'null' => false,
477
				),
478
				'email' => array(
479
					'type' => 'string',
480
					'length' => 255,
481
					'null' => false,
482
				),
483
				'some_date' => array(
484
					'type' => 'date',
485
					'length' => '',
486
					'null' => false,
487
				),
488
				'some_time' => array(
489
					'type' => 'time',
490
					'length' => '',
491
					'null' => false,
492
				),
493
				'created' => array(
494
					'type' => 'datetime',
495
					'length' => '',
496
					'null' => false,
497
				)
498
			)
499
		));
500
		$this->Task->interactive = false;
501
 
502
		$result = $this->Task->doValidation($Model);
503
		$expected = array(
504
			'name' => array(
505
				'notEmpty' => 'notEmpty'
506
			),
507
			'email' => array(
508
				'email' => 'email',
509
			),
510
			'some_date' => array(
511
				'date' => 'date'
512
			),
513
			'some_time' => array(
514
				'time' => 'time'
515
			),
516
		);
517
		$this->assertEquals($expected, $result);
518
	}
519
 
520
/**
521
 * test that finding primary key works
522
 *
523
 * @return void
524
 */
525
	public function testFindPrimaryKey() {
526
		$fields = array(
527
			'one' => array(),
528
			'two' => array(),
529
			'key' => array('key' => 'primary')
530
		);
531
		$anything = new PHPUnit_Framework_Constraint_IsAnything();
532
		$this->Task->expects($this->once())->method('in')
533
			->with($anything, null, 'key')
534
			->will($this->returnValue('my_field'));
535
 
536
		$result = $this->Task->findPrimaryKey($fields);
537
		$expected = 'my_field';
538
		$this->assertEquals($expected, $result);
539
	}
540
 
541
/**
542
 * test finding Display field
543
 *
544
 * @return void
545
 */
546
	public function testFindDisplayFieldNone() {
547
		$fields = array(
548
			'id' => array(), 'tagname' => array(), 'body' => array(),
549
			'created' => array(), 'modified' => array()
550
		);
551
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
552
		$result = $this->Task->findDisplayField($fields);
553
		$this->assertFalse($result);
554
	}
555
 
556
/**
557
 * Test finding a displayname from user input
558
 *
559
 * @return void
560
 */
561
	public function testFindDisplayName() {
562
		$fields = array(
563
			'id' => array(), 'tagname' => array(), 'body' => array(),
564
			'created' => array(), 'modified' => array()
565
		);
566
		$this->Task->expects($this->any())->method('in')
567
			->will($this->onConsecutiveCalls('y', 2));
568
 
569
		$result = $this->Task->findDisplayField($fields);
570
		$this->assertEquals('tagname', $result);
571
	}
572
 
573
/**
574
 * test that belongsTo generation works.
575
 *
576
 * @return void
577
 */
578
	public function testBelongsToGeneration() {
579
		$model = new Model(array('ds' => 'test', 'name' => 'BakeComment'));
580
		$result = $this->Task->findBelongsTo($model, array());
581
		$expected = array(
582
			'belongsTo' => array(
583
				array(
584
					'alias' => 'BakeArticle',
585
					'className' => 'BakeArticle',
586
					'foreignKey' => 'bake_article_id',
587
				),
588
				array(
589
					'alias' => 'BakeUser',
590
					'className' => 'BakeUser',
591
					'foreignKey' => 'bake_user_id',
592
				),
593
			)
594
		);
595
		$this->assertEquals($expected, $result);
596
 
597
		$model = new Model(array('ds' => 'test', 'name' => 'CategoryThread'));
598
		$result = $this->Task->findBelongsTo($model, array());
599
		$expected = array(
600
			'belongsTo' => array(
601
				array(
602
					'alias' => 'ParentCategoryThread',
603
					'className' => 'CategoryThread',
604
					'foreignKey' => 'parent_id',
605
				),
606
			)
607
		);
608
		$this->assertEquals($expected, $result);
609
	}
610
 
611
/**
612
 * test that hasOne and/or hasMany relations are generated properly.
613
 *
614
 * @return void
615
 */
616
	public function testHasManyHasOneGeneration() {
617
		$model = new Model(array('ds' => 'test', 'name' => 'BakeArticle'));
618
		$this->Task->connection = 'test';
619
		$this->Task->listAll();
620
		$result = $this->Task->findHasOneAndMany($model, array());
621
		$expected = array(
622
			'hasMany' => array(
623
				array(
624
					'alias' => 'BakeComment',
625
					'className' => 'BakeComment',
626
					'foreignKey' => 'bake_article_id',
627
				),
628
			),
629
			'hasOne' => array(
630
				array(
631
					'alias' => 'BakeComment',
632
					'className' => 'BakeComment',
633
					'foreignKey' => 'bake_article_id',
634
				),
635
			),
636
		);
637
		$this->assertEquals($expected, $result);
638
 
639
		$model = new Model(array('ds' => 'test', 'name' => 'CategoryThread'));
640
		$result = $this->Task->findHasOneAndMany($model, array());
641
		$expected = array(
642
			'hasOne' => array(
643
				array(
644
					'alias' => 'ChildCategoryThread',
645
					'className' => 'CategoryThread',
646
					'foreignKey' => 'parent_id',
647
				),
648
			),
649
			'hasMany' => array(
650
				array(
651
					'alias' => 'ChildCategoryThread',
652
					'className' => 'CategoryThread',
653
					'foreignKey' => 'parent_id',
654
				),
655
			)
656
		);
657
		$this->assertEquals($expected, $result);
658
	}
659
 
660
/**
661
 * Test that HABTM generation works
662
 *
663
 * @return void
664
 */
665
	public function testHasAndBelongsToManyGeneration() {
666
		$model = new Model(array('ds' => 'test', 'name' => 'BakeArticle'));
667
		$this->Task->connection = 'test';
668
		$this->Task->listAll();
669
		$result = $this->Task->findHasAndBelongsToMany($model, array());
670
		$expected = array(
671
			'hasAndBelongsToMany' => array(
672
				array(
673
					'alias' => 'BakeTag',
674
					'className' => 'BakeTag',
675
					'foreignKey' => 'bake_article_id',
676
					'joinTable' => 'bake_articles_bake_tags',
677
					'associationForeignKey' => 'bake_tag_id',
678
				),
679
			),
680
		);
681
		$this->assertEquals($expected, $result);
682
	}
683
 
684
/**
685
 * test non interactive doAssociations
686
 *
687
 * @return void
688
 */
689
	public function testDoAssociationsNonInteractive() {
690
		$this->Task->connection = 'test';
691
		$this->Task->interactive = false;
692
		$model = new Model(array('ds' => 'test', 'name' => 'BakeArticle'));
693
		$result = $this->Task->doAssociations($model);
694
		$expected = array(
695
			'belongsTo' => array(
696
				array(
697
					'alias' => 'BakeUser',
698
					'className' => 'BakeUser',
699
					'foreignKey' => 'bake_user_id',
700
				),
701
			),
702
			'hasMany' => array(
703
				array(
704
					'alias' => 'BakeComment',
705
					'className' => 'BakeComment',
706
					'foreignKey' => 'bake_article_id',
707
				),
708
			),
709
			'hasAndBelongsToMany' => array(
710
				array(
711
					'alias' => 'BakeTag',
712
					'className' => 'BakeTag',
713
					'foreignKey' => 'bake_article_id',
714
					'joinTable' => 'bake_articles_bake_tags',
715
					'associationForeignKey' => 'bake_tag_id',
716
				),
717
			),
718
		);
719
		$this->assertEquals($expected, $result);
720
	}
721
 
722
/**
723
 * test non interactive doActsAs
724
 *
725
 * @return void
726
 */
727
	public function testDoActsAs() {
728
		$this->Task->connection = 'test';
729
		$this->Task->interactive = false;
730
		$model = new Model(array('ds' => 'test', 'name' => 'NumberTree'));
731
		$result = $this->Task->doActsAs($model);
732
 
733
		$this->assertEquals(array('Tree'), $result);
734
	}
735
 
736
/**
737
 * Ensure that the fixture object is correctly called.
738
 *
739
 * @return void
740
 */
741
	public function testBakeFixture() {
742
		$this->Task->plugin = 'TestPlugin';
743
		$this->Task->interactive = true;
744
		$this->Task->Fixture->expects($this->at(0))->method('bake')->with('BakeArticle', 'bake_articles');
745
		$this->Task->bakeFixture('BakeArticle', 'bake_articles');
746
 
747
		$this->assertEquals($this->Task->plugin, $this->Task->Fixture->plugin);
748
		$this->assertEquals($this->Task->connection, $this->Task->Fixture->connection);
749
		$this->assertEquals($this->Task->interactive, $this->Task->Fixture->interactive);
750
	}
751
 
752
/**
753
 * Ensure that the test object is correctly called.
754
 *
755
 * @return void
756
 */
757
	public function testBakeTest() {
758
		$this->Task->plugin = 'TestPlugin';
759
		$this->Task->interactive = true;
760
		$this->Task->Test->expects($this->at(0))->method('bake')->with('Model', 'BakeArticle');
761
		$this->Task->bakeTest('BakeArticle');
762
 
763
		$this->assertEquals($this->Task->plugin, $this->Task->Test->plugin);
764
		$this->assertEquals($this->Task->connection, $this->Task->Test->connection);
765
		$this->assertEquals($this->Task->interactive, $this->Task->Test->interactive);
766
	}
767
 
768
/**
769
 * test confirming of associations, and that when an association is hasMany
770
 * a question for the hasOne is also not asked.
771
 *
772
 * @return void
773
 */
774
	public function testConfirmAssociations() {
775
		$associations = array(
776
			'hasOne' => array(
777
				array(
778
					'alias' => 'ChildCategoryThread',
779
					'className' => 'CategoryThread',
780
					'foreignKey' => 'parent_id',
781
				),
782
			),
783
			'hasMany' => array(
784
				array(
785
					'alias' => 'ChildCategoryThread',
786
					'className' => 'CategoryThread',
787
					'foreignKey' => 'parent_id',
788
				),
789
			),
790
			'belongsTo' => array(
791
				array(
792
					'alias' => 'User',
793
					'className' => 'User',
794
					'foreignKey' => 'user_id',
795
				),
796
			)
797
		);
798
		$model = new Model(array('ds' => 'test', 'name' => 'CategoryThread'));
799
 
800
		$this->Task->expects($this->any())->method('in')
801
			->will($this->onConsecutiveCalls('n', 'y', 'n', 'n', 'n'));
802
 
803
		$result = $this->Task->confirmAssociations($model, $associations);
804
		$this->assertTrue(empty($result['hasOne']));
805
 
806
		$result = $this->Task->confirmAssociations($model, $associations);
807
		$this->assertTrue(empty($result['hasMany']));
808
		$this->assertTrue(empty($result['hasOne']));
809
	}
810
 
811
/**
812
 * test that inOptions generates questions and only accepts a valid answer
813
 *
814
 * @return void
815
 */
816
	public function testInOptions() {
817
		$this->_useMockedOut();
818
 
819
		$options = array('one', 'two', 'three');
820
		$this->Task->expects($this->at(0))->method('out')->with('1. one');
821
		$this->Task->expects($this->at(1))->method('out')->with('2. two');
822
		$this->Task->expects($this->at(2))->method('out')->with('3. three');
823
		$this->Task->expects($this->at(3))->method('in')->will($this->returnValue(10));
824
 
825
		$this->Task->expects($this->at(4))->method('out')->with('1. one');
826
		$this->Task->expects($this->at(5))->method('out')->with('2. two');
827
		$this->Task->expects($this->at(6))->method('out')->with('3. three');
828
		$this->Task->expects($this->at(7))->method('in')->will($this->returnValue(2));
829
		$result = $this->Task->inOptions($options, 'Pick a number');
830
		$this->assertEquals(1, $result);
831
	}
832
 
833
/**
834
 * test baking validation
835
 *
836
 * @return void
837
 */
838
	public function testBakeValidation() {
839
		$validate = array(
840
			'name' => array(
841
				'notempty' => 'notEmpty'
842
			),
843
			'email' => array(
844
				'email' => 'email',
845
			),
846
			'some_date' => array(
847
				'date' => 'date'
848
			),
849
			'some_time' => array(
850
				'time' => 'time'
851
			)
852
		);
853
		$result = $this->Task->bake('BakeArticle', compact('validate'));
854
		$this->assertRegExp('/class BakeArticle extends AppModel \{/', $result);
855
		$this->assertRegExp('/\$validate \= array\(/', $result);
856
		$expected = <<< STRINGEND
857
array(
858
			'notempty' => array(
859
				'rule' => array('notEmpty'),
860
				//'message' => 'Your custom message here',
861
				//'allowEmpty' => false,
862
				//'required' => false,
863
				//'last' => false, // Stop validation after this rule
864
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
865
			),
866
STRINGEND;
867
		$this->assertRegExp('/' . preg_quote(str_replace("\r\n", "\n", $expected), '/') . '/', $result);
868
	}
869
 
870
/**
871
 * test baking relations
872
 *
873
 * @return void
874
 */
875
	public function testBakeRelations() {
876
		$associations = array(
877
			'belongsTo' => array(
878
				array(
879
					'alias' => 'SomethingElse',
880
					'className' => 'SomethingElse',
881
					'foreignKey' => 'something_else_id',
882
				),
883
				array(
884
					'alias' => 'BakeUser',
885
					'className' => 'BakeUser',
886
					'foreignKey' => 'bake_user_id',
887
				),
888
			),
889
			'hasOne' => array(
890
				array(
891
					'alias' => 'OtherModel',
892
					'className' => 'OtherModel',
893
					'foreignKey' => 'other_model_id',
894
				),
895
			),
896
			'hasMany' => array(
897
				array(
898
					'alias' => 'BakeComment',
899
					'className' => 'BakeComment',
900
					'foreignKey' => 'parent_id',
901
				),
902
			),
903
			'hasAndBelongsToMany' => array(
904
				array(
905
					'alias' => 'BakeTag',
906
					'className' => 'BakeTag',
907
					'foreignKey' => 'bake_article_id',
908
					'joinTable' => 'bake_articles_bake_tags',
909
					'associationForeignKey' => 'bake_tag_id',
910
				),
911
			)
912
		);
913
		$result = $this->Task->bake('BakeArticle', compact('associations'));
914
		$this->assertContains(' * @property BakeUser $BakeUser', $result);
915
		$this->assertContains(' * @property OtherModel $OtherModel', $result);
916
		$this->assertContains(' * @property BakeComment $BakeComment', $result);
917
		$this->assertContains(' * @property BakeTag $BakeTag', $result);
918
		$this->assertRegExp('/\$hasAndBelongsToMany \= array\(/', $result);
919
		$this->assertRegExp('/\$hasMany \= array\(/', $result);
920
		$this->assertRegExp('/\$belongsTo \= array\(/', $result);
921
		$this->assertRegExp('/\$hasOne \= array\(/', $result);
922
		$this->assertRegExp('/BakeTag/', $result);
923
		$this->assertRegExp('/OtherModel/', $result);
924
		$this->assertRegExp('/SomethingElse/', $result);
925
		$this->assertRegExp('/BakeComment/', $result);
926
	}
927
 
928
/**
929
 * test bake() with a -plugin param
930
 *
931
 * @return void
932
 */
933
	public function testBakeWithPlugin() {
934
		$this->Task->plugin = 'ControllerTest';
935
 
936
		//fake plugin path
937
		CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));
938
		$path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Model' . DS . 'BakeArticle.php';
939
		$this->Task->expects($this->once())->method('createFile')
940
			->with($path, $this->stringContains('BakeArticle extends ControllerTestAppModel'));
941
 
942
		$result = $this->Task->bake('BakeArticle', array(), array());
943
		$this->assertContains("App::uses('ControllerTestAppModel', 'ControllerTest.Model');", $result);
944
 
945
		$this->assertEquals(count(ClassRegistry::keys()), 0);
946
		$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
947
	}
948
 
949
/**
950
 * test bake() for models with behaviors
951
 *
952
 * @return void
953
 */
954
	public function testBakeWithBehaviors() {
955
		$result = $this->Task->bake('NumberTree', array('actsAs' => array('Tree', 'PluginName.Sluggable')));
956
		$expected = <<<TEXT
957
/**
958
 * Behaviors
959
 *
960
 * @var array
961
 */
962
	public \$actsAs = array(
963
		'Tree',
964
		'PluginName.Sluggable',
965
	);
966
TEXT;
967
		$this->assertTextContains($expected, $result);
968
	}
969
 
970
/**
971
 * test that execute passes runs bake depending with named model.
972
 *
973
 * @return void
974
 */
975
	public function testExecuteWithNamedModel() {
976
		$this->Task->connection = 'test';
977
		$this->Task->path = '/my/path/';
978
		$this->Task->args = array('BakeArticle');
979
		$filename = '/my/path/BakeArticle.php';
980
 
981
		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
982
		$this->Task->expects($this->once())->method('createFile')
983
			->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
984
 
985
		$this->Task->execute();
986
 
987
		$this->assertEquals(count(ClassRegistry::keys()), 0);
988
		$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
989
	}
990
 
991
/**
992
 * data provider for testExecuteWithNamedModelVariations
993
 *
994
 * @return void
995
 */
996
	public static function nameVariations() {
997
		return array(
998
			array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
999
		);
1000
	}
1001
 
1002
/**
1003
 * test that execute passes with different inflections of the same name.
1004
 *
1005
 * @dataProvider nameVariations
1006
 * @return void
1007
 */
1008
	public function testExecuteWithNamedModelVariations($name) {
1009
		$this->Task->connection = 'test';
1010
		$this->Task->path = '/my/path/';
1011
		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
1012
 
1013
		$this->Task->args = array($name);
1014
		$filename = '/my/path/BakeArticle.php';
1015
 
1016
		$this->Task->expects($this->at(0))->method('createFile')
1017
			->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
1018
		$this->Task->execute();
1019
	}
1020
 
1021
/**
1022
 * test that execute with a model name picks up hasMany associations.
1023
 *
1024
 * @return void
1025
 */
1026
	public function testExecuteWithNamedModelHasManyCreated() {
1027
		$this->Task->connection = 'test';
1028
		$this->Task->path = '/my/path/';
1029
		$this->Task->args = array('BakeArticle');
1030
		$filename = '/my/path/BakeArticle.php';
1031
 
1032
		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
1033
		$this->Task->expects($this->at(0))->method('createFile')
1034
			->with($filename, $this->stringContains("'BakeComment' => array("));
1035
 
1036
		$this->Task->execute();
1037
	}
1038
 
1039
/**
1040
 * test that execute runs all() when args[0] = all
1041
 *
1042
 * @return void
1043
 */
1044
	public function testExecuteIntoAll() {
1045
		$count = count($this->Task->listAll('test'));
1046
		if ($count != count($this->fixtures)) {
1047
			$this->markTestSkipped('Additional tables detected.');
1048
		}
1049
 
1050
		$this->Task->connection = 'test';
1051
		$this->Task->path = '/my/path/';
1052
		$this->Task->args = array('all');
1053
		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
1054
 
1055
		$this->Task->Fixture->expects($this->exactly(6))->method('bake');
1056
		$this->Task->Test->expects($this->exactly(6))->method('bake');
1057
 
1058
		$filename = '/my/path/BakeArticle.php';
1059
		$this->Task->expects($this->at(1))->method('createFile')
1060
			->with($filename, $this->stringContains('class BakeArticle'));
1061
 
1062
		$filename = '/my/path/BakeArticlesBakeTag.php';
1063
		$this->Task->expects($this->at(2))->method('createFile')
1064
			->with($filename, $this->stringContains('class BakeArticlesBakeTag'));
1065
 
1066
		$filename = '/my/path/BakeComment.php';
1067
		$this->Task->expects($this->at(3))->method('createFile')
1068
			->with($filename, $this->stringContains('class BakeComment'));
1069
 
1070
		$filename = '/my/path/BakeComment.php';
1071
		$this->Task->expects($this->at(3))->method('createFile')
1072
			->with($filename, $this->stringContains('public $primaryKey = \'otherid\';'));
1073
 
1074
		$filename = '/my/path/BakeTag.php';
1075
		$this->Task->expects($this->at(4))->method('createFile')
1076
			->with($filename, $this->stringContains('class BakeTag'));
1077
 
1078
		$filename = '/my/path/BakeTag.php';
1079
		$this->Task->expects($this->at(4))->method('createFile')
1080
			->with($filename, $this->logicalNot($this->stringContains('public $primaryKey')));
1081
 
1082
		$filename = '/my/path/CategoryThread.php';
1083
		$this->Task->expects($this->at(5))->method('createFile')
1084
			->with($filename, $this->stringContains('class CategoryThread'));
1085
 
1086
		$filename = '/my/path/NumberTree.php';
1087
		$this->Task->expects($this->at(6))->method('createFile')
1088
			->with($filename, $this->stringContains('class NumberTree'));
1089
 
1090
		$this->Task->execute();
1091
 
1092
		$this->assertEquals(count(ClassRegistry::keys()), 0);
1093
		$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
1094
	}
1095
 
1096
/**
1097
 * test that odd tablenames aren't inflected back from modelname
1098
 *
1099
 * @return void
1100
 */
1101
	public function testExecuteIntoAllOddTables() {
1102
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
1103
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
1104
		$this->Task = $this->getMock('ModelTask',
1105
			array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'bake', 'bakeFixture'),
1106
			array($out, $out, $in)
1107
		);
1108
		$this->_setupOtherMocks();
1109
 
1110
		$this->Task->connection = 'test';
1111
		$this->Task->path = '/my/path/';
1112
		$this->Task->args = array('all');
1113
		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
1114
		$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('bake_odd')));
1115
		$object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
1116
		$this->Task->expects($this->once())->method('_getModelObject')->with('BakeOdd', 'bake_odd')->will($this->returnValue($object));
1117
		$this->Task->expects($this->at(3))->method('bake')->with($object, false)->will($this->returnValue(true));
1118
		$this->Task->expects($this->once())->method('bakeFixture')->with('BakeOdd', 'bake_odd');
1119
 
1120
		$this->Task->execute();
1121
 
1122
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
1123
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
1124
		$this->Task = $this->getMock('ModelTask',
1125
			array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'doActsAs', 'createFile'),
1126
			array($out, $out, $in)
1127
		);
1128
		$this->_setupOtherMocks();
1129
 
1130
		$this->Task->connection = 'test';
1131
		$this->Task->path = '/my/path/';
1132
		$this->Task->args = array('all');
1133
		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
1134
		$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('bake_odd')));
1135
		$object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
1136
		$this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object));
1137
		$this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array()));
1138
		$this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array()));
1139
		$this->Task->expects($this->once())->method('doActsAs')->will($this->returnValue(array()));
1140
 
1141
		$filename = '/my/path/BakeOdd.php';
1142
		$this->Task->expects($this->once())->method('createFile')
1143
			->with($filename, $this->stringContains('class BakeOdd'));
1144
 
1145
		$filename = '/my/path/BakeOdd.php';
1146
		$this->Task->expects($this->once())->method('createFile')
1147
			->with($filename, $this->stringContains('public $useTable = \'bake_odd\''));
1148
 
1149
		$this->Task->execute();
1150
	}
1151
 
1152
/**
1153
 * test that odd tablenames aren't inflected back from modelname
1154
 *
1155
 * @return void
1156
 */
1157
	public function testExecuteIntoBakeOddTables() {
1158
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
1159
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
1160
		$this->Task = $this->getMock('ModelTask',
1161
			array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'bake', 'bakeFixture'),
1162
			array($out, $out, $in)
1163
		);
1164
		$this->_setupOtherMocks();
1165
 
1166
		$this->Task->connection = 'test';
1167
		$this->Task->path = '/my/path/';
1168
		$this->Task->args = array('BakeOdd');
1169
		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
1170
		$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
1171
		$object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
1172
		$this->Task->expects($this->once())->method('_getModelObject')->with('BakeOdd', 'bake_odd')->will($this->returnValue($object));
1173
		$this->Task->expects($this->once())->method('bake')->with($object, false)->will($this->returnValue(true));
1174
		$this->Task->expects($this->once())->method('bakeFixture')->with('BakeOdd', 'bake_odd');
1175
 
1176
		$this->Task->execute();
1177
 
1178
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
1179
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
1180
		$this->Task = $this->getMock('ModelTask',
1181
			array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'doActsAs', 'createFile'),
1182
			array($out, $out, $in)
1183
		);
1184
		$this->_setupOtherMocks();
1185
 
1186
		$this->Task->connection = 'test';
1187
		$this->Task->path = '/my/path/';
1188
		$this->Task->args = array('BakeOdd');
1189
		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
1190
		$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
1191
		$object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
1192
		$this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object));
1193
		$this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array()));
1194
		$this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array()));
1195
		$this->Task->expects($this->once())->method('doActsAs')->will($this->returnValue(array()));
1196
 
1197
		$filename = '/my/path/BakeOdd.php';
1198
		$this->Task->expects($this->once())->method('createFile')
1199
			->with($filename, $this->stringContains('class BakeOdd'));
1200
 
1201
		$filename = '/my/path/BakeOdd.php';
1202
		$this->Task->expects($this->once())->method('createFile')
1203
			->with($filename, $this->stringContains('public $useTable = \'bake_odd\''));
1204
 
1205
		$this->Task->execute();
1206
	}
1207
 
1208
/**
1209
 * test that skipTables changes how all() works.
1210
 *
1211
 * @return void
1212
 */
1213
	public function testSkipTablesAndAll() {
1214
		$count = count($this->Task->listAll('test'));
1215
		if ($count != count($this->fixtures)) {
1216
			$this->markTestSkipped('Additional tables detected.');
1217
		}
1218
 
1219
		$this->Task->connection = 'test';
1220
		$this->Task->path = '/my/path/';
1221
		$this->Task->args = array('all');
1222
		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
1223
		$this->Task->skipTables = array('bake_tags', 'number_trees');
1224
 
1225
		$this->Task->Fixture->expects($this->exactly(4))->method('bake');
1226
		$this->Task->Test->expects($this->exactly(4))->method('bake');
1227
 
1228
		$filename = '/my/path/BakeArticle.php';
1229
		$this->Task->expects($this->at(1))->method('createFile')
1230
			->with($filename, $this->stringContains('class BakeArticle'));
1231
 
1232
		$filename = '/my/path/BakeArticlesBakeTag.php';
1233
		$this->Task->expects($this->at(2))->method('createFile')
1234
			->with($filename, $this->stringContains('class BakeArticlesBakeTag'));
1235
 
1236
		$filename = '/my/path/BakeComment.php';
1237
		$this->Task->expects($this->at(3))->method('createFile')
1238
			->with($filename, $this->stringContains('class BakeComment'));
1239
 
1240
		$filename = '/my/path/CategoryThread.php';
1241
		$this->Task->expects($this->at(4))->method('createFile')
1242
			->with($filename, $this->stringContains('class CategoryThread'));
1243
 
1244
		$this->Task->execute();
1245
	}
1246
 
1247
/**
1248
 * test the interactive side of bake.
1249
 *
1250
 * @return void
1251
 */
1252
	public function testExecuteIntoInteractive() {
1253
		$tables = $this->Task->listAll('test');
1254
		$article = array_search('bake_articles', $tables) + 1;
1255
 
1256
		$this->Task->connection = 'test';
1257
		$this->Task->path = '/my/path/';
1258
		$this->Task->interactive = true;
1259
 
1260
		$this->Task->expects($this->any())->method('in')
1261
			->will($this->onConsecutiveCalls(
1262
				$article, // article
1263
				'n', // no validation
1264
				'y', // associations
1265
				'y', // comment relation
1266
				'y', // user relation
1267
				'y', // tag relation
1268
				'n', // additional assocs
1269
				'y' // looks good?
1270
			));
1271
		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
1272
 
1273
		$this->Task->Test->expects($this->once())->method('bake');
1274
		$this->Task->Fixture->expects($this->once())->method('bake');
1275
 
1276
		$filename = '/my/path/BakeArticle.php';
1277
 
1278
		$this->Task->expects($this->once())->method('createFile')
1279
			->with($filename, $this->stringContains('class BakeArticle'));
1280
 
1281
		$this->Task->execute();
1282
 
1283
		$this->assertEquals(count(ClassRegistry::keys()), 0);
1284
		$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
1285
	}
1286
 
1287
/**
1288
 * test using bake interactively with a table that does not exist.
1289
 *
1290
 * @return void
1291
 */
1292
	public function testExecuteWithNonExistantTableName() {
1293
		$this->Task->connection = 'test';
1294
		$this->Task->path = '/my/path/';
1295
 
1296
		$this->Task->expects($this->any())->method('in')
1297
			->will($this->onConsecutiveCalls(
1298
				'Foobar', // Or type in the name of the model
1299
				'y', // Do you want to use this table
1300
				'n' // Doesn't exist, continue anyway?
1301
			));
1302
 
1303
		$this->Task->execute();
1304
	}
1305
 
1306
/**
1307
 * test using bake interactively with a table that does not exist.
1308
 *
1309
 * @return void
1310
 */
1311
	public function testForcedExecuteWithNonExistantTableName() {
1312
		$this->Task->connection = 'test';
1313
		$this->Task->path = '/my/path/';
1314
 
1315
		$this->Task->expects($this->any())->method('in')
1316
			->will($this->onConsecutiveCalls(
1317
				'Foobar', // Or type in the name of the model
1318
				'y', // Do you want to use this table
1319
				'y', // Doesn't exist, continue anyway?
1320
				'id', // Primary key
1321
				'y' // Looks good?
1322
			));
1323
 
1324
		$this->Task->execute();
1325
	}
1326
 
1327
}