TestTaskTest.php 22 KB

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