TestTaskTest.php 21 KB

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