Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15403 manish.sha 1
<?php
2
/**
3
 * TestTaskTest 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.0.7726
18
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
19
 */
20
 
21
App::uses('ShellDispatcher', 'Console');
22
App::uses('ConsoleOutput', 'Console');
23
App::uses('ConsoleInput', 'Console');
24
App::uses('Shell', 'Console');
25
App::uses('TestTask', 'Console/Command/Task');
26
App::uses('TemplateTask', 'Console/Command/Task');
27
App::uses('Controller', 'Controller');
28
App::uses('Model', 'Model');
29
 
30
/**
31
 * Test Article model
32
 *
33
 * @package       Cake.Test.Case.Console.Command.Task
34
 */
35
class TestTaskArticle extends Model {
36
 
37
/**
38
 * Table name to use
39
 *
40
 * @var string
41
 */
42
	public $useTable = 'articles';
43
 
44
/**
45
 * HasMany Associations
46
 *
47
 * @var array
48
 */
49
	public $hasMany = array(
50
		'Comment' => array(
51
			'className' => 'TestTask.TestTaskComment',
52
			'foreignKey' => 'article_id',
53
		)
54
	);
55
 
56
/**
57
 * Has and Belongs To Many Associations
58
 *
59
 * @var array
60
 */
61
	public $hasAndBelongsToMany = array(
62
		'Tag' => array(
63
			'className' => 'TestTaskTag',
64
			'joinTable' => 'articles_tags',
65
			'foreignKey' => 'article_id',
66
			'associationForeignKey' => 'tag_id'
67
		)
68
	);
69
 
70
/**
71
 * Example public method
72
 *
73
 * @return void
74
 */
75
	public function doSomething() {
76
	}
77
 
78
/**
79
 * Example Secondary public method
80
 *
81
 * @return void
82
 */
83
	public function doSomethingElse() {
84
	}
85
 
86
/**
87
 * Example protected method
88
 *
89
 * @return void
90
 */
91
	protected function _innerMethod() {
92
	}
93
 
94
}
95
 
96
/**
97
 * Tag Testing Model
98
 *
99
 * @package       Cake.Test.Case.Console.Command.Task
100
 */
101
class TestTaskTag extends Model {
102
 
103
/**
104
 * Table name
105
 *
106
 * @var string
107
 */
108
	public $useTable = 'tags';
109
 
110
/**
111
 * Has and Belongs To Many Associations
112
 *
113
 * @var array
114
 */
115
	public $hasAndBelongsToMany = array(
116
		'Article' => array(
117
			'className' => 'TestTaskArticle',
118
			'joinTable' => 'articles_tags',
119
			'foreignKey' => 'tag_id',
120
			'associationForeignKey' => 'article_id'
121
		)
122
	);
123
}
124
 
125
/**
126
 * Simulated plugin
127
 *
128
 * @package       Cake.Test.Case.Console.Command.Task
129
 */
130
class TestTaskAppModel extends Model {
131
}
132
 
133
/**
134
 * Testing AppMode (TaskComment)
135
 *
136
 * @package       Cake.Test.Case.Console.Command.Task
137
 */
138
class TestTaskComment extends TestTaskAppModel {
139
 
140
/**
141
 * Table name
142
 *
143
 * @var string
144
 */
145
	public $useTable = 'comments';
146
 
147
/**
148
 * Belongs To Associations
149
 *
150
 * @var array
151
 */
152
	public $belongsTo = array(
153
		'Article' => array(
154
			'className' => 'TestTaskArticle',
155
			'foreignKey' => 'article_id',
156
		)
157
	);
158
}
159
 
160
/**
161
 * Test Task Comments Controller
162
 *
163
 * @package       Cake.Test.Case.Console.Command.Task
164
 */
165
class TestTaskCommentsController extends Controller {
166
 
167
/**
168
 * Models to use
169
 *
170
 * @var array
171
 */
172
	public $uses = array('TestTaskComment', 'TestTaskTag');
173
}
174
 
