Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 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
 
417
		$this->assertContains("'app.test_task_article'", $result);
418
		$this->assertContains("'app.test_task_comment'", $result);
419
		$this->assertContains("'app.test_task_tag'", $result);
420
		$this->assertContains("'app.articles_tag'", $result);
421
	}
422
 
423
/**
424
 * test baking controller test files
425
 *
426
 * @return void
427
 */
428
	public function testBakeControllerTest() {
429
		$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
430
		$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
431
 
432
		$result = $this->Task->bake('Controller', 'TestTaskComments');
433
 
434
		$this->assertContains("App::uses('TestTaskCommentsController', 'Controller')", $result);
435
		$this->assertContains('class TestTaskCommentsControllerTest extends ControllerTestCase', $result);
436
 
437
		$this->assertNotContains('function setUp()', $result);
438
		$this->assertNotContains("\$this->TestTaskComments = new TestTaskCommentsController()", $result);
439
		$this->assertNotContains("\$this->TestTaskComments->constructClasses()", $result);
440
 
441
		$this->assertNotContains('function tearDown()', $result);
442
		$this->assertNotContains('unset($this->TestTaskComments)', $result);
443
 
444
		$this->assertContains("'app.test_task_article'", $result);
445
		$this->assertContains("'app.test_task_comment'", $result);
446
		$this->assertContains("'app.test_task_tag'", $result);
447
		$this->assertContains("'app.articles_tag'", $result);
448
	}
449
 
450
/**
451
 * test baking component test files,
452
 *
453
 * @return void
454
 */
455
	public function testBakeComponentTest() {
456
		$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
457
 
458
		$result = $this->Task->bake('Component', 'Example');
459
 
460
		$this->assertContains("App::uses('Component', 'Controller')", $result);
461
		$this->assertContains("App::uses('ComponentCollection', 'Controller')", $result);
462
		$this->assertContains("App::uses('ExampleComponent', 'Controller/Component')", $result);
463
		$this->assertContains('class ExampleComponentTest extends CakeTestCase', $result);
464
 
465
		$this->assertContains('function setUp()', $result);
466
		$this->assertContains("\$Collection = new ComponentCollection()", $result);
467
		$this->assertContains("\$this->Example = new ExampleComponent(\$Collection)", $result);
468
 
469
		$this->assertContains('function tearDown()', $result);
470
		$this->assertContains('unset($this->Example)', $result);
471
	}
472
 
473
/**
474
 * test baking behavior test files,
475
 *
476
 * @return void
477
 */
478
	public function testBakeBehaviorTest() {
479
		$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
480
 
481
		$result = $this->Task->bake('Behavior', 'Example');
482
 
483
		$this->assertContains("App::uses('ExampleBehavior', 'Model/Behavior')", $result);
484
		$this->assertContains('class ExampleBehaviorTest extends CakeTestCase', $result);
485
 
486
		$this->assertContains('function setUp()', $result);
487
		$this->assertContains("\$this->Example = new ExampleBehavior()", $result);
488
 
489
		$this->assertContains('function tearDown()', $result);
490
		$this->assertContains('unset($this->Example)', $result);
491
	}
492
 
493
/**
494
 * test baking helper test files,
495
 *
496
 * @return void
497
 */
498
	public function testBakeHelperTest() {
499
		$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
500
 
501
		$result = $this->Task->bake('Helper', 'Example');
502
 
503
		$this->assertContains("App::uses('ExampleHelper', 'View/Helper')", $result);
504
		$this->assertContains('class ExampleHelperTest extends CakeTestCase', $result);
505
 
506
		$this->assertContains('function setUp()', $result);
507
		$this->assertContains("\$View = new View()", $result);
508
		$this->assertContains("\$this->Example = new ExampleHelper(\$View)", $result);
509
 
510
		$this->assertContains('function tearDown()', $result);
511
		$this->assertContains('unset($this->Example)', $result);
512
	}
513
 
514
/**
515
 * test Constructor generation ensure that constructClasses is called for controllers
516
 *
517
 * @return void
518
 */
519
	public function testGenerateConstructor() {
520
		$result = $this->Task->generateConstructor('controller', 'PostsController', null);
521
		$expected = array('', '', '');
522
		$this->assertEquals($expected, $result);
523
 
524
		$result = $this->Task->generateConstructor('model', 'Post', null);
525
		$expected = array('', "ClassRegistry::init('Post');\n", '');
526
		$this->assertEquals($expected, $result);
527
 
528
		$result = $this->Task->generateConstructor('helper', 'FormHelper', null);
529
		$expected = array("\$View = new View();\n", "new FormHelper(\$View);\n", '');
530
		$this->assertEquals($expected, $result);
531
	}
532
 
533
/**
534
 * Test generateUses()
535
 */
536
	public function testGenerateUses() {
537
		$result = $this->Task->generateUses('model', 'Model', 'Post');
538
		$expected = array(
539
			array('Post', 'Model')
540
		);
541
		$this->assertEquals($expected, $result);
542
 
543
		$result = $this->Task->generateUses('controller', 'Controller', 'PostsController');
544
		$expected = array(
545
			array('PostsController', 'Controller')
546
		);
547
		$this->assertEquals($expected, $result);
548
 
549
		$result = $this->Task->generateUses('helper', 'View/Helper', 'FormHelper');
550
		$expected = array(
551
			array('View', 'View'),
552
			array('Helper', 'View'),
553
			array('FormHelper', 'View/Helper'),
554
		);
555
		$this->assertEquals($expected, $result);
556
 
557
		$result = $this->Task->generateUses('component', 'Controller/Component', 'AuthComponent');
558
		$expected = array(
559
			array('ComponentCollection', 'Controller'),
560
			array('Component', 'Controller'),
561
			array('AuthComponent', 'Controller/Component')
562
		);
563
		$this->assertEquals($expected, $result);
564
	}
