cakephp2x /cake/tests/cases/console/libs/tasks/model.test.php

Language PHP Lines 773
MD5 Hash 952d9fc024357f7974b2db06186944a7
Repository https://github.com/msadouni/cakephp2x.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
<?php
/**
 * ModelTaskTest file
 *
 * Test Case for test generation shell task
 *
 * PHP Version 5.x
 *
 * CakePHP : Rapid Development Framework (http://cakephp.org)
 * Copyright 2006-2009, Cake Software Foundation, Inc.
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2006-2009, Cake Software Foundation, Inc.
 * @link          http://cakephp.org CakePHP Project
 * @package       cake
 * @subpackage    cake.tests.cases.console.libs.tasks
 * @since         CakePHP v 1.2.6
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
App::import('Shell', 'Shell', false);

if (!defined('DISABLE_AUTO_DISPATCH')) {
	define('DISABLE_AUTO_DISPATCH', true);
}

if (!class_exists('ShellDispatcher')) {
	ob_start();
	$argv = false;
	require CAKE . 'console' .  DS . 'cake.php';
	ob_end_clean();
}

require_once CAKE . 'console' .  DS . 'libs' . DS . 'tasks' . DS . 'model.php';
require_once CAKE . 'console' .  DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
require_once CAKE . 'console' .  DS . 'libs' . DS . 'tasks' . DS . 'template.php';

Mock::generatePartial(
	'ShellDispatcher', 'TestModelTaskMockShellDispatcher',
	array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
);
Mock::generatePartial(
	'ModelTask', 'MockModelTask',
	array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
);

Mock::generate(
	'Model', 'MockModelTaskModel'
);

Mock::generate(
	'FixtureTask', 'MockModelTaskFixtureTask'
);

/**
 * ModelTaskTest class
 *
 * @package       cake
 * @subpackage    cake.tests.cases.console.libs.tasks
 */
class ModelTaskTest extends CakeTestCase {

/**
 * fixtures
 *
 * @var array
 */
	public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag', 'core.category_thread');

/**
 * starTest method
 *
 * @return void
 * @access public
 */
	public function startTest() {
		$this->Dispatcher =& new TestModelTaskMockShellDispatcher();
		$this->Task =& new MockModelTask($this->Dispatcher);
		$this->Task->Dispatch =& $this->Dispatcher;
		$this->Task->Dispatch->shellPaths = App::path('shells');
		$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
		$this->Task->Fixture =& new MockModelTaskFixtureTask();
		$this->Task->Test =& new MockModelTaskFixtureTask();
	}

/**
 * endTest method
 *
 * @return void
 * @access public
 */
	public function endTest() {
		unset($this->Task, $this->Dispatcher);
		ClassRegistry::flush();
	}

/**
 * Test that listAll scans the database connection and lists all the tables in it.s
 *
 * @return void
 * @access public
 */
	public function testListAll() {
		$this->Task->expectAt(1, 'out', array('1. Article'));
		$this->Task->expectAt(2, 'out', array('2. ArticlesTag'));
		$this->Task->expectAt(3, 'out', array('3. CategoryThread'));
		$this->Task->expectAt(4, 'out', array('4. Comment'));
		$this->Task->expectAt(5, 'out', array('5. Tag'));
		$result = $this->Task->listAll('test_suite');
		$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
		$this->assertEqual($result, $expected);

		$this->Task->expectAt(7, 'out', array('1. Article'));
		$this->Task->expectAt(8, 'out', array('2. ArticlesTag'));
		$this->Task->expectAt(9, 'out', array('3. CategoryThread'));
		$this->Task->expectAt(10, 'out', array('4. Comment'));
		$this->Task->expectAt(11, 'out', array('5. Tag'));

		$this->Task->connection = 'test_suite';
		$result = $this->Task->listAll();
		$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
		$this->assertEqual($result, $expected);
	}

/**
 * Test that getName interacts with the user and returns the model name.
 *
 * @return void
 * @access public
 */
	public function testGetName() {
		$this->Task->setReturnValue('in', 1);

		$this->Task->setReturnValueAt(0, 'in', 'q');
		$this->Task->expectOnce('_stop');
		$this->Task->getName('test_suite');

		$this->Task->setReturnValueAt(1, 'in', 1);
		$result = $this->Task->getName('test_suite');
		$expected = 'Article';
		$this->assertEqual($result, $expected);

		$this->Task->setReturnValueAt(2, 'in', 4);
		$result = $this->Task->getName('test_suite');
		$expected = 'Comment';
		$this->assertEqual($result, $expected);

		$this->Task->setReturnValueAt(3, 'in', 10);
		$result = $this->Task->getName('test_suite');
		$this->Task->expectOnce('err');
	}

/**
 * Test table name interactions
 *
 * @return void
 * @access public
 */
	public function testGetTableName() {
		$this->Task->setReturnValueAt(0, 'in', 'y');
		$result = $this->Task->getTable('Article', 'test_suite');
		$expected = 'articles';
		$this->assertEqual($result, $expected);

		$this->Task->setReturnValueAt(1, 'in', 'n');
		$this->Task->setReturnValueAt(2, 'in', 'my_table');
		$result = $this->Task->getTable('Article', 'test_suite');
		$expected = 'my_table';
		$this->assertEqual($result, $expected);
	}

/**
 * test that initializing the validations works.
 *
 * @return void
 * @access public
 */
	public function testInitValidations() {
		$result = $this->Task->initValidations();
		$this->assertTrue(in_array('notempty', $result));
	}

/**
 * test that individual field validation works, with interactive = false
 * tests the guessing features of validation
 *
 * @return void
 * @access public
 */
	public function testFieldValidationGuessing() {
		$this->Task->interactive = false;
		$this->Task->initValidations();

		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
		$expected = array('notempty' => 'notempty');

		$result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false));
		$expected = array('date' => 'date');

		$result = $this->Task->fieldValidation('text', array('type' => 'time', 'length' => 10, 'null' => false));
		$expected = array('time' => 'time');

		$result = $this->Task->fieldValidation('email', array('type' => 'string', 'length' => 10, 'null' => false));
		$expected = array('email' => 'email');

		$result = $this->Task->fieldValidation('test', array('type' => 'integer', 'length' => 10, 'null' => false));
		$expected = array('numeric' => 'numeric');

		$result = $this->Task->fieldValidation('test', array('type' => 'boolean', 'length' => 10, 'null' => false));
		$expected = array('numeric' => 'numeric');
	}