175
/**
176
 * TestTaskTest class
177
 *
178
 * @package       Cake.Test.Case.Console.Command.Task
179
 */
180
class TestTaskTest extends CakeTestCase {
181
 
182
/**
183
 * Fixtures
184
 *
185
 * @var string
186
 */
187
	public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
188
 
189
/**
190
 * setUp method
191
 *
192
 * @return void
193
 */
194
	public function setUp() {
195
		parent::setUp();
196
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
197
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
198
 
199
		$this->Task = $this->getMock('TestTask',
200
			array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
201
			array($out, $out, $in)
202
		);
203
		$this->Task->name = 'Test';
204
		$this->Task->Template = new TemplateTask($out, $out, $in);
205
	}
206
 
207
/**
208
 * tearDown method
209
 *
210
 * @return void
211
 */
212
	public function tearDown() {
213
		parent::tearDown();
214
		unset($this->Task);
215
		CakePlugin::unload();
216
	}
217
 
218
/**
219
 * Test that file path generation doesn't continuously append paths.
220
 *
221
 * @return void
222
 */
223
	public function testFilePathGenerationModelRepeated() {
224
		$this->Task->expects($this->never())->method('err');
225
		$this->Task->expects($this->never())->method('_stop');
226
 
227
		$file = TESTS . 'Case' . DS . 'Model' . DS . 'MyClassTest.php';
228
 
229
		$this->Task->expects($this->at(1))->method('createFile')
230
			->with($file, $this->anything());
231
 
232
		$this->Task->expects($this->at(3))->method('createFile')
233
			->with($file, $this->anything());
234
 
235
		$file = TESTS . 'Case' . DS . 'Controller' . DS . 'CommentsControllerTest.php';
236
		$this->Task->expects($this->at(5))->method('createFile')
237
			->with($file, $this->anything());
238
 
239
		$this->Task->bake('Model', 'MyClass');
240
		$this->Task->bake('Model', 'MyClass');
241
		$this->Task->bake('Controller', 'Comments');
242
	}
243
 
244
/**
245
 * Test that method introspection pulls all relevant non parent class
246
 * methods into the test case.
247
 *
248
 * @return void
249
 */
250
	public function testMethodIntrospection() {
251
		$result = $this->Task->getTestableMethods('TestTaskArticle');
252
		$expected = array('dosomething', 'dosomethingelse');
253
		$this->assertEquals($expected, array_map('strtolower', $result));
254
	}
255
 
256
/**
257
 * test that the generation of fixtures works correctly.
258
 *
259
 * @return void
260
 */
261
	public function testFixtureArrayGenerationFromModel() {
262
		$subject = ClassRegistry::init('TestTaskArticle');
263
		$result = $this->Task->generateFixtureList($subject);
264
		$expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
265
			'app.test_task_article', 'app.test_task_tag');
266
 
267
		$this->assertEquals(sort($expected), sort($result));
268
	}
269
 
270
/**
271
 * test that the generation of fixtures works correctly.
272
 *
273
 * @return void
274
 */
275
	public function testFixtureArrayGenerationFromController() {
276
		$subject = new TestTaskCommentsController();
277
		$result = $this->Task->generateFixtureList($subject);
278
		$expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
279
			'app.test_task_article', 'app.test_task_tag');
280
 
281
		$this->assertEquals(sort($expected), sort($result));
282
	}
283
 
284
/**
285
 * test user interaction to get object type
286
 *
287
 * @return void
288
 */
289
	public function testGetObjectType() {
290
		$this->Task->expects($this->once())->method('_stop');
291
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('q'));
292
		$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(2));
293
 
294
		$this->Task->getObjectType();
295
 
296
		$result = $this->Task->getObjectType();
297
		$this->assertEquals($this->Task->classTypes['Controller'], $result);
298
	}
299
 
300
/**
301
 * creating test subjects should clear the registry so the registry is always fresh
302
 *
303
 * @return void
304
 */