565
 
566
/**
567
 * Test that mock class generation works for the appropriate classes
568
 *
569
 * @return void
570
 */
571
	public function testMockClassGeneration() {
572
		$result = $this->Task->hasMockClass('controller');
573
		$this->assertTrue($result);
574
	}
575
 
576
/**
577
 * test bake() with a -plugin param
578
 *
579
 * @return void
580
 */
581
	public function testBakeWithPlugin() {
582
		$this->Task->plugin = 'TestTest';
583
 
584
		//fake plugin path
585
		CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
586
		$path = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php';
587
		$this->Task->expects($this->once())->method('createFile')
588
			->with($path, $this->anything());
589
 
590
		$this->Task->bake('Helper', 'Form');
591
		CakePlugin::unload();
592
	}
593
 
594
/**
595
 * test interactive with plugins lists from the plugin
596
 *
597
 * @return void
598
 */
599
	public function testInteractiveWithPlugin() {
600
		$testApp = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
601
		App::build(array(
602
			'Plugin' => array($testApp)
603
		), App::RESET);
604
		CakePlugin::load('TestPlugin');
605
 
606
		$this->Task->plugin = 'TestPlugin';
607
		$path = $testApp . 'TestPlugin' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'OtherHelperTest.php';
608
		$this->Task->expects($this->any())
609
			->method('in')
610
			->will($this->onConsecutiveCalls(
611
				5, //helper
612
				1 //OtherHelper
613
			));
614
 
615
		$this->Task->expects($this->once())
616
			->method('createFile')
617
			->with($path, $this->anything());
618
 
619
		$this->Task->stdout->expects($this->at(21))
620
			->method('write')
621
			->with('1. OtherHelperHelper');
622
 
623
		$this->Task->execute();
624
	}
625
 
626
	public static function caseFileNameProvider() {
627
		return array(
628
			array('Model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),
629
			array('Helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),
630
			array('Controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),
631
			array('Behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),
632
			array('Component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),
633
			array('model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),
634
			array('helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),
635
			array('controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),
636
			array('behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),
637
			array('component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),
638
		);
639
	}
640
 
641
/**
642
 * Test filename generation for each type + plugins
643
 *
644
 * @dataProvider caseFileNameProvider
645
 * @return void
646
 */
647
	public function testTestCaseFileName($type, $class, $expected) {
648
		$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
649
 
650
		$result = $this->Task->testCaseFileName($type, $class);
651
		$expected = $this->Task->path . $expected;
652
		$this->assertEquals($expected, $result);
653
	}
654
 
655
/**
656
 * Test filename generation for plugins.
657
 *
658
 * @return void
659
 */
660
	public function testTestCaseFileNamePlugin() {
661
		$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
662
 
663
		CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
664
		$this->Task->plugin = 'TestTest';
665
		$result = $this->Task->testCaseFileName('Model', 'Post');
666
		$expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php';
667
		$this->assertEquals($expected, $result);
668
	}
669
 
670
/**
671
 * test execute with a type defined
672
 *
673
 * @return void
674
 */
675
	public function testExecuteWithOneArg() {
676
		$this->Task->args[0] = 'Model';
677
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
678
		$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
679
		$this->Task->expects($this->once())->method('createFile')
680
			->with(
681
				$this->anything(),
682
				$this->stringContains('class TestTaskTagTest extends CakeTestCase')
683
			);
684
		$this->Task->execute();
685
	}
686
 
687
/**
688
 * test execute with type and class name defined
689
 *
690
 * @return void
691
 */
692
	public function testExecuteWithTwoArgs() {
693
		$this->Task->args = array('Model', 'TestTaskTag');
694
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
695
		$this->Task->expects($this->once())->method('createFile')
696
			->with(
697
				$this->anything(),
698
				$this->stringContains('class TestTaskTagTest extends CakeTestCase')
699
			);
700
		$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
701
		$this->Task->execute();
702
	}
703
 
704
/**
705
 * test execute with type and class name defined and lower case.
706
 *
707
 * @return void
708
 */
709
	public function testExecuteWithTwoArgsLowerCase() {
710
		$this->Task->args = array('model', 'TestTaskTag');
711
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
712
		$this->Task->expects($this->once())->method('createFile')
713
			->with(
714
				$this->anything(),
715
				$this->stringContains('class TestTaskTagTest extends CakeTestCase')
716
			);
717
		$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
718
		$this->Task->execute();
719
	}
720
 
721
/**
722
 * Data provider for mapType() tests.
723
 *
724
 * @return array
725
 */
726
	public static function mapTypeProvider() {
727
		return array(
728
			array('controller', null, 'Controller'),
729
			array('Controller', null, 'Controller'),
730
			array('component', null, 'Controller/Component'),
731
			array('Component', null, 'Controller/Component'),
732
			array('model', null, 'Model'),
733
			array('Model', null, 'Model'),
734
			array('behavior', null, 'Model/Behavior'),
735
			array('Behavior', null, 'Model/Behavior'),
736
			array('helper', null, 'View/Helper'),
737
			array('Helper', null, 'View/Helper'),
738
			array('Helper', 'DebugKit', 'DebugKit.View/Helper'),
739
		);
740
	}
741
 
742
/**
743
 * Test that mapType returns the correct package names.
744
 *
745
 * @dataProvider mapTypeProvider
746
 * @return void
747
 */
748
	public function testMapType($original, $plugin, $expected) {
749
		$this->assertEquals($expected, $this->Task->mapType($original, $plugin));
750
	}
751
}