/**
 * test that interactive field validation works and returns multiple validators.
 *
 * @return void
 * @access public
 */
	public function testInteractiveFieldValidation() {
		$this->Task->initValidations();
		$this->Task->interactive = true;
		$this->Task->setReturnValueAt(0, 'in', '20');
		$this->Task->setReturnValueAt(1, 'in', 'y');
		$this->Task->setReturnValueAt(2, 'in', '16');
		$this->Task->setReturnValueAt(3, 'in', 'n');

		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
		$expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength');
		$this->assertEqual($result, $expected);
	}

/**
 * test the validation Generation routine
 *
 * @return void
 * @access public
 */
	public function testNonInteractiveDoValidation() {
		$Model =& new MockModelTaskModel();
		$Model->primaryKey = 'id';
		$Model->setReturnValue('schema', array(
			'id' => array(
				'type' => 'integer',
				'length' => 11,
				'null' => false,
				'key' => 'primary',
			),
			'name' => array(
				'type' => 'string',
				'length' => 20,
				'null' => false,
			),
			'email' => array(
				'type' => 'string',
				'length' => 255,
				'null' => false,
			),
			'some_date' => array(
				'type' => 'date',
				'length' => '',
				'null' => false,
			),
			'some_time' => array(
				'type' => 'time',
				'length' => '',
				'null' => false,
			),
			'created' => array(
				'type' => 'datetime',
				'length' => '',
				'null' => false,
			)
		));
		$this->Task->interactive = false;

		$result = $this->Task->doValidation($Model);
		$expected = array(
			'name' => array(
				'notempty' => 'notempty'
			),
			'email' => array(
				'email' => 'email',
			),
			'some_date' => array(
				'date' => 'date'
			),
			'some_time' => array(
				'time' => 'time'
			),
		);
		$this->assertEqual($result, $expected);
	}

/**
 * test that finding primary key works
 *
 * @return void
 * @access public
 */
	public function testFindPrimaryKey() {
		$fields = array(
			'one' => array(),
			'two' => array(),
			'key' => array('key' => 'primary')
		);
		$this->Task->expectAt(0, 'in', array('*', null, 'key'));
		$this->Task->setReturnValue('in', 'my_field');
		$result = $this->Task->findPrimaryKey($fields);
		$expected = 'my_field';
		$this->assertEqual($result, $expected);
	}

