TestTaskTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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. AuthUsersTable'));
  132. $this->Task->stdout->expects($this->at(4))
  133. ->method('write')
  134. ->with($this->stringContains('4. AuthorsTable'));
  135. $this->Task->outputClassChoices('Table');
  136. }
  137. /**
  138. * Test generating class options for table.
  139. *
  140. * @return void
  141. */
  142. public function testOutputClassOptionsForTablePlugin() {
  143. Plugin::load('TestPlugin');
  144. $this->Task->plugin = 'TestPlugin';
  145. $this->Task->stdout->expects($this->at(0))
  146. ->method('write')
  147. ->with($this->stringContains('You must provide'));
  148. $this->Task->stdout->expects($this->at(1))
  149. ->method('write')
  150. ->with($this->stringContains('1. TestPluginCommentsTable'));
  151. $this->Task->outputClassChoices('Table');
  152. }
  153. /**
  154. * Test that file path generation doesn't continuously append paths.
  155. *
  156. * @return void
  157. */
  158. public function testFilePathGenerationModelRepeated() {
  159. $this->markTestIncomplete('Not working for some reason');
  160. $this->Task->expects($this->never())->method('err');
  161. $this->Task->expects($this->never())->method('_stop');
  162. $file = TESTS . 'TestCase/Model/MyClassTest.php';
  163. $this->Task->expects($this->at(1))->method('createFile')
  164. ->with($file, $this->anything());
  165. $this->Task->expects($this->at(3))->method('createFile')
  166. ->with($file, $this->anything());
  167. $file = TESTS . 'TestCase/Controller/CommentsControllerTest.php';
  168. $this->Task->expects($this->at(5))->method('createFile')
  169. ->with($file, $this->anything());
  170. $this->Task->bake('Model', 'MyClass');
  171. $this->Task->bake('Model', 'MyClass');
  172. $this->Task->bake('Controller', 'Comments');
  173. }
  174. /**
  175. * Test that method introspection pulls all relevant non parent class
  176. * methods into the test case.
  177. *
  178. * @return void
  179. */
  180. public function testMethodIntrospection() {
  181. $result = $this->Task->getTestableMethods('TestApp\Model\Table\ArticlesTable');
  182. $expected = array('dosomething', 'dosomethingelse');
  183. $this->assertEquals($expected, array_map('strtolower', $result));
  184. }
  185. /**
  186. * test that the generation of fixtures works correctly.
  187. *
  188. * @return void
  189. */
  190. public function testFixtureArrayGenerationFromModel() {
  191. $this->markTestIncomplete('Not working right now');
  192. $subject = new TestTaskArticlesTable();
  193. $result = $this->Task->generateFixtureList($subject);
  194. $expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
  195. 'app.test_task_article', 'app.test_task_tag');
  196. $this->assertEquals(sort($expected), sort($result));
  197. }
  198. /**
  199. * test that the generation of fixtures works correctly.
  200. *
  201. * @return void
  202. */
  203. public function testFixtureArrayGenerationFromController() {
  204. $this->markTestIncomplete('Not working right now');
  205. $subject = new TestTaskCommentsController();
  206. $result = $this->Task->generateFixtureList($subject);
  207. $expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
  208. 'app.test_task_article', 'app.test_task_tag');
  209. $this->assertEquals(sort($expected), sort($result));
  210. }
  211. /**
  212. * creating test subjects should clear the registry so the registry is always fresh
  213. *
  214. * @return void
  215. */
  216. public function testRegistryClearWhenBuildingTestObjects() {
  217. $this->markTestIncomplete('Not working right now');
  218. $model = new TestTaskCommentsTable();
  219. $model->bindModel(array(
  220. 'belongsTo' => array(
  221. 'Random' => array(
  222. 'className' => 'TestTaskArticle',
  223. 'foreignKey' => 'article_id',
  224. )
  225. )
  226. ));
  227. $keys = ClassRegistry::keys();
  228. $this->assertTrue(in_array('test_task_comment', $keys));
  229. $this->Task->buildTestSubject('Model', 'TestTaskComment');
  230. $keys = ClassRegistry::keys();
  231. $this->assertFalse(in_array('random', $keys));
  232. }
  233. /**
  234. * test that getClassName returns the user choice as a class name.
  235. *
  236. * @return void
  237. */
  238. public function testGetClassName() {
  239. $objects = App::objects('model');
  240. $this->skipIf(empty($objects), 'No models in app.');
  241. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));
  242. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
  243. $result = $this->Task->getClassName('Model');
  244. $this->assertEquals('MyCustomClass', $result);
  245. $result = $this->Task->getClassName('Model');
  246. $options = App::objects('model');
  247. $this->assertEquals($options[0], $result);
  248. }
  249. /**
  250. * Test the user interaction for defining additional fixtures.
  251. *
  252. * @return void
  253. */
  254. public function testGetUserFixtures() {
  255. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  256. $this->Task->expects($this->at(1))->method('in')
  257. ->will($this->returnValue('app.pizza, app.topping, app.side_dish'));
  258. $result = $this->Task->getUserFixtures();
  259. $expected = array('app.pizza', 'app.topping', 'app.side_dish');
  260. $this->assertEquals($expected, $result);
  261. }
  262. /**
  263. * Dataprovider for class name generation.
  264. *
  265. * @return array
  266. */
  267. public static function realClassProvider() {
  268. return [
  269. ['Entity', 'Article', 'App\Model\Entity\Article'],
  270. ['Entity', 'ArticleEntity', 'App\Model\Entity\ArticleEntity'],
  271. ['Table', 'Posts', 'App\Model\Table\PostsTable'],
  272. ['Table', 'PostsTable', 'App\Model\Table\PostsTable'],
  273. ['Controller', 'Posts', 'App\Controller\PostsController'],
  274. ['Controller', 'PostsController', 'App\Controller\PostsController'],
  275. ['Behavior', 'Timestamp', 'App\Model\Behavior\TimestampBehavior'],
  276. ['Behavior', 'TimestampBehavior', 'App\Model\Behavior\TimestampBehavior'],
  277. ['Helper', 'Form', 'App\View\Helper\FormHelper'],
  278. ['Helper', 'FormHelper', 'App\View\Helper\FormHelper'],
  279. ['Component', 'Auth', 'App\Controller\Component\AuthComponent'],
  280. ['Component', 'AuthComponent', 'App\Controller\Component\AuthComponent'],
  281. ];
  282. }
  283. /**
  284. * test that resolving class names works
  285. *
  286. * @dataProvider realClassProvider
  287. * @return void
  288. */
  289. public function testGetRealClassname($type, $name, $expected) {
  290. $result = $this->Task->getRealClassname($type, $name);
  291. $this->assertEquals($expected, $result);
  292. }
  293. /**
  294. * test resolving class names with plugins
  295. *
  296. * @return void
  297. */
  298. public function testGetRealClassnamePlugin() {
  299. Plugin::load('TestPLugin');
  300. $this->Task->plugin = 'TestPlugin';
  301. $result = $this->Task->getRealClassname('Helper', 'Asset');
  302. $expected = 'TestPlugin\View\Helper\AssetHelper';
  303. $this->assertEquals($expected, $result);
  304. }
  305. /**
  306. * Test baking a test for a concrete model.
  307. *
  308. * @return void
  309. */
  310. public function testBakeModelTest() {
  311. $this->markTestIncomplete('Model tests need reworking.');
  312. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  313. $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
  314. $result = $this->Task->bake('Model', 'TestTaskArticle');
  315. $this->assertContains("use App\Model\TestTaskArticle", $result);
  316. $this->assertContains('class TestTaskArticleTest extends TestCase', $result);
  317. $this->assertContains('function setUp()', $result);
  318. $this->assertContains("\$this->TestTaskArticle = ClassRegistry::init('TestTaskArticle')", $result);
  319. $this->assertContains('function tearDown()', $result);
  320. $this->assertContains('unset($this->TestTaskArticle)', $result);
  321. }
  322. /**
  323. * test baking controller test files
  324. *
  325. * @return void
  326. */
  327. public function testBakeControllerTest() {
  328. $this->markTestIncomplete('This test explodes because of namespicing');
  329. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  330. $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
  331. $result = $this->Task->bake('Controller', 'TestTaskComments');
  332. $this->assertContains("App::uses('TestTaskCommentsController', 'Controller')", $result);
  333. $this->assertContains('class TestTaskCommentsControllerTest extends ControllerTestCase', $result);
  334. $this->assertNotContains('function setUp()', $result);
  335. $this->assertNotContains("\$this->TestTaskComments = new TestTaskCommentsController()", $result);
  336. $this->assertNotContains("\$this->TestTaskComments->constructClasses()", $result);
  337. $this->assertNotContains('function tearDown()', $result);
  338. $this->assertNotContains('unset($this->TestTaskComments)', $result);
  339. $this->assertContains("'app.test_task_article'", $result);
  340. $this->assertContains("'app.test_task_comment'", $result);
  341. $this->assertContains("'app.test_task_tag'", $result);
  342. $this->assertContains("'app.articles_tag'", $result);
  343. }
  344. /**
  345. * test baking component test files,
  346. *
  347. * @return void
  348. */
  349. public function testBakeComponentTest() {
  350. $this->markTestIncomplete('Model tests need reworking.');
  351. Configure::write('App.namespace', 'TestApp');
  352. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  353. $result = $this->Task->bake('Component', 'Apple');
  354. $this->assertContains('use Cake\Controller\ComponentRegistry', $result);
  355. $this->assertContains('use TestApp\Controller\Component\AppleComponent', $result);
  356. $this->assertContains('class AppleComponentTest extends TestCase', $result);
  357. $this->assertContains('function setUp()', $result);
  358. $this->assertContains("\$registry = new ComponentRegistry()", $result);
  359. $this->assertContains("\$this->Apple = new AppleComponent(\$registry)", $result);
  360. $this->assertContains('function testStartup()', $result);
  361. $this->assertContains('$this->markTestIncomplete(\'testStartup not implemented.\')', $result);
  362. $this->assertContains('function tearDown()', $result);
  363. $this->assertContains('unset($this->Apple)', $result);
  364. }
  365. /**
  366. * test baking behavior test files,
  367. *
  368. * @return void
  369. */
  370. public function testBakeBehaviorTest() {
  371. $this->markTestIncomplete('Model tests need reworking.');
  372. $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
  373. $result = $this->Task->bake('Behavior', 'Example');
  374. $this->assertContains("use App\Model\Behavior\ExampleBehavior;", $result);
  375. $this->assertContains('class ExampleBehaviorTest extends TestCase', $result);
  376. $this->assertContains('function setUp()', $result);
  377. $this->assertContains("\$this->Example = new ExampleBehavior()", $result);
  378. $this->assertContains('function tearDown()', $result);
  379. $this->assertContains('unset($this->Example)', $result);
  380. }
  381. /**
  382. * test baking helper test files,
  383. *
  384. * @return void
  385. */
  386. public function testBakeHelperTest() {
  387. $this->Task->expects($this->once())
  388. ->method('createFile')
  389. ->will($this->returnValue(true));
  390. $result = $this->Task->bake('Helper', 'Example');
  391. $this->assertContains("use Cake\View\View;", $result);
  392. $this->assertContains("use App\View\Helper\ExampleHelper;", $result);
  393. $this->assertContains('class ExampleHelperTest extends TestCase', $result);
  394. $this->assertContains('function setUp()', $result);
  395. $this->assertContains("\$View = new View()", $result);
  396. $this->assertContains("\$this->Example = new ExampleHelper(\$View)", $result);
  397. $this->assertContains('function tearDown()', $result);
  398. $this->assertContains('unset($this->Example)', $result);
  399. }
  400. /**
  401. * test Constructor generation ensure that constructClasses is called for controllers
  402. *
  403. * @return void
  404. */
  405. public function testGenerateConstructor() {
  406. $result = $this->Task->generateConstructor('controller', 'PostsController', null);
  407. $expected = array('', '', '');
  408. $this->assertEquals($expected, $result);
  409. $result = $this->Task->generateConstructor('model', 'Post', null);
  410. $expected = array('', "ClassRegistry::init('Post');\n", '');
  411. $this->assertEquals($expected, $result);
  412. $result = $this->Task->generateConstructor('helper', 'FormHelper', null);
  413. $expected = array("\$View = new View();\n", "new FormHelper(\$View);\n", '');
  414. $this->assertEquals($expected, $result);
  415. }
  416. /**
  417. * Test generateUses()
  418. */
  419. public function testGenerateUses() {
  420. $result = $this->Task->generateUses('model', 'Model', 'App\Model\Post');
  421. $expected = array(
  422. 'App\Model\Post',
  423. );
  424. $this->assertEquals($expected, $result);
  425. $result = $this->Task->generateUses('controller', 'Controller', 'App\Controller\PostsController');
  426. $expected = array(
  427. 'App\Controller\PostsController',
  428. );
  429. $this->assertEquals($expected, $result);
  430. $result = $this->Task->generateUses('helper', 'View/Helper', 'App\View\Helper\FormHelper');
  431. $expected = array(
  432. 'Cake\View\View',
  433. 'App\View\Helper\FormHelper',
  434. );
  435. $this->assertEquals($expected, $result);
  436. $result = $this->Task->generateUses('component', 'Controller/Component', 'App\Controller\Component\AuthComponent');
  437. $expected = array(
  438. 'Cake\Controller\ComponentRegistry',
  439. 'App\Controller\Component\AuthComponent',
  440. );
  441. $this->assertEquals($expected, $result);
  442. }
  443. /**
  444. * Test that mock class generation works for the appropriate classes
  445. *
  446. * @return void
  447. */
  448. public function testMockClassGeneration() {
  449. $result = $this->Task->hasMockClass('controller');
  450. $this->assertTrue($result);
  451. }
  452. /**
  453. * test bake() with a -plugin param
  454. *
  455. * @return void
  456. */
  457. public function testBakeWithPlugin() {
  458. $this->markTestIncomplete('Model tests need reworking.');
  459. $this->Task->plugin = 'TestTest';
  460. //fake plugin path
  461. Plugin::load('TestTest', array('path' => APP . 'Plugin/TestTest/'));
  462. $path = APP . 'Plugin/TestTest/Test/TestCase/View/Helper/FormHelperTest.php';
  463. $this->Task->expects($this->once())->method('createFile')
  464. ->with($path, $this->anything());
  465. $this->Task->bake('Helper', 'Form');
  466. Plugin::unload();
  467. }
  468. /**
  469. * test interactive with plugins lists from the plugin
  470. *
  471. * @return void
  472. */
  473. public function testInteractiveWithPlugin() {
  474. $this->markTestIncomplete();
  475. $testApp = TEST_APP . 'Plugin/';
  476. Plugin::load('TestPlugin');
  477. $this->Task->plugin = 'TestPlugin';
  478. $path = $testApp . 'TestPlugin/Test/TestCase/View/Helper/OtherHelperTest.php';
  479. $this->Task->expects($this->any())
  480. ->method('in')
  481. ->will($this->onConsecutiveCalls(
  482. 5, //helper
  483. 1 //OtherHelper
  484. ));
  485. $this->Task->expects($this->once())
  486. ->method('createFile')
  487. ->with($path, $this->anything());
  488. $this->Task->stdout->expects($this->at(21))
  489. ->method('write')
  490. ->with('1. OtherHelperHelper');
  491. $this->Task->execute();
  492. }
  493. public static function caseFileNameProvider() {
  494. return array(
  495. array('Model', 'Post', 'TestCase/Model/PostTest.php'),
  496. array('Helper', 'Form', 'TestCase/View/Helper/FormHelperTest.php'),
  497. array('Controller', 'Posts', 'TestCase/Controller/PostsControllerTest.php'),
  498. array('Behavior', 'Tree', 'TestCase/Model/Behavior/TreeBehaviorTest.php'),
  499. array('Component', 'Auth', 'TestCase/Controller/Component/AuthComponentTest.php'),
  500. array('model', 'Post', 'TestCase/Model/PostTest.php'),
  501. array('helper', 'Form', 'TestCase/View/Helper/FormHelperTest.php'),
  502. array('controller', 'Posts', 'TestCase/Controller/PostsControllerTest.php'),
  503. array('behavior', 'Tree', 'TestCase/Model/Behavior/TreeBehaviorTest.php'),
  504. array('component', 'Auth', 'TestCase/Controller/Component/AuthComponentTest.php'),
  505. );
  506. }
  507. /**
  508. * Test filename generation for each type + plugins
  509. *
  510. * @dataProvider caseFileNameProvider
  511. * @return void
  512. */
  513. public function testTestCaseFileName($type, $class, $expected) {
  514. $this->markTestIncomplete();
  515. $this->Task->path = DS . 'my/path/tests/';
  516. $result = $this->Task->testCaseFileName($type, $class);
  517. $expected = $this->Task->path . $expected;
  518. $this->assertEquals($expected, $result);
  519. }
  520. /**
  521. * Test filename generation for plugins.
  522. *
  523. * @return void
  524. */
  525. public function testTestCaseFileNamePlugin() {
  526. $this->markTestIncomplete();
  527. $this->Task->path = DS . 'my/path/tests/';
  528. Plugin::load('TestTest', array('path' => APP . 'Plugin/TestTest/'));
  529. $this->Task->plugin = 'TestTest';
  530. $result = $this->Task->testCaseFileName('Model', 'Post');
  531. $expected = APP . 'Plugin/TestTest/Test/TestCase/Model/PostTest.php';
  532. $this->assertEquals($expected, $result);
  533. }
  534. /**
  535. * test execute with a type defined
  536. *
  537. * @return void
  538. */
  539. public function testExecuteWithOneArg() {
  540. $this->markTestIncomplete('Tests using models need work');
  541. $this->Task->args[0] = 'Model';
  542. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
  543. $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
  544. $this->Task->expects($this->once())->method('createFile')
  545. ->with(
  546. $this->anything(),
  547. $this->stringContains('class TestTaskTagTest extends TestCase')
  548. );
  549. $this->Task->execute();
  550. }
  551. /**
  552. * test execute with type and class name defined
  553. *
  554. * @return void
  555. */
  556. public function testExecuteWithTwoArgs() {
  557. $this->markTestIncomplete('Tests using models need work');
  558. $this->Task->args = array('Model', 'TestTaskTag');
  559. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
  560. $this->Task->expects($this->once())->method('createFile')
  561. ->with(
  562. $this->anything(),
  563. $this->stringContains('class TestTaskTagTest extends TestCase')
  564. );
  565. $this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
  566. $this->Task->execute();
  567. }
  568. /**
  569. * test execute with type and class name defined and lower case.
  570. *
  571. * @return void
  572. */
  573. public function testExecuteWithTwoArgsLowerCase() {
  574. $this->markTestIncomplete('Tests using models need work');
  575. $this->Task->args = array('model', 'TestTaskTag');
  576. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
  577. $this->Task->expects($this->once())->method('createFile')
  578. ->with(
  579. $this->anything(),
  580. $this->stringContains('class TestTaskTagTest extends TestCase')
  581. );
  582. $this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
  583. $this->Task->execute();
  584. }
  585. /**
  586. * Data provider for mapType() tests.
  587. *
  588. * @return array
  589. */
  590. public static function mapTypeProvider() {
  591. return array(
  592. array('controller', 'Controller'),
  593. array('Controller', 'Controller'),
  594. array('component', 'Controller\Component'),
  595. array('Component', 'Controller\Component'),
  596. array('table', 'Model\Table'),
  597. array('Table', 'Model\Table'),
  598. array('entity', 'Model\Entity'),
  599. array('Entity', 'Model\Entity'),
  600. array('behavior', 'Model\Behavior'),
  601. array('Behavior', 'Model\Behavior'),
  602. array('helper', 'View\Helper'),
  603. array('Helper', 'View\Helper'),
  604. array('Helper', 'View\Helper'),
  605. );
  606. }
  607. /**
  608. * Test that mapType returns the correct package names.
  609. *
  610. * @dataProvider mapTypeProvider
  611. * @return void
  612. */
  613. public function testMapType($original, $expected) {
  614. $this->assertEquals($expected, $this->Task->mapType($original));
  615. }
  616. }