305
	public function testRegistryClearWhenBuildingTestObjects() {
306
		ClassRegistry::flush();
307
		$model = ClassRegistry::init('TestTaskComment');
308
		$model->bindModel(array(
309
			'belongsTo' => array(
310
				'Random' => array(
311
					'className' => 'TestTaskArticle',
312
					'foreignKey' => 'article_id',
313
				)
314
			)
315
		));
316
		$keys = ClassRegistry::keys();
317
		$this->assertTrue(in_array('test_task_comment', $keys));
318
		$this->Task->buildTestSubject('Model', 'TestTaskComment');
319
 
320
		$keys = ClassRegistry::keys();
321
		$this->assertFalse(in_array('random', $keys));
322
	}
323
 
324
/**
325
 * test that getClassName returns the user choice as a class name.
326
 *
327
 * @return void
328
 */
329
	public function testGetClassName() {
330
		$objects = App::objects('model');
331
		$this->skipIf(empty($objects), 'No models in app.');
332
 
333
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));
334
		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
335
 
336
		$result = $this->Task->getClassName('Model');
337
		$this->assertEquals('MyCustomClass', $result);
338
 
339
		$result = $this->Task->getClassName('Model');
340
		$options = App::objects('model');
341
		$this->assertEquals($options[0], $result);
342
	}
343
 
344
/**
345
 * Test the user interaction for defining additional fixtures.
346
 *
347
 * @return void
348
 */
349
	public function testGetUserFixtures() {
350
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
351
		$this->Task->expects($this->at(1))->method('in')
352
			->will($this->returnValue('app.pizza, app.topping, app.side_dish'));
353
 
354
		$result = $this->Task->getUserFixtures();
355
		$expected = array('app.pizza', 'app.topping', 'app.side_dish');
356
		$this->assertEquals($expected, $result);
357
	}
358
 
359
/**
360
 * test that resolving class names works
361
 *
362
 * @return void
363
 */
364
	public function testGetRealClassname() {
365
		$result = $this->Task->getRealClassname('Model', 'Post');
366
		$this->assertEquals('Post', $result);
367
 
368
		$result = $this->Task->getRealClassname('Controller', 'Posts');
369
		$this->assertEquals('PostsController', $result);
370
 
371
		$result = $this->Task->getRealClassname('Controller', 'PostsController');
372
		$this->assertEquals('PostsController', $result);
373
 
374
		$result = $this->Task->getRealClassname('Controller', 'AlertTypes');
375
		$this->assertEquals('AlertTypesController', $result);
376
 
377
		$result = $this->Task->getRealClassname('Helper', 'Form');
378
		$this->assertEquals('FormHelper', $result);
379
 
380
		$result = $this->Task->getRealClassname('Helper', 'FormHelper');
381
		$this->assertEquals('FormHelper', $result);
382
 
383
		$result = $this->Task->getRealClassname('Behavior', 'Containable');
384
		$this->assertEquals('ContainableBehavior', $result);
385
 
386
		$result = $this->Task->getRealClassname('Behavior', 'ContainableBehavior');
387
		$this->assertEquals('ContainableBehavior', $result);
388
 
389
		$result = $this->Task->getRealClassname('Component', 'Auth');
390
		$this->assertEquals('AuthComponent', $result);
391
	}
392
 
393
/**
394
 * test baking files. The conditionally run tests are known to fail in PHP4
395
 * as PHP4 class names are all lower case, breaking the plugin path inflection.
396
 *
397
 * @return void
398
 */
