TestTaskTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP Project
  12. * @since 1.2.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Console\Command\Task;
  16. use Cake\Console\Command\Task\TemplateTask;
  17. use Cake\Console\Command\Task\TestTask;
  18. use Cake\Controller\Controller;
  19. use Cake\Core\App;
  20. use Cake\Core\Configure;
  21. use Cake\Core\Plugin;
  22. use Cake\ORM\Table;
  23. use Cake\TestSuite\TestCase;
  24. use Cake\Utility\ClassRegistry;
  25. /**
  26. * TestTaskTest class
  27. *
  28. */
  29. class TestTaskTest extends TestCase {
  30. /**
  31. * Fixtures
  32. *
  33. * @var string
  34. */
  35. public $fixtures = ['core.article', 'core.author',
  36. 'core.comment', 'core.articles_tag', 'core.tag'];
  37. /**
  38. * setUp method
  39. *
  40. * @return void
  41. */
  42. public function setUp() {
  43. parent::setUp();
  44. $out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false);
  45. $in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
  46. $this->Task = $this->getMock('Cake\Console\Command\Task\TestTask',
  47. array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
  48. array($out, $out, $in)
  49. );
  50. $this->Task->name = 'Test';
  51. $this->Task->Template = new TemplateTask($out, $out, $in);
  52. }
  53. /**
  54. * tearDown method
  55. *
  56. * @return void
  57. */
  58. public function tearDown() {
  59. parent::tearDown();
  60. unset($this->Task);
  61. Plugin::unload();
  62. }
  63. /**
  64. * Test that with no args execute() outputs the types you can generate
  65. * tests for.
  66. *
  67. * @return void
  68. */
  69. public function testExecuteNoArgsPrintsTypeOptions() {
  70. $this->Task = $this->getMockBuilder('Cake\Console\Command\Task\TestTask')
  71. ->disableOriginalConstructor()
  72. ->setMethods(['outputTypeChoices'])
  73. ->getMock();
  74. $this->Task->expects($this->once())
  75. ->method('outputTypeChoices');
  76. $this->Task->execute();
  77. }
  78. /**
  79. * Test outputTypeChoices method
  80. *
  81. * @return void
  82. */
  83. public function testOutputTypeChoices() {
  84. $this->Task->stdout->expects($this->at(0))
  85. ->method('write')
  86. ->with($this->stringContains('You must provide'));
  87. $this->Task->stdout->expects($this->at(1))
  88. ->method('write')
  89. ->with($this->stringContains('1. Entity'));
  90. $this->Task->stdout->expects($this->at(2))
  91. ->method('write')
  92. ->with($this->stringContains('2. Table'));
  93. $this->Task->stdout->expects($this->at(3))
  94. ->method('write')
  95. ->with($this->stringContains('3. Controller'));
  96. $this->Task->outputTypeChoices();
  97. }
  98. /**
  99. * Test that with no args execute() outputs the types you can generate
  100. * tests for.
  101. *
  102. * @return void
  103. */
  104. public function testExecuteOneArgPrintsClassOptions() {
  105. $this->Task = $this->getMockBuilder('Cake\Console\Command\Task\TestTask')
  106. ->disableOriginalConstructor()
  107. ->setMethods(['outputClassChoices'])
  108. ->getMock();
  109. $this->Task->expects($this->once())
  110. ->method('outputClassChoices');
  111. $this->Task->args = ['Entity'];
  112. $this->Task->execute();
  113. }
  114. /**
  115. * Test generating class options for table.
  116. *
  117. * @return void
  118. */
  119. public function testOutputClassOptionsForTable() {
  120. $this->Task->stdout->expects($this->at(0))
  121. ->method('write')
  122. ->with($this->stringContains('You must provide'));
  123. $this->Task->stdout->expects($this->at(1))
  124. ->method('write')
  125. ->with($this->stringContains('1. ArticlesTable'));
  126. $this->Task->stdout->expects($this->at(2))
  127. ->method('write')
  128. ->with($this->stringContains('2. ArticlesTagsTable'));
  129. $this->Task->stdout->expects($this->at(3))
  130. ->method('write')
  131. ->with($this->stringContains('3. AuthorsTable'));
  132. $this->Task->outputClassChoices('Table');
  133. }
  134. /**
  135. * Test that file path generation doesn't continuously append paths.
  136. *
  137. * @return void
  138. */
  139. public function testFilePathGenerationModelRepeated() {
  140. $this->markTestIncomplete('Not working for some reason');
  141. $this->Task->expects($this->never())->method('err');
  142. $this->Task->expects($this->never())->method('_stop');
  143. $file = TESTS . 'TestCase/Model/MyClassTest.php';
  144. $this->Task->expects($this->at(1))->method('createFile')
  145. ->with($file, $this->anything());
  146. $this->Task->expects($this->at(3))->method('createFile')
  147. ->with($file, $this->anything());
  148. $file = TESTS . 'TestCase/Controller/CommentsControllerTest.php';
  149. $this->Task->expects($this->at(5))->method('createFile')
  150. ->with($file, $this->anything());
  151. $this->Task->bake('Model', 'MyClass');
  152. $this->Task->bake('Model', 'MyClass');
  153. $this->Task->bake('Controller', 'Comments');
  154. }
  155. /**
  156. * Test that method introspection pulls all relevant non parent class
  157. * methods into the test case.
  158. *
  159. * @return void
  160. */
  161. public function testMethodIntrospection() {
  162. $result = $this->Task->getTestableMethods('TestApp\Model\Table\ArticlesTable');
  163. $expected = array('dosomething', 'dosomethingelse');
  164. $this->assertEquals($expected, array_map('strtolower', $result));
  165. }
  166. /**
  167. * test that the generation of fixtures works correctly.
  168. *
  169. * @return void
  170. */
  171. public function testFixtureArrayGenerationFromModel() {
  172. $this->markTestIncomplete('Not working right now');
  173. $subject = new TestTaskArticlesTable();
  174. $result = $this->Task->generateFixtureList($subject);
  175. $expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
  176. 'app.test_task_article', 'app.test_task_tag');
  177. $this->assertEquals(sort($expected), sort($result));
  178. }
  179. /**
  180. * test that the generation of fixtures works correctly.
  181. *
  182. * @return void
  183. */
  184. public function testFixtureArrayGenerationFromController() {
  185. $this->markTestIncomplete('Not working right now');
  186. $subject = new TestTaskCommentsController();
  187. $result = $this->Task->generateFixtureList($subject);
  188. $expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
  189. 'app.test_task_article', 'app.test_task_tag');
  190. $this->assertEquals(sort($expected), sort($result));
  191. }
  192. /**
  193. * creating test subjects should clear the registry so the registry is always fresh
  194. *
  195. * @return void
  196. */
  197. public function testRegistryClearWhenBuildingTestObjects() {
  198. $this->markTestIncomplete('Not working right now');
  199. $model = new TestTaskCommentsTable();
  200. $model->bindModel(array(
  201. 'belongsTo' => array(
  202. 'Random' => array(
  203. 'className' => 'TestTaskArticle',
  204. 'foreignKey' => 'article_id',
  205. )
  206. )
  207. ));
  208. $keys = ClassRegistry::keys();
  209. $this->assertTrue(in_array('test_task_comment', $keys));
  210. $this->Task->buildTestSubject('Model', 'TestTaskComment');
  211. $keys = ClassRegistry::keys();
  212. $this->assertFalse(in_array('random', $keys));
  213. }
  214. /**
  215. * test that getClassName returns the user choice as a class name.
  216. *
  217. * @return void
  218. */
  219. public function testGetClassName() {
  220. $objects = App::objects('model');
  221. $this->skipIf(empty($objects), 'No models in app.');
  222. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));
  223. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
  224. $result = $this->Task->getClassName('Model');
  225. $this->assertEquals('MyCustomClass', $result);
  226. $result = $this->Task->getClassName('Model');
  227. $options = App::objects('model');
  228. $this->assertEquals($options[0], $result);
  229. }
  230. /**
  231. * Test the user interaction for defining additional fixtures.
  232. *
  233. * @return void
  234. */
  235. public function testGetUserFixtures() {
  236. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  237. $this->Task->expects($this->at(1))->method('in')
  238. ->will($this->returnValue('app.pizza, app.topping, app.side_dish'));
  239. $result = $this->Task->getUserFixtures();
  240. $expected = array('app.pizza', 'app.topping', 'app.side_dish');
  241. $this->assertEquals($expected, $result);
  242. }
  243. /**
  244. * test that resolving class names works
  245. *
  246. * @return void
  247. */
  248. public function testGetRealClassname() {
  249. $result = $this->Task->getRealClassname('Model', 'Post');
  250. $this->assertEquals('App\Model\Post', $result);
  251. $result = $this->Task->getRealClassname('Controller', 'Posts');
  252. $this->assertEquals('App\Controller\PostsController', $result);
  253. $result = $this->Task->getRealClassname('Controller', 'PostsController');
  254. $this->assertEquals('App\Controller\PostsController', $result);
  255. $result = $this->Task->getRealClassname('Controller', 'AlertTypes');
  256. $this->assertEquals('App\Controller\AlertTypesController', $result);
  257. $result = $this->Task->getRealClassname('Helper', 'Form');
  258. $this->assertEquals('App\View\Helper\FormHelper', $result);
  259. $result = $this->Task->getRealClassname('Helper', 'FormHelper');
  260. $this->assertEquals('App\View\Helper\FormHelper', $result);
  261. $result = $this->Task->getRealClassname('Behavior', 'Tree');
  262. $this->assertEquals('App\Model\Behavior\TreeBehavior', $result);
  263. $result = $this->Task->getRealClassname('Component', 'Auth');
  264. $this->assertEquals('App\Controller\Component\AuthComponent', $result);
  265. $result = $this->Task->getRealClassname('Component', 'Utility', 'TestPlugin');
  266. $this->assertEquals('TestPlugin\Controller\Component\UtilityComponent', $result);
  267. }
  268. /**
  269. * Test baking a test for a concrete model.
  270. *
  271. * @return void
  272. */
  273. public function testBakeModelTest() {
  274. $this->markTestIncomplete('Model tests need reworking.');
  275. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  276. $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
  277. $result = $this->Task->bake('Model', 'TestTaskArticle');
  278. $this->assertContains("use App\Model\TestTaskArticle", $result);
  279. $this->assertContains('class TestTaskArticleTest extends TestCase', $result);
  280. $this->assertContains('function setUp()', $result);
  281. $this->assertContains("\$this->TestTaskArticle = ClassRegistry::init('TestTaskArticle')", $result);
  282. $this->assertContains('function tearDown()', $result);
  283. $this->assertContains('unset($this->TestTaskArticle)', $result);
  284. }
  285. /**
  286. * test baking controller test files
  287. *
  288. * @return void
  289. */
  290. public function testBakeControllerTest() {
  291. $this->markTestIncomplete('This test explodes because of namespicing');
  292. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  293. $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
  294. $result = $this->Task->bake('Controller', 'TestTaskComments');
  295. $this->assertContains("App::uses('TestTaskCommentsController', 'Controller')", $result);
  296. $this->assertContains('class TestTaskCommentsControllerTest extends ControllerTestCase', $result);
  297. $this->assertNotContains('function setUp()', $result);
  298. $this->assertNotContains("\$this->TestTaskComments = new TestTaskCommentsController()", $result);
  299. $this->assertNotContains("\$this->TestTaskComments->constructClasses()", $result);
  300. $this->assertNotContains('function tearDown()', $result);
  301. $this->assertNotContains('unset($this->TestTaskComments)', $result);
  302. $this->assertContains("'app.test_task_article'", $result);
  303. $this->assertContains("'app.test_task_comment'", $result);
  304. $this->assertContains("'app.test_task_tag'", $result);
  305. $this->assertContains("'app.articles_tag'", $result);
  306. }
  307. /**
  308. * test baking component test files,
  309. *
  310. * @return void
  311. */
  312. public function testBakeComponentTest() {
  313. Configure::write('App.namespace', 'TestApp');
  314. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  315. $result = $this->Task->bake('Component', 'Apple');
  316. $this->assertContains('use Cake\Controller\ComponentRegistry', $result);
  317. $this->assertContains('use TestApp\Controller\Component\AppleComponent', $result);
  318. $this->assertContains('class AppleComponentTest extends TestCase', $result);
  319. $this->assertContains('function setUp()', $result);
  320. $this->assertContains("\$registry = new ComponentRegistry()", $result);
  321. $this->assertContains("\$this->Apple = new AppleComponent(\$registry)", $result);
  322. $this->assertContains('function testStartup()', $result);
  323. $this->assertContains('$this->markTestIncomplete(\'testStartup not implemented.\')', $result);
  324. $this->assertContains('function tearDown()', $result);
  325. $this->assertContains('unset($this->Apple)', $result);
  326. }
  327. /**
  328. * test baking behavior test files,
  329. *
  330. * @return void
  331. */
  332. public function testBakeBehaviorTest() {
  333. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  334. $result = $this->Task->bake('Behavior', 'Example');
  335. $this->assertContains("use App\Model\Behavior\ExampleBehavior;", $result);
  336. $this->assertContains('class ExampleBehaviorTest extends TestCase', $result);
  337. $this->assertContains('function setUp()', $result);
  338. $this->assertContains("\$this->Example = new ExampleBehavior()", $result);
  339. $this->assertContains('function tearDown()', $result);
  340. $this->assertContains('unset($this->Example)', $result);
  341. }
  342. /**
  343. * test baking helper test files,
  344. *
  345. * @return void
  346. */
  347. public function testBakeHelperTest() {
  348. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  349. $result = $this->Task->bake('Helper', 'Example');
  350. $this->assertContains("use Cake\View\View;", $result);
  351. $this->assertContains("use App\View\Helper\ExampleHelper;", $result);
  352. $this->assertContains('class ExampleHelperTest extends TestCase', $result);
  353. $this->assertContains('function setUp()', $result);
  354. $this->assertContains("\$View = new View()", $result);
  355. $this->assertContains("\$this->Example = new ExampleHelper(\$View)", $result);
  356. $this->assertContains('function tearDown()', $result);
  357. $this->assertContains('unset($this->Example)', $result);
  358. }
  359. /**
  360. * test Constructor generation ensure that constructClasses is called for controllers
  361. *
  362. * @return void
  363. */
  364. public function testGenerateConstructor() {
  365. $result = $this->Task->generateConstructor('controller', 'PostsController', null);
  366. $expected = array('', '', '');
  367. $this->assertEquals($expected, $result);
  368. $result = $this->Task->generateConstructor('model', 'Post', null);
  369. $expected = array('', "ClassRegistry::init('Post');\n", '');
  370. $this->assertEquals($expected, $result);
  371. $result = $this->Task->generateConstructor('helper', 'FormHelper', null);
  372. $expected = array("\$View = new View();\n", "new FormHelper(\$View);\n", '');
  373. $this->assertEquals($expected, $result);
  374. }
  375. /**
  376. * Test generateUses()
  377. */
  378. public function testGenerateUses() {
  379. $result = $this->Task->generateUses('model', 'Model', 'App\Model\Post');
  380. $expected = array(
  381. 'App\Model\Post',
  382. );
  383. $this->assertEquals($expected, $result);
  384. $result = $this->Task->generateUses('controller', 'Controller', 'App\Controller\PostsController');
  385. $expected = array(
  386. 'App\Controller\PostsController',
  387. );
  388. $this->assertEquals($expected, $result);
  389. $result = $this->Task->generateUses('helper', 'View/Helper', 'App\View\Helper\FormHelper');
  390. $expected = array(
  391. 'Cake\View\View',
  392. 'App\View\Helper\FormHelper',
  393. );
  394. $this->assertEquals($expected, $result);
  395. $result = $this->Task->generateUses('component', 'Controller/Component', 'App\Controller\Component\AuthComponent');
  396. $expected = array(
  397. 'Cake\Controller\ComponentRegistry',
  398. 'App\Controller\Component\AuthComponent',
  399. );
  400. $this->assertEquals($expected, $result);
  401. }
  402. /**
  403. * Test that mock class generation works for the appropriate classes
  404. *
  405. * @return void
  406. */
  407. public function testMockClassGeneration() {
  408. $result = $this->Task->hasMockClass('controller');
  409. $this->assertTrue($result);
  410. }
  411. /**
  412. * test bake() with a -plugin param
  413. *
  414. * @return void
  415. */
  416. public function testBakeWithPlugin() {
  417. $this->Task->plugin = 'TestTest';
  418. //fake plugin path
  419. Plugin::load('TestTest', array('path' => APP . 'Plugin/TestTest/'));
  420. $path = APP . 'Plugin/TestTest/Test/TestCase/View/Helper/FormHelperTest.php';
  421. $this->Task->expects($this->once())->method('createFile')
  422. ->with($path, $this->anything());
  423. $this->Task->bake('Helper', 'Form');
  424. Plugin::unload();
  425. }
  426. /**
  427. * test interactive with plugins lists from the plugin
  428. *
  429. * @return void
  430. */
  431. public function testInteractiveWithPlugin() {
  432. $this->markTestIncomplete();
  433. $testApp = TEST_APP . 'Plugin/';
  434. Plugin::load('TestPlugin');
  435. $this->Task->plugin = 'TestPlugin';
  436. $path = $testApp . 'TestPlugin/Test/TestCase/View/Helper/OtherHelperTest.php';
  437. $this->Task->expects($this->any())
  438. ->method('in')
  439. ->will($this->onConsecutiveCalls(
  440. 5, //helper
  441. 1 //OtherHelper
  442. ));
  443. $this->Task->expects($this->once())
  444. ->method('createFile')
  445. ->with($path, $this->anything());
  446. $this->Task->stdout->expects($this->at(21))
  447. ->method('write')
  448. ->with('1. OtherHelperHelper');
  449. $this->Task->execute();
  450. }
  451. public static function caseFileNameProvider() {
  452. return array(
  453. array('Model', 'Post', 'TestCase/Model/PostTest.php'),
  454. array('Helper', 'Form', 'TestCase/View/Helper/FormHelperTest.php'),
  455. array('Controller', 'Posts', 'TestCase/Controller/PostsControllerTest.php'),
  456. array('Behavior', 'Tree', 'TestCase/Model/Behavior/TreeBehaviorTest.php'),
  457. array('Component', 'Auth', 'TestCase/Controller/Component/AuthComponentTest.php'),
  458. array('model', 'Post', 'TestCase/Model/PostTest.php'),
  459. array('helper', 'Form', 'TestCase/View/Helper/FormHelperTest.php'),
  460. array('controller', 'Posts', 'TestCase/Controller/PostsControllerTest.php'),
  461. array('behavior', 'Tree', 'TestCase/Model/Behavior/TreeBehaviorTest.php'),
  462. array('component', 'Auth', 'TestCase/Controller/Component/AuthComponentTest.php'),
  463. );
  464. }
  465. /**
  466. * Test filename generation for each type + plugins
  467. *
  468. * @dataProvider caseFileNameProvider
  469. * @return void
  470. */
  471. public function testTestCaseFileName($type, $class, $expected) {
  472. $this->markTestIncomplete();
  473. $this->Task->path = DS . 'my/path/tests/';
  474. $result = $this->Task->testCaseFileName($type, $class);
  475. $expected = $this->Task->path . $expected;
  476. $this->assertEquals($expected, $result);
  477. }
  478. /**
  479. * Test filename generation for plugins.
  480. *
  481. * @return void
  482. */
  483. public function testTestCaseFileNamePlugin() {
  484. $this->markTestIncomplete();
  485. $this->Task->path = DS . 'my/path/tests/';
  486. Plugin::load('TestTest', array('path' => APP . 'Plugin/TestTest/'));
  487. $this->Task->plugin = 'TestTest';
  488. $result = $this->Task->testCaseFileName('Model', 'Post');
  489. $expected = APP . 'Plugin/TestTest/Test/TestCase/Model/PostTest.php';
  490. $this->assertEquals($expected, $result);
  491. }
  492. /**
  493. * test execute with a type defined
  494. *
  495. * @return void
  496. */
  497. public function testExecuteWithOneArg() {
  498. $this->markTestIncomplete('Tests using models need work');
  499. $this->Task->args[0] = 'Model';
  500. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
  501. $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
  502. $this->Task->expects($this->once())->method('createFile')
  503. ->with(
  504. $this->anything(),
  505. $this->stringContains('class TestTaskTagTest extends TestCase')
  506. );
  507. $this->Task->execute();
  508. }
  509. /**
  510. * test execute with type and class name defined
  511. *
  512. * @return void
  513. */
  514. public function testExecuteWithTwoArgs() {
  515. $this->markTestIncomplete('Tests using models need work');
  516. $this->Task->args = array('Model', 'TestTaskTag');
  517. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
  518. $this->Task->expects($this->once())->method('createFile')
  519. ->with(
  520. $this->anything(),
  521. $this->stringContains('class TestTaskTagTest extends TestCase')
  522. );
  523. $this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
  524. $this->Task->execute();
  525. }
  526. /**
  527. * test execute with type and class name defined and lower case.
  528. *
  529. * @return void
  530. */
  531. public function testExecuteWithTwoArgsLowerCase() {
  532. $this->markTestIncomplete('Tests using models need work');
  533. $this->Task->args = array('model', 'TestTaskTag');
  534. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
  535. $this->Task->expects($this->once())->method('createFile')
  536. ->with(
  537. $this->anything(),
  538. $this->stringContains('class TestTaskTagTest extends TestCase')
  539. );
  540. $this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
  541. $this->Task->execute();
  542. }
  543. /**
  544. * Data provider for mapType() tests.
  545. *
  546. * @return array
  547. */
  548. public static function mapTypeProvider() {
  549. return array(
  550. array('controller', 'Controller'),
  551. array('Controller', 'Controller'),
  552. array('component', 'Controller/Component'),
  553. array('Component', 'Controller/Component'),
  554. array('table', 'Model/Table'),
  555. array('Table', 'Model/Table'),
  556. array('entity', 'Model/Entity'),
  557. array('Entity', 'Model/Entity'),
  558. array('behavior', 'Model/Behavior'),
  559. array('Behavior', 'Model/Behavior'),
  560. array('helper', 'View/Helper'),
  561. array('Helper', 'View/Helper'),
  562. array('Helper', 'View/Helper'),
  563. );
  564. }
  565. /**
  566. * Test that mapType returns the correct package names.
  567. *
  568. * @dataProvider mapTypeProvider
  569. * @return void
  570. */
  571. public function testMapType($original, $expected) {
  572. $this->assertEquals($expected, $this->Task->mapType($original));
  573. }
  574. }