TestTaskTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. <?php
  2. /**
  3. * TestTaskTest file
  4. *
  5. * Test Case for test generation shell task
  6. *
  7. * PHP 5
  8. *
  9. * CakePHP : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2005-2012, Cake Software Foundation, Inc.
  11. *
  12. * Licensed under The MIT License
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
  16. * @link http://cakephp.org CakePHP Project
  17. * @package Cake.Test.Case.Console.Command.Task
  18. * @since CakePHP v 1.2.0.7726
  19. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  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. * Test Article model
  31. *
  32. * @package Cake.Test.Case.Console.Command.Task
  33. * @package Cake.Test.Case.Console.Command.Task
  34. */
  35. class TestTaskArticle extends Model {
  36. /**
  37. * Model name
  38. *
  39. * @var string
  40. */
  41. public $name = 'TestTaskArticle';
  42. /**
  43. * Table name to use
  44. *
  45. * @var string
  46. */
  47. public $useTable = 'articles';
  48. /**
  49. * HasMany Associations
  50. *
  51. * @var array
  52. */
  53. public $hasMany = array(
  54. 'Comment' => array(
  55. 'className' => 'TestTask.TestTaskComment',
  56. 'foreignKey' => 'article_id',
  57. )
  58. );
  59. /**
  60. * Has and Belongs To Many Associations
  61. *
  62. * @var array
  63. */
  64. public $hasAndBelongsToMany = array(
  65. 'Tag' => array(
  66. 'className' => 'TestTaskTag',
  67. 'joinTable' => 'articles_tags',
  68. 'foreignKey' => 'article_id',
  69. 'associationForeignKey' => 'tag_id'
  70. )
  71. );
  72. /**
  73. * Example public method
  74. *
  75. * @return void
  76. */
  77. public function doSomething() {
  78. }
  79. /**
  80. * Example Secondary public method
  81. *
  82. * @return void
  83. */
  84. public function doSomethingElse() {
  85. }
  86. /**
  87. * Example protected method
  88. *
  89. * @return void
  90. */
  91. protected function _innerMethod() {
  92. }
  93. }
  94. /**
  95. * Tag Testing Model
  96. *
  97. * @package Cake.Test.Case.Console.Command.Task
  98. * @package Cake.Test.Case.Console.Command.Task
  99. */
  100. class TestTaskTag extends Model {
  101. /**
  102. * Model name
  103. *
  104. * @var string
  105. */
  106. public $name = 'TestTaskTag';
  107. /**
  108. * Table name
  109. *
  110. * @var string
  111. */
  112. public $useTable = 'tags';
  113. /**
  114. * Has and Belongs To Many Associations
  115. *
  116. * @var array
  117. */
  118. public $hasAndBelongsToMany = array(
  119. 'Article' => array(
  120. 'className' => 'TestTaskArticle',
  121. 'joinTable' => 'articles_tags',
  122. 'foreignKey' => 'tag_id',
  123. 'associationForeignKey' => 'article_id'
  124. )
  125. );
  126. }
  127. /**
  128. * Simulated plugin
  129. *
  130. * @package Cake.Test.Case.Console.Command.Task
  131. * @package Cake.Test.Case.Console.Command.Task
  132. */
  133. class TestTaskAppModel extends Model {
  134. }
  135. /**
  136. * Testing AppMode (TaskComment)
  137. *
  138. * @package Cake.Test.Case.Console.Command.Task
  139. * @package Cake.Test.Case.Console.Command.Task
  140. */
  141. class TestTaskComment extends TestTaskAppModel {
  142. /**
  143. * Model name
  144. *
  145. * @var string
  146. */
  147. public $name = 'TestTaskComment';
  148. /**
  149. * Table name
  150. *
  151. * @var string
  152. */
  153. public $useTable = 'comments';
  154. /**
  155. * Belongs To Associations
  156. *
  157. * @var array
  158. */
  159. public $belongsTo = array(
  160. 'Article' => array(
  161. 'className' => 'TestTaskArticle',
  162. 'foreignKey' => 'article_id',
  163. )
  164. );
  165. }
  166. /**
  167. * Test Task Comments Controller
  168. *
  169. * @package Cake.Test.Case.Console.Command.Task
  170. * @package Cake.Test.Case.Console.Command.Task
  171. */
  172. class TestTaskCommentsController extends Controller {
  173. /**
  174. * Controller Name
  175. *
  176. * @var string
  177. */
  178. public $name = 'TestTaskComments';
  179. /**
  180. * Models to use
  181. *
  182. * @var array
  183. */
  184. public $uses = array('TestTaskComment', 'TestTaskTag');
  185. }
  186. /**
  187. * TestTaskTest class
  188. *
  189. * @package Cake.Test.Case.Console.Command.Task
  190. */
  191. class TestTaskTest extends CakeTestCase {
  192. /**
  193. * Fixtures
  194. *
  195. * @var string
  196. */
  197. public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
  198. /**
  199. * setUp method
  200. *
  201. * @return void
  202. */
  203. public function setUp() {
  204. parent::setUp();
  205. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  206. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  207. $this->Task = $this->getMock('TestTask',
  208. array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
  209. array($out, $out, $in)
  210. );
  211. $this->Task->name = 'Test';
  212. $this->Task->Template = new TemplateTask($out, $out, $in);
  213. }
  214. /**
  215. * tearDown method
  216. *
  217. * @return void
  218. */
  219. public function tearDown() {
  220. parent::tearDown();
  221. unset($this->Task);
  222. CakePlugin::unload();
  223. }
  224. /**
  225. * Test that file path generation doesn't continuously append paths.
  226. *
  227. * @return void
  228. */
  229. public function testFilePathGenerationModelRepeated() {
  230. $this->Task->expects($this->never())->method('err');
  231. $this->Task->expects($this->never())->method('_stop');
  232. $file = TESTS . 'Case' . DS . 'Model' . DS . 'MyClassTest.php';
  233. $this->Task->expects($this->at(1))->method('createFile')
  234. ->with($file, $this->anything());
  235. $this->Task->expects($this->at(3))->method('createFile')
  236. ->with($file, $this->anything());
  237. $file = TESTS . 'Case' . DS . 'Controller' . DS . 'CommentsControllerTest.php';
  238. $this->Task->expects($this->at(5))->method('createFile')
  239. ->with($file, $this->anything());
  240. $this->Task->bake('Model', 'MyClass');
  241. $this->Task->bake('Model', 'MyClass');
  242. $this->Task->bake('Controller', 'Comments');
  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. * test that the generation of fixtures works correctly.
  257. *
  258. * @return void
  259. */
  260. public function testFixtureArrayGenerationFromModel() {
  261. $subject = ClassRegistry::init('TestTaskArticle');
  262. $result = $this->Task->generateFixtureList($subject);
  263. $expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
  264. 'app.test_task_article', 'app.test_task_tag');
  265. $this->assertEquals(sort($expected), sort($result));
  266. }
  267. /**
  268. * test that the generation of fixtures works correctly.
  269. *
  270. * @return void
  271. */
  272. public function testFixtureArrayGenerationFromController() {
  273. $subject = new TestTaskCommentsController();
  274. $result = $this->Task->generateFixtureList($subject);
  275. $expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
  276. 'app.test_task_article', 'app.test_task_tag');
  277. $this->assertEquals(sort($expected), sort($result));
  278. }
  279. /**
  280. * test user interaction to get object type
  281. *
  282. * @return void
  283. */
  284. public function testGetObjectType() {
  285. $this->Task->expects($this->once())->method('_stop');
  286. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('q'));
  287. $this->Task->expects($this->at(2))->method('in')->will($this->returnValue(2));
  288. $this->Task->getObjectType();
  289. $result = $this->Task->getObjectType();
  290. $this->assertEquals($this->Task->classTypes['Controller'], $result);
  291. }
  292. /**
  293. * creating test subjects should clear the registry so the registry is always fresh
  294. *
  295. * @return void
  296. */
  297. public function testRegistryClearWhenBuildingTestObjects() {
  298. ClassRegistry::flush();
  299. $model = ClassRegistry::init('TestTaskComment');
  300. $model->bindModel(array(
  301. 'belongsTo' => array(
  302. 'Random' => array(
  303. 'className' => 'TestTaskArticle',
  304. 'foreignKey' => 'article_id',
  305. )
  306. )
  307. ));
  308. $keys = ClassRegistry::keys();
  309. $this->assertTrue(in_array('test_task_comment', $keys));
  310. $object = $this->Task->buildTestSubject('Model', 'TestTaskComment');
  311. $keys = ClassRegistry::keys();
  312. $this->assertFalse(in_array('random', $keys));
  313. }
  314. /**
  315. * test that getClassName returns the user choice as a classname.
  316. *
  317. * @return void
  318. */
  319. public function testGetClassName() {
  320. $objects = App::objects('model');
  321. $this->skipIf(empty($objects), 'No models in app.');
  322. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));
  323. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
  324. $result = $this->Task->getClassName('Model');
  325. $this->assertEquals('MyCustomClass', $result);
  326. $result = $this->Task->getClassName('Model');
  327. $options = App::objects('model');
  328. $this->assertEquals($options[0], $result);
  329. }
  330. /**
  331. * Test the user interaction for defining additional fixtures.
  332. *
  333. * @return void
  334. */
  335. public function testGetUserFixtures() {
  336. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  337. $this->Task->expects($this->at(1))->method('in')
  338. ->will($this->returnValue('app.pizza, app.topping, app.side_dish'));
  339. $result = $this->Task->getUserFixtures();
  340. $expected = array('app.pizza', 'app.topping', 'app.side_dish');
  341. $this->assertEquals($expected, $result);
  342. }
  343. /**
  344. * test that resolving classnames works
  345. *
  346. * @return void
  347. */
  348. public function testGetRealClassname() {
  349. $result = $this->Task->getRealClassname('Model', 'Post');
  350. $this->assertEquals('Post', $result);
  351. $result = $this->Task->getRealClassname('Controller', 'Posts');
  352. $this->assertEquals('PostsController', $result);
  353. $result = $this->Task->getRealClassname('Controller', 'PostsController');
  354. $this->assertEquals('PostsController', $result);
  355. $result = $this->Task->getRealClassname('Controller', 'AlertTypes');
  356. $this->assertEquals('AlertTypesController', $result);
  357. $result = $this->Task->getRealClassname('Helper', 'Form');
  358. $this->assertEquals('FormHelper', $result);
  359. $result = $this->Task->getRealClassname('Helper', 'FormHelper');
  360. $this->assertEquals('FormHelper', $result);
  361. $result = $this->Task->getRealClassname('Behavior', 'Containable');
  362. $this->assertEquals('ContainableBehavior', $result);
  363. $result = $this->Task->getRealClassname('Behavior', 'ContainableBehavior');
  364. $this->assertEquals('ContainableBehavior', $result);
  365. $result = $this->Task->getRealClassname('Component', 'Auth');
  366. $this->assertEquals('AuthComponent', $result);
  367. }
  368. /**
  369. * test baking files. The conditionally run tests are known to fail in PHP4
  370. * as PHP4 classnames are all lower case, breaking the plugin path inflection.
  371. *
  372. * @return void
  373. */
  374. public function testBakeModelTest() {
  375. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  376. $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
  377. $result = $this->Task->bake('Model', 'TestTaskArticle');
  378. $this->assertContains("App::uses('TestTaskArticle', 'Model')", $result);
  379. $this->assertContains('class TestTaskArticleTest extends CakeTestCase', $result);
  380. $this->assertContains('function setUp()', $result);
  381. $this->assertContains("\$this->TestTaskArticle = ClassRegistry::init('TestTaskArticle')", $result);
  382. $this->assertContains('function tearDown()', $result);
  383. $this->assertContains('unset($this->TestTaskArticle)', $result);
  384. $this->assertContains('function testDoSomething()', $result);
  385. $this->assertContains('function testDoSomethingElse()', $result);
  386. $this->assertContains("'app.test_task_article'", $result);
  387. $this->assertContains("'plugin.test_task.test_task_comment'", $result);
  388. $this->assertContains("'app.test_task_tag'", $result);
  389. $this->assertContains("'app.articles_tag'", $result);
  390. }
  391. /**
  392. * test baking controller test files, ensure that the stub class is generated.
  393. * Conditional assertion is known to fail on PHP4 as classnames are all lower case
  394. * causing issues with inflection of path name from classname.
  395. *
  396. * @return void
  397. */
  398. public function testBakeControllerTest() {
  399. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  400. $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
  401. $result = $this->Task->bake('Controller', 'TestTaskComments');
  402. $this->assertContains("App::uses('TestTaskCommentsController', 'Controller')", $result);
  403. $this->assertContains('class TestTaskCommentsControllerTest extends CakeTestCase', $result);
  404. $this->assertContains('class TestTestTaskCommentsController extends TestTaskCommentsController', $result);
  405. $this->assertContains('public $autoRender = false', $result);
  406. $this->assertContains('function redirect($url, $status = null, $exit = true)', $result);
  407. $this->assertContains('function setUp()', $result);
  408. $this->assertContains("\$this->TestTaskComments = new TestTestTaskCommentsController()", $result);
  409. $this->assertContains("\$this->TestTaskComments->constructClasses()", $result);
  410. $this->assertContains('function tearDown()', $result);
  411. $this->assertContains('unset($this->TestTaskComments)', $result);
  412. $this->assertContains("'app.test_task_article'", $result);
  413. $this->assertContains("'plugin.test_task.test_task_comment'", $result);
  414. $this->assertContains("'app.test_task_tag'", $result);
  415. $this->assertContains("'app.articles_tag'", $result);
  416. }
  417. /**
  418. * test Constructor generation ensure that constructClasses is called for controllers
  419. *
  420. * @return void
  421. */
  422. public function testGenerateConstructor() {
  423. $result = $this->Task->generateConstructor('controller', 'PostsController');
  424. $expected = array('', "new TestPostsController();\n", "\$this->Posts->constructClasses();\n");
  425. $this->assertEquals($expected, $result);
  426. $result = $this->Task->generateConstructor('model', 'Post');
  427. $expected = array('', "ClassRegistry::init('Post');\n", '');
  428. $this->assertEquals($expected, $result);
  429. $result = $this->Task->generateConstructor('helper', 'FormHelper');
  430. $expected = array("\$View = new View();\n", "new FormHelper(\$View);\n", '');
  431. $this->assertEquals($expected, $result);
  432. }
  433. /**
  434. * Test generateUses()
  435. */
  436. public function testGenerateUses() {
  437. $result = $this->Task->generateUses('model', 'Model', 'Post');
  438. $expected = array(
  439. array('Post', 'Model')
  440. );
  441. $this->assertEquals($expected, $result);
  442. $result = $this->Task->generateUses('controller', 'Controller', 'PostsController');
  443. $expected = array(
  444. array('PostsController', 'Controller')
  445. );
  446. $this->assertEquals($expected, $result);
  447. $result = $this->Task->generateUses('helper', 'View/Helper', 'FormHelper');
  448. $expected = array(
  449. array('View', 'View'),
  450. array('Helper', 'View'),
  451. array('FormHelper', 'View/Helper'),
  452. );
  453. $this->assertEquals($expected, $result);
  454. $result = $this->Task->generateUses('component', 'Controller/Component', 'AuthComponent');
  455. $expected = array(
  456. array('ComponentCollection', 'Controller'),
  457. array('Component', 'Controller'),
  458. array('AuthComponent', 'Controller/Component')
  459. );
  460. $this->assertEquals($expected, $result);
  461. }
  462. /**
  463. * Test that mock class generation works for the appropriate classes
  464. *
  465. * @return void
  466. */
  467. public function testMockClassGeneration() {
  468. $result = $this->Task->hasMockClass('controller');
  469. $this->assertTrue($result);
  470. }
  471. /**
  472. * test bake() with a -plugin param
  473. *
  474. * @return void
  475. */
  476. public function testBakeWithPlugin() {
  477. $this->Task->plugin = 'TestTest';
  478. //fake plugin path
  479. CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
  480. $path = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php';
  481. $this->Task->expects($this->once())->method('createFile')
  482. ->with($path, $this->anything());
  483. $this->Task->bake('Helper', 'Form');
  484. CakePlugin::unload();
  485. }
  486. /**
  487. * test interactive with plugins lists from the plugin
  488. *
  489. * @return void
  490. */
  491. public function testInteractiveWithPlugin() {
  492. $testApp = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
  493. App::build(array(
  494. 'Plugin' => array($testApp)
  495. ), App::RESET);
  496. CakePlugin::load('TestPlugin');
  497. $this->Task->plugin = 'TestPlugin';
  498. $path = $testApp . 'TestPlugin' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'OtherHelperTest.php';
  499. $this->Task->expects($this->any())
  500. ->method('in')
  501. ->will($this->onConsecutiveCalls(
  502. 5, //helper
  503. 1 //OtherHelper
  504. ));
  505. $this->Task->expects($this->once())
  506. ->method('createFile')
  507. ->with($path, $this->anything());
  508. $this->Task->stdout->expects($this->at(21))
  509. ->method('write')
  510. ->with('1. OtherHelperHelper');
  511. $this->Task->execute();
  512. }
  513. public static function caseFileNameProvider() {
  514. return array(
  515. array('Model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),
  516. array('Helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),
  517. array('Controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),
  518. array('Behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),
  519. array('Component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),
  520. array('model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),
  521. array('helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),
  522. array('controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),
  523. array('behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),
  524. array('component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),
  525. );
  526. }
  527. /**
  528. * Test filename generation for each type + plugins
  529. *
  530. * @dataProvider caseFileNameProvider
  531. * @return void
  532. */
  533. public function testTestCaseFileName($type, $class, $expected) {
  534. $this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
  535. $result = $this->Task->testCaseFileName($type, $class);
  536. $expected = $this->Task->path . $expected;
  537. $this->assertEquals($expected, $result);
  538. }
  539. /**
  540. * Test filename generation for plugins.
  541. *
  542. * @return void
  543. */
  544. public function testTestCaseFileNamePlugin() {
  545. $this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
  546. CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS ));
  547. $this->Task->plugin = 'TestTest';
  548. $result = $this->Task->testCaseFileName('Model', 'Post');
  549. $expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php';
  550. $this->assertEquals($expected, $result);
  551. }
  552. /**
  553. * test execute with a type defined
  554. *
  555. * @return void
  556. */
  557. public function testExecuteWithOneArg() {
  558. $this->Task->args[0] = 'Model';
  559. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
  560. $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
  561. $this->Task->expects($this->once())->method('createFile')
  562. ->with(
  563. $this->anything(),
  564. $this->stringContains('class TestTaskTagTest extends CakeTestCase')
  565. );
  566. $this->Task->execute();
  567. }
  568. /**
  569. * test execute with type and class name defined
  570. *
  571. * @return void
  572. */
  573. public function testExecuteWithTwoArgs() {
  574. $this->Task->args = array('Model', 'TestTaskTag');
  575. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
  576. $this->Task->expects($this->once())->method('createFile')
  577. ->with(
  578. $this->anything(),
  579. $this->stringContains('class TestTaskTagTest extends CakeTestCase')
  580. );
  581. $this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
  582. $this->Task->execute();
  583. }
  584. /**
  585. * test execute with type and class name defined and lower case.
  586. *
  587. * @return void
  588. */
  589. public function testExecuteWithTwoArgsLowerCase() {
  590. $this->Task->args = array('model', 'TestTaskTag');
  591. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
  592. $this->Task->expects($this->once())->method('createFile')
  593. ->with(
  594. $this->anything(),
  595. $this->stringContains('class TestTaskTagTest extends CakeTestCase')
  596. );
  597. $this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
  598. $this->Task->execute();
  599. }
  600. /**
  601. * Data provider for mapType() tests.
  602. *
  603. * @return array
  604. */
  605. public static function mapTypeProvider() {
  606. return array(
  607. array('controller', null, 'Controller'),
  608. array('Controller', null, 'Controller'),
  609. array('component', null, 'Controller/Component'),
  610. array('Component', null, 'Controller/Component'),
  611. array('model', null, 'Model'),
  612. array('Model', null, 'Model'),
  613. array('behavior', null, 'Model/Behavior'),
  614. array('Behavior', null, 'Model/Behavior'),
  615. array('helper', null, 'View/Helper'),
  616. array('Helper', null, 'View/Helper'),
  617. array('Helper', 'DebugKit', 'DebugKit.View/Helper'),
  618. );
  619. }
  620. /**
  621. * Test that mapType returns the correct package names.
  622. *
  623. * @dataProvider mapTypeProvider
  624. * @return void
  625. */
  626. public function testMapType($original, $plugin, $expected) {
  627. $this->assertEquals($expected, $this->Task->mapType($original, $plugin));
  628. }
  629. }