399
	public function testBakeModelTest() {
400
		$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
401
		$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
402
 
403
		$result = $this->Task->bake('Model', 'TestTaskArticle');
404
 
405
		$this->assertContains("App::uses('TestTaskArticle', 'Model')", $result);
406
		$this->assertContains('class TestTaskArticleTest extends CakeTestCase', $result);
407
 
408
		$this->assertContains('function setUp()', $result);
409
		$this->assertContains("\$this->TestTaskArticle = ClassRegistry::init('TestTaskArticle')", $result);
410
 
411
		$this->assertContains('function tearDown()', $result);
412
		$this->assertContains('unset($this->TestTaskArticle)', $result);
413
 
414
		$this->assertContains('function testDoSomething()', $result);
415
		$this->assertContains('function testDoSomethingElse()', $result);
416
		$this->assertContains('$this->markTestIncomplete(\'testDoSomething not implemented.\')', $result);
417
		$this->assertContains('$this->markTestIncomplete(\'testDoSomethingElse not implemented.\')', $result);
418
 
419
		$this->assertContains("'app.test_task_article'", $result);
420
		$this->assertContains("'app.test_task_comment'", $result);
421
		$this->assertContains("'app.test_task_tag'", $result);
422
		$this->assertContains("'app.articles_tag'", $result);
423
	}
424
 
425
/**
426
 * test baking controller test files
427
 *
428
 * @return void
429
 */
430
	public function testBakeControllerTest() {
431
		$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
432
		$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
433
 
434
		$result = $this->Task->bake('Controller', 'TestTaskComments');
435
 
436
		$this->assertContains("App::uses('TestTaskCommentsController', 'Controller')", $result);
437
		$this->assertContains('class TestTaskCommentsControllerTest extends ControllerTestCase', $result);
438
 
439
		$this->assertNotContains('function setUp()', $result);
440
		$this->assertNotContains("\$this->TestTaskComments = new TestTaskCommentsController()", $result);
441
		$this->assertNotContains("\$this->TestTaskComments->constructClasses()", $result);
442
 
443
		$this->assertNotContains('function tearDown()', $result);
444
		$this->assertNotContains('unset($this->TestTaskComments)', $result);
445
 
446
		$this->assertContains("'app.test_task_article'", $result);
447
		$this->assertContains("'app.test_task_comment'", $result);
448
		$this->assertContains("'app.test_task_tag'", $result);
449
		$this->assertContains("'app.articles_tag'", $result);
450
	}
451
 
452
/**
453
 * test baking component test files,
454
 *
455
 * @return void
456
 */
457
	public function testBakeComponentTest() {
458
		$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
459
 
460
		$result = $this->Task->bake('Component', 'Example');
461
 
462
		$this->assertContains("App::uses('Component', 'Controller')", $result);
463
		$this->assertContains("App::uses('ComponentCollection', 'Controller')", $result);
464
		$this->assertContains("App::uses('ExampleComponent', 'Controller/Component')", $result);
465
		$this->assertContains('class ExampleComponentTest extends CakeTestCase', $result);
466
 
467
		$this->assertContains('function setUp()', $result);
468
		$this->assertContains("\$Collection = new ComponentCollection()", $result);
469
		$this->assertContains("\$this->Example = new ExampleComponent(\$Collection)", $result);
470
 
471
		$this->assertContains('function tearDown()', $result);
472
		$this->assertContains('unset($this->Example)', $result);
473
	}
474
 
475
/**
476
 * test baking behavior test files,
477
 *
478
 * @return void
479
 */
480
	public function testBakeBehaviorTest() {
481
		$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
482
 
483
		$result = $this->Task->bake('Behavior', 'Example');
484
 
485
		$this->assertContains("App::uses('ExampleBehavior', 'Model/Behavior')", $result);
486
		$this->assertContains('class ExampleBehaviorTest extends CakeTestCase', $result);
487
 
488
		$this->assertContains('function setUp()', $result);
489
		$this->assertContains("\$this->Example = new ExampleBehavior()", $result);
490
 
491
		$this->assertContains('function tearDown()', $result);
492
		$this->assertContains('unset($this->Example)', $result);
493
	}
494
 
495
/**
496
 * test baking helper test files,
497
 *
498
 * @return void
499
 */