/**
 * test finding Display field
 *
 * @return void
 * @access public
 */
	public function testFindDisplayField() {
		$fields = array('id' => array(), 'tagname' => array(), 'body' => array(),
			'created' => array(), 'modified' => array());

		$this->Task->setReturnValue('in', 'n');
		$this->Task->setReturnValueAt(0, 'in', 'n');
		$result = $this->Task->findDisplayField($fields);
		$this->assertFalse($result);

		$this->Task->setReturnValueAt(1, 'in', 'y');
		$this->Task->setReturnValueAt(2, 'in', 2);
		$result = $this->Task->findDisplayField($fields);
		$this->assertEqual($result, 'tagname');
	}

/**
 * test that belongsTo generation works.
 *
 * @return void
 * @access public
 */
	public function testBelongsToGeneration() {
		$model = new Model(array('ds' => 'test_suite', 'name' => 'Comment'));
		$result = $this->Task->findBelongsTo($model, array());
		$expected = array(
			'belongsTo' => array(
				array(
					'alias' => 'Article',
					'className' => 'Article',
					'foreignKey' => 'article_id',
				),
				array(
					'alias' => 'User',
					'className' => 'User',
					'foreignKey' => 'user_id',
				),
			)
		);
		$this->assertEqual($result, $expected);

		$model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
		$result = $this->Task->findBelongsTo($model, array());
		$expected = array(
			'belongsTo' => array(
				array(
					'alias' => 'ParentCategoryThread',
					'className' => 'CategoryThread',
					'foreignKey' => 'parent_id',
				),
			)
		);
		$this->assertEqual($result, $expected);
	}

/**
 * test that hasOne and/or hasMany relations are generated properly.
 *
 * @return void
 * @access public
 */
	public function testHasManyHasOneGeneration() {
		$model = new Model(array('ds' => 'test_suite', 'name' => 'Article'));
		$this->Task->connection = 'test_suite';
		$this->Task->listAll();
		$result = $this->Task->findHasOneAndMany($model, array());
		$expected = array(
			'hasMany' => array(
				array(
					'alias' => 'Comment',
					'className' => 'Comment',
					'foreignKey' => 'article_id',
				),
			),
			'hasOne' => array(
				array(
					'alias' => 'Comment',
					'className' => 'Comment',
					'foreignKey' => 'article_id',
				),
			),
		);
		$this->assertEqual($result, $expected);

		$model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
		$result = $this->Task->findHasOneAndMany($model, array());
		$expected = array(
			'hasOne' => array(
				array(
					'alias' => 'ChildCategoryThread',
					'className' => 'CategoryThread',
					'foreignKey' => 'parent_id',
				),
			),
			'hasMany' => array(
				array(
					'alias' => 'ChildCategoryThread',
					'className' => 'CategoryThread',
					'foreignKey' => 'parent_id',
				),
			)
		);
		$this->assertEqual($result, $expected);
	}

/**
 * Test that HABTM generation works
 *
 * @return void
 * @access public
 */
	public function testHasAndBelongsToManyGeneration() {
		$model = new Model(array('ds' => 'test_suite', 'name' => 'Article'));
		$this->Task->connection = 'test_suite';
		$this->Task->listAll();
		$result = $this->Task->findHasAndBelongsToMany($model, array());
		$expected = array(
			'hasAndBelongsToMany' => array(
				array(
					'alias' => 'Tag',
					'className' => 'Tag',
					'foreignKey' => 'article_id',
					'joinTable' => 'articles_tags',
					'associationForeignKey' => 'tag_id',
				),
			),
		);
		$this->assertEqual($result, $expected);
	}

/**
 * test non interactive doAssociations
 *
 * @return void
 * @access public
 */
	public function testDoAssociationsNonInteractive() {
		$this->Task->connection = 'test_suite';
		$this->Task->interactive = false;
		$model = new Model(array('ds' => 'test_suite', 'name' => 'Article'));
		$result = $this->Task->doAssociations($model);
		$expected = array(
			'hasMany' => array(
				array(
					'alias' => 'Comment',
					'className' => 'Comment',
					'foreignKey' => 'article_id',
				),
			),
			'hasAndBelongsToMany' => array(
				array(
					'alias' => 'Tag',
					'className' => 'Tag',
					'foreignKey' => 'article_id',
					'joinTable' => 'articles_tags',
					'associationForeignKey' => 'tag_id',
				),
			),
		);
	}

