TestTaskTest.php 21 KB

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