500
	public function testBakeHelperTest() {
501
		$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
502
 
503
		$result = $this->Task->bake('Helper', 'Example');
504
 
505
		$this->assertContains("App::uses('ExampleHelper', 'View/Helper')", $result);
506
		$this->assertContains('class ExampleHelperTest extends CakeTestCase', $result);
507
 
508
		$this->assertContains('function setUp()', $result);
509
		$this->assertContains("\$View = new View()", $result);
510
		$this->assertContains("\$this->Example = new ExampleHelper(\$View)", $result);
511
 
512
		$this->assertContains('function tearDown()', $result);
513
		$this->assertContains('unset($this->Example)', $result);
514
	}
515
 
516
/**
517
 * test Constructor generation ensure that constructClasses is called for controllers
518
 *
519
 * @return void
520
 */
521
	public function testGenerateConstructor() {
522
		$result = $this->Task->generateConstructor('controller', 'PostsController', null);
523
		$expected = array('', '', '');
524
		$this->assertEquals($expected, $result);
525
 
526
		$result = $this->Task->generateConstructor('model', 'Post', null);
527
		$expected = array('', "ClassRegistry::init('Post');\n", '');
528
		$this->assertEquals($expected, $result);
529
 
530
		$result = $this->Task->generateConstructor('helper', 'FormHelper', null);
531
		$expected = array("\$View = new View();\n", "new FormHelper(\$View);\n", '');
532
		$this->assertEquals($expected, $result);
533
	}
534
 
535
/**
536
 * Test generateUses()
537
 *
538
 * @return void
539
 */
540
	public function testGenerateUses() {
541
		$result = $this->Task->generateUses('model', 'Model', 'Post');
542
		$expected = array(
543
			array('Post', 'Model')
544
		);
545
		$this->assertEquals($expected, $result);
546
 
547
		$result = $this->Task->generateUses('controller', 'Controller', 'PostsController');
548
		$expected = array(
549
			array('PostsController', 'Controller')
550
		);
551
		$this->assertEquals($expected, $result);
552
 
553
		$result = $this->Task->generateUses('helper', 'View/Helper', 'FormHelper');
554
		$expected = array(
555
			array('View', 'View'),
556
			array('Helper', 'View'),
557
			array('FormHelper', 'View/Helper'),
558
		);
559
		$this->assertEquals($expected, $result);
560
 
561
		$result = $this->Task->generateUses('component', 'Controller/Component', 'AuthComponent');
562
		$expected = array(
563
			array('ComponentCollection', 'Controller'),
564
			array('Component', 'Controller'),
565
			array('AuthComponent', 'Controller/Component')
566
		);
567
		$this->assertEquals($expected, $result);
568
	}
569
 
570
/**
571
 * Test that mock class generation works for the appropriate classes
572
 *
573
 * @return void
574
 */
575
	public function testMockClassGeneration() {
576
		$result = $this->Task->hasMockClass('controller');
577
		$this->assertTrue($result);
578
	}
579
 
580
/**
581
 * test bake() with a -plugin param
582
 *
583
 * @return void
584
 */
585
	public function testBakeWithPlugin() {
586
		$this->Task->plugin = 'TestTest';
587
 
588
		//fake plugin path
589
		CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
590
		$path = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php';
591
		$this->Task->expects($this->once())->method('createFile')
592
			->with($path, $this->anything());
593
 
594
		$this->Task->bake('Helper', 'Form');
595
		CakePlugin::unload();
596
	}
597
 
598
/**
599
 * test interactive with plugins lists from the plugin
600
 *
601
 * @return void
602
 */
603
	public function testInteractiveWithPlugin() {
604
		$testApp = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
605
		App::build(array(
606
			'Plugin' => array($testApp)
607
		), App::RESET);
608
		CakePlugin::load('TestPlugin');
609
 
610
		$this->Task->plugin = 'TestPlugin';
611
		$path = $testApp . 'TestPlugin' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'OtherHelperTest.php';
612
		$this->Task->expects($this->any())
613
			->method('in')
614
			->will($this->onConsecutiveCalls(
615
				5, //helper
616
				1 //OtherHelper
617
			));
618
 
619
		$this->Task->expects($this->once())
620
			->method('createFile')
621
			->with($path, $this->anything());
622
 
623
		$this->Task->stdout->expects($this->at(21))
624
			->method('write')
625
			->with('1. OtherHelperHelper');
626
 
627
		$this->Task->execute();
628
	}