/**
 * Ensure that the fixutre object is correctly called.
 *
 * @return void
 * @access public
 */
	public function testBakeFixture() {
		$this->Task->Fixture->expectAt(0, 'bake', array('Article', 'articles'));
		$this->Task->bakeFixture('Article', 'articles');

		$this->assertEqual($this->Task->plugin, $this->Task->Fixture->plugin);
		$this->assertEqual($this->Task->connection, $this->Task->Fixture->connection);
	}

/**
 * Ensure that the test object is correctly called.
 *
 * @return void
 * @access public
 */
	public function testBakeTest() {
		$this->Task->Test->expectAt(0, 'bake', array('Model', 'Article'));
		$this->Task->bakeTest('Article');

		$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
		$this->assertEqual($this->Task->connection, $this->Task->Test->connection);
	}

/**
 * test confirming of associations, and that when an association is hasMany
 * a question for the hasOne is also not asked.
 *
 * @return void
 * @access public
 */
	public function testConfirmAssociations() {
		$associations = array(
			'hasOne' => array(
				array(
					'alias' => 'ChildCategoryThread',
					'className' => 'CategoryThread',
					'foreignKey' => 'parent_id',
				),
			),
			'hasMany' => array(
				array(
					'alias' => 'ChildCategoryThread',
					'className' => 'CategoryThread',
					'foreignKey' => 'parent_id',
				),
			),
			'belongsTo' => array(
				array(
					'alias' => 'User',
					'className' => 'User',
					'foreignKey' => 'user_id',
				),
			)
		);
		$model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
		$this->Task->setReturnValueAt(0, 'in', 'y');
		$result = $this->Task->confirmAssociations($model, $associations);
		$this->assertTrue(empty($result['hasOne']));

		$this->Task->setReturnValue('in', 'n');
		$result = $this->Task->confirmAssociations($model, $associations);
		$this->assertTrue(empty($result['hasMany']));
		$this->assertTrue(empty($result['hasOne']));
	}

/**
 * test that inOptions generates questions and only accepts a valid answer
 *
 * @return void
 * @access public
 */
	public function testInOptions() {
		$options = array('one', 'two', 'three');
		$this->Task->expectAt(0, 'out', array('1. one'));
		$this->Task->expectAt(1, 'out', array('2. two'));
		$this->Task->expectAt(2, 'out', array('3. three'));
		$this->Task->setReturnValueAt(0, 'in', 10);

		$this->Task->expectAt(3, 'out', array('1. one'));
		$this->Task->expectAt(4, 'out', array('2. two'));
		$this->Task->expectAt(5, 'out', array('3. three'));
		$this->Task->setReturnValueAt(1, 'in', 2);
		$result = $this->Task->inOptions($options, 'Pick a number');
		$this->assertEqual($result, 1);
	}

/**
 * test baking validation
 *
 * @return void
 * @access public
 */
	public function testBakeValidation() {
		$validate = array(
			'name' => array(
				'notempty' => 'notempty'
			),
			'email' => array(
				'email' => 'email',
			),
			'some_date' => array(
				'date' => 'date'
			),
			'some_time' => array(
				'time' => 'time'
			)
		);
		$result = $this->Task->bake('Article', compact('validate'));
		$this->assertPattern('/class Article extends AppModel \{/', $result);
		$this->assertPattern('/\$name \= \'Article\'/', $result);
		$this->assertPattern('/\$validate \= array\(/', $result);
		$pattern = '/' . preg_quote("'notempty' => array('rule' => array('notempty')),", '/') . '/';
		$this->assertPattern($pattern, $result);
	}

/**
 * test baking relations
 *
 * @return void
 * @access public
 */
	public function testBakeRelations() {
		$associations = array(
			'belongsTo' => array(
				array(
					'alias' => 'SomethingElse',
					'className' => 'SomethingElse',
					'foreignKey' => 'something_else_id',
				),
				array(
					'alias' => 'User',
					'className' => 'User',
					'foreignKey' => 'user_id',
				),
			),
			'hasOne' => array(
				array(
					'alias' => 'OtherModel',
					'className' => 'OtherModel',
					'foreignKey' => 'other_model_id',
				),
			),
			'hasMany' => array(
				array(
					'alias' => 'Comment',
					'className' => 'Comment',
					'foreignKey' => 'parent_id',
				),
			),
			'hasAndBelongsToMany' => array(
				array(
					'alias' => 'Tag',
					'className' => 'Tag',
					'foreignKey' => 'article_id',
					'joinTable' => 'articles_tags',
					'associationForeignKey' => 'tag_id',
				),
			)
		);
		$result = $this->Task->bake('Article', compact('associations'));
		$this->assertPattern('/\$hasAndBelongsToMany \= array\(/', $result);
		$this->assertPattern('/\$hasMany \= array\(/', $result);
		$this->assertPattern('/\$belongsTo \= array\(/', $result);
		$this->assertPattern('/\$hasOne \= array\(/', $result);
		$this->assertPattern('/Tag/', $result);
		$this->assertPattern('/OtherModel/', $result);
		$this->assertPattern('/SomethingElse/', $result);
		$this->assertPattern('/Comment/', $result);
	}

/**
 * test bake() with a -plugin param
 *
 * @return void
 * @access public
 */
	public function testBakeWithPlugin() {
		$this->Task->plugin = 'ControllerTest';

		$path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
		$this->Task->expectAt(0, 'createFile', array($path, '*'));
		$this->Task->bake('Article', array(), array());

		$this->Task->plugin = 'controllerTest';

		$path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
		$this->Task->expectAt(1, 'createFile', array(
		$path, new PatternExpectation('/Article extends ControllerTestAppModel/')));
		$this->Task->bake('Article', array(), array());
	}

/**
 * test that execute passes runs bake depending with named model.
 *
 * @return void
 * @access public
 */
	public function testExecuteWithNamedModel() {
		$this->Task->connection = 'test_suite';
		$this->Task->path = '/my/path/';
		$this->Task->args = array('article');
		$filename = '/my/path/article.php';
		$this->Task->setReturnValue('_checkUnitTest', 1);
		$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
		$this->Task->execute();
	}

/**
 * test that execute runs all() when args[0] = all
 *
 * @return void
 * @access public
 */
	public function testExecuteIntoAll() {
		$this->Task->connection = 'test_suite';
		$this->Task->path = '/my/path/';
		$this->Task->args = array('all');
		$this->Task->setReturnValue('_checkUnitTest', true);

		$this->Task->Fixture->expectCallCount('bake', 5);
		$this->Task->Test->expectCallCount('bake', 5);

		$filename = '/my/path/article.php';
		$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));

		$filename = '/my/path/articles_tag.php';
		$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticlesTag/')));

		$filename = '/my/path/category_thread.php';
		$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class CategoryThread/')));

		$filename = '/my/path/comment.php';
		$this->Task->expectAt(3, 'createFile', array($filename, new PatternExpectation('/class Comment/')));

		$filename = '/my/path/tag.php';
		$this->Task->expectAt(4, 'createFile', array($filename, new PatternExpectation('/class Tag/')));

		$this->Task->execute();
	}

/**
 * test the interactive side of bake.
 *
 * @return void
 * @access public
 */
	public function testExecuteIntoInteractive() {
		$this->Task->connection = 'test_suite';
		$this->Task->path = '/my/path/';
		$this->Task->interactive = true;

		$this->Task->setReturnValueAt(0, 'in', '1'); //choose article
		$this->Task->setReturnValueAt(1, 'in', 'n'); //no validation
		$this->Task->setReturnValueAt(2, 'in', 'y'); //yes to associations
		$this->Task->setReturnValueAt(3, 'in', 'y'); //yes to comment relation
		$this->Task->setReturnValueAt(4, 'in', 'y'); //yes to user relation
		$this->Task->setReturnValueAt(5, 'in', 'y'); //yes to tag relation
		$this->Task->setReturnValueAt(6, 'in', 'n'); //no to additional assocs
		$this->Task->setReturnValueAt(7, 'in', 'y'); //yes to looksGood?
		$this->Task->setReturnValue('_checkUnitTest', true);

		$this->Task->Test->expectOnce('bake');
		$this->Task->Fixture->expectOnce('bake');

		$filename = '/my/path/article.php';
		$this->Task->expectOnce('createFile');
		$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
		$this->Task->execute();
	}

/**
 * test using bake interactively with a table that does not exist.
 *
 * @return void
 * @access public
 */
	public function testExecuteWithNonExistantTableName() {
		$this->Task->connection = 'test_suite';
		$this->Task->path = '/my/path/';

		$this->Task->expectOnce('_stop');
		$this->Task->expectOnce('err');

		$this->Task->setReturnValueAt(0, 'in', 'Foobar');
		$this->Task->setReturnValueAt(1, 'in', 'y');
		$this->Task->execute();
	}
}
?>
Back to Top