629
 
630
	public static function caseFileNameProvider() {
631
		return array(
632
			array('Model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),
633
			array('Helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),
634
			array('Controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),
635
			array('Behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),
636
			array('Component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),
637
			array('model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),
638
			array('helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),
639
			array('controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),
640
			array('behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),
641
			array('component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),
642
		);
643
	}
644
 
645
/**
646
 * Test filename generation for each type + plugins
647
 *
648
 * @dataProvider caseFileNameProvider
649
 * @return void
650
 */
651
	public function testTestCaseFileName($type, $class, $expected) {
652
		$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
653
 
654
		$result = $this->Task->testCaseFileName($type, $class);
655
		$expected = $this->Task->path . $expected;
656
		$this->assertEquals($expected, $result);
657
	}
658
 
659
/**
660
 * Test filename generation for plugins.
661
 *
662
 * @return void
663
 */
664
	public function testTestCaseFileNamePlugin() {
665
		$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
666
 
667
		CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
668
		$this->Task->plugin = 'TestTest';
669
		$result = $this->Task->testCaseFileName('Model', 'Post');
670
		$expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php';
671
		$this->assertEquals($expected, $result);
672
	}
673
 
674
/**
675
 * test execute with a type defined
676
 *
677
 * @return void
678
 */
679
	public function testExecuteWithOneArg() {
680
		$this->Task->args[0] = 'Model';
681
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
682
		$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
683
		$this->Task->expects($this->once())->method('createFile')
684
			->with(
685
				$this->anything(),
686
				$this->stringContains('class TestTaskTagTest extends CakeTestCase')
687
			);
688
		$this->Task->execute();
689
	}
690
 
691
/**
692
 * test execute with type and class name defined
693
 *
694
 * @return void
695
 */
696
	public function testExecuteWithTwoArgs() {
697
		$this->Task->args = array('Model', 'TestTaskTag');
698
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
699
		$this->Task->expects($this->once())->method('createFile')
700
			->with(
701
				$this->anything(),
702
				$this->stringContains('class TestTaskTagTest extends CakeTestCase')
703
			);
704
		$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
705
		$this->Task->execute();
706
	}
707
 
708
/**
709
 * test execute with type and class name defined and lower case.
710
 *
711
 * @return void
712
 */
713
	public function testExecuteWithTwoArgsLowerCase() {
714
		$this->Task->args = array('model', 'TestTaskTag');
715
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
716
		$this->Task->expects($this->once())->method('createFile')
717
			->with(
718
				$this->anything(),
719
				$this->stringContains('class TestTaskTagTest extends CakeTestCase')
720
			);
721
		$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
722
		$this->Task->execute();
723
	}
724
 
725
/**
726
 * Data provider for mapType() tests.
727
 *
728
 * @return array
729
 */
730
	public static function mapTypeProvider() {
731
		return array(
732
			array('controller', null, 'Controller'),
733
			array('Controller', null, 'Controller'),
734
			array('component', null, 'Controller/Component'),
735
			array('Component', null, 'Controller/Component'),
736
			array('model', null, 'Model'),
737
			array('Model', null, 'Model'),
738
			array('behavior', null, 'Model/Behavior'),
739
			array('Behavior', null, 'Model/Behavior'),
740
			array('helper', null, 'View/Helper'),
741
			array('Helper', null, 'View/Helper'),
742
			array('Helper', 'DebugKit', 'DebugKit.View/Helper'),
743
		);
744
	}
745
 
746
/**
747
 * Test that mapType returns the correct package names.
748
 *
749
 * @dataProvider mapTypeProvider
750
 * @return void
751
 */
752
	public function testMapType($original, $plugin, $expected) {
753
		$this->assertEquals($expected, $this->Task->mapType($original, $plugin));
754
	}
755
}