TestTaskTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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\Network\Request;
  23. use Cake\Network\Response;
  24. use Cake\ORM\Table;
  25. use Cake\ORM\TableRegistry;
  26. use Cake\TestSuite\TestCase;
  27. use TestApp\Controller\PostsController;
  28. use TestApp\Model\Table\ArticlesTable;
  29. /**
  30. * TestTaskTest class
  31. *
  32. */
  33. class TestTaskTest extends TestCase {
  34. /**
  35. * Fixtures
  36. *
  37. * @var string
  38. */
  39. public $fixtures = ['core.article', 'core.author',
  40. 'core.comment', 'core.articles_tag', 'core.tag'];
  41. /**
  42. * setUp method
  43. *
  44. * @return void
  45. */
  46. public function setUp() {
  47. parent::setUp();
  48. $this->io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
  49. $this->Task = $this->getMock('Cake\Console\Command\Task\TestTask',
  50. array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
  51. array($this->io)
  52. );
  53. $this->Task->name = 'Test';
  54. $this->Task->Template = new TemplateTask($this->io);
  55. $this->Task->Template->interactive = false;
  56. }
  57. /**
  58. * tearDown method
  59. *
  60. * @return void
  61. */
  62. public function tearDown() {
  63. parent::tearDown();
  64. unset($this->Task);
  65. Plugin::unload();
  66. }
  67. /**
  68. * Test that with no args execute() outputs the types you can generate
  69. * tests for.
  70. *
  71. * @return void
  72. */
  73. public function testExecuteNoArgsPrintsTypeOptions() {
  74. $this->Task = $this->getMockBuilder('Cake\Console\Command\Task\TestTask')
  75. ->disableOriginalConstructor()
  76. ->setMethods(['outputTypeChoices'])
  77. ->getMock();
  78. $this->Task->expects($this->once())
  79. ->method('outputTypeChoices');
  80. $this->Task->main();
  81. }
  82. /**
  83. * Test outputTypeChoices method
  84. *
  85. * @return void
  86. */
  87. public function testOutputTypeChoices() {
  88. $this->io->expects($this->at(0))
  89. ->method('out')
  90. ->with($this->stringContains('You must provide'));
  91. $this->io->expects($this->at(1))
  92. ->method('out')
  93. ->with($this->stringContains('1. Entity'));
  94. $this->io->expects($this->at(2))
  95. ->method('out')
  96. ->with($this->stringContains('2. Table'));
  97. $this->io->expects($this->at(3))
  98. ->method('out')
  99. ->with($this->stringContains('3. Controller'));
  100. $this->Task->outputTypeChoices();
  101. }
  102. /**
  103. * Test that with no args execute() outputs the types you can generate
  104. * tests for.
  105. *
  106. * @return void
  107. */
  108. public function testExecuteOneArgPrintsClassOptions() {
  109. $this->Task = $this->getMockBuilder('Cake\Console\Command\Task\TestTask')
  110. ->disableOriginalConstructor()
  111. ->setMethods(['outputClassChoices'])
  112. ->getMock();
  113. $this->Task->expects($this->once())
  114. ->method('outputClassChoices');
  115. $this->Task->main('Entity');
  116. }
  117. /**
  118. * test execute with type and class name defined
  119. *
  120. * @return void
  121. */
  122. public function testExecuteWithTwoArgs() {
  123. $this->Task->expects($this->once())->method('createFile')
  124. ->with(
  125. $this->stringContains('TestCase' . DS . 'Model' . DS . 'Table' . DS . 'TestTaskTagTableTest.php'),
  126. $this->stringContains('class TestTaskTagTableTest extends TestCase')
  127. );
  128. $this->Task->main('Table', 'TestTaskTag');
  129. }
  130. /**
  131. * Test generating class options for table.
  132. *
  133. * @return void
  134. */
  135. public function testOutputClassOptionsForTable() {
  136. $this->io->expects($this->at(0))
  137. ->method('out')
  138. ->with($this->stringContains('You must provide'));
  139. $this->io->expects($this->at(1))
  140. ->method('out')
  141. ->with($this->stringContains('1. ArticlesTable'));
  142. $this->io->expects($this->at(2))
  143. ->method('out')
  144. ->with($this->stringContains('2. ArticlesTagsTable'));
  145. $this->io->expects($this->at(3))
  146. ->method('out')
  147. ->with($this->stringContains('3. AuthUsersTable'));
  148. $this->io->expects($this->at(4))
  149. ->method('out')
  150. ->with($this->stringContains('4. AuthorsTable'));
  151. $this->Task->outputClassChoices('Table');
  152. }
  153. /**
  154. * Test generating class options for table.
  155. *
  156. * @return void
  157. */
  158. public function testOutputClassOptionsForTablePlugin() {
  159. Plugin::load('TestPlugin');
  160. $this->Task->plugin = 'TestPlugin';
  161. $this->io->expects($this->at(0))
  162. ->method('out')
  163. ->with($this->stringContains('You must provide'));
  164. $this->io->expects($this->at(1))
  165. ->method('out')
  166. ->with($this->stringContains('1. AuthorsTable'));
  167. $this->io->expects($this->at(2))
  168. ->method('out')
  169. ->with($this->stringContains('2. CommentsTable'));
  170. $this->io->expects($this->at(3))
  171. ->method('out')
  172. ->with($this->stringContains('3. TestPluginCommentsTable'));
  173. $this->Task->outputClassChoices('Table');
  174. }
  175. /**
  176. * Test that method introspection pulls all relevant non parent class
  177. * methods into the test case.
  178. *
  179. * @return void
  180. */
  181. public function testMethodIntrospection() {
  182. $result = $this->Task->getTestableMethods('TestApp\Model\Table\ArticlesTable');
  183. $expected = array('dosomething', 'dosomethingelse');
  184. $this->assertEquals($expected, array_map('strtolower', $result));
  185. }
  186. /**
  187. * test that the generation of fixtures works correctly.
  188. *
  189. * @return void
  190. */
  191. public function testFixtureArrayGenerationFromModel() {
  192. $subject = new ArticlesTable();
  193. $result = $this->Task->generateFixtureList($subject);
  194. $expected = [
  195. 'app.article',
  196. 'app.author',
  197. 'app.tag',
  198. 'app.articles_tag'
  199. ];
  200. $this->assertEquals($expected, $result);
  201. }
  202. /**
  203. * test that the generation of fixtures works correctly.
  204. *
  205. * @return void
  206. */
  207. public function testFixtureArrayGenerationFromController() {
  208. $subject = new PostsController(new Request(), new Response());
  209. $result = $this->Task->generateFixtureList($subject);
  210. $expected = [
  211. 'app.post',
  212. ];
  213. $this->assertEquals($expected, $result);
  214. }
  215. /**
  216. * Dataprovider for class name generation.
  217. *
  218. * @return array
  219. */
  220. public static function realClassProvider() {
  221. return [
  222. ['Entity', 'Article', 'App\Model\Entity\Article'],
  223. ['entity', 'ArticleEntity', 'App\Model\Entity\ArticleEntity'],
  224. ['Table', 'Posts', 'App\Model\Table\PostsTable'],
  225. ['table', 'PostsTable', 'App\Model\Table\PostsTable'],
  226. ['Controller', 'Posts', 'App\Controller\PostsController'],
  227. ['controller', 'PostsController', 'App\Controller\PostsController'],
  228. ['Behavior', 'Timestamp', 'App\Model\Behavior\TimestampBehavior'],
  229. ['behavior', 'TimestampBehavior', 'App\Model\Behavior\TimestampBehavior'],
  230. ['Helper', 'Form', 'App\View\Helper\FormHelper'],
  231. ['helper', 'FormHelper', 'App\View\Helper\FormHelper'],
  232. ['Component', 'Auth', 'App\Controller\Component\AuthComponent'],
  233. ['component', 'AuthComponent', 'App\Controller\Component\AuthComponent'],
  234. ['Shell', 'Example', 'App\Console\Command\ExampleShell'],
  235. ['shell', 'Example', 'App\Console\Command\ExampleShell'],
  236. ['Cell', 'Example', 'App\View\Cell\ExampleCell'],
  237. ['cell', 'Example', 'App\View\Cell\ExampleCell'],
  238. ];
  239. }
  240. /**
  241. * test that resolving class names works
  242. *
  243. * @dataProvider realClassProvider
  244. * @return void
  245. */
  246. public function testGetRealClassname($type, $name, $expected) {
  247. $result = $this->Task->getRealClassname($type, $name);
  248. $this->assertEquals($expected, $result);
  249. }
  250. /**
  251. * test resolving class names with plugins
  252. *
  253. * @return void
  254. */
  255. public function testGetRealClassnamePlugin() {
  256. Plugin::load('TestPlugin');
  257. $this->Task->plugin = 'TestPlugin';
  258. $result = $this->Task->getRealClassname('Helper', 'Asset');
  259. $expected = 'TestPlugin\View\Helper\AssetHelper';
  260. $this->assertEquals($expected, $result);
  261. }
  262. /**
  263. * Test baking a test for a concrete model with fixtures arg
  264. *
  265. * @return void
  266. */
  267. public function testBakeFixturesParam() {
  268. $this->Task->expects($this->once())
  269. ->method('createFile')
  270. ->will($this->returnValue(true));
  271. $this->Task->params['fixtures'] = 'app.post, app.comments , app.user ,';
  272. $result = $this->Task->bake('Table', 'Articles');
  273. $this->assertContains('public $fixtures = [', $result);
  274. $this->assertContains('app.post', $result);
  275. $this->assertContains('app.comments', $result);
  276. $this->assertContains('app.user', $result);
  277. $this->assertNotContains("''", $result);
  278. }
  279. /**
  280. * Test baking a test for a cell.
  281. *
  282. * @return void
  283. */
  284. public function testBakeCellTest() {
  285. $this->Task->expects($this->once())
  286. ->method('createFile')
  287. ->will($this->returnValue(true));
  288. $result = $this->Task->bake('Cell', 'Articles');
  289. $this->assertContains("use App\View\Cell\ArticlesCell", $result);
  290. $this->assertContains('class ArticlesCellTest extends TestCase', $result);
  291. $this->assertContains('function setUp()', $result);
  292. $this->assertContains("\$this->request = \$this->getMock('Cake\Network\Request')", $result);
  293. $this->assertContains("\$this->response = \$this->getMock('Cake\Network\Response')", $result);
  294. $this->assertContains("\$this->Articles = new ArticlesCell(\$this->request, \$this->response", $result);
  295. }
  296. /**
  297. * Test baking a test for a concrete model.
  298. *
  299. * @return void
  300. */
  301. public function testBakeModelTest() {
  302. $this->Task->expects($this->once())
  303. ->method('createFile')
  304. ->will($this->returnValue(true));
  305. $result = $this->Task->bake('Table', 'Articles');
  306. $this->assertContains("use App\Model\Table\ArticlesTable", $result);
  307. $this->assertContains('class ArticlesTableTest extends TestCase', $result);
  308. $this->assertContains('function setUp()', $result);
  309. $this->assertContains("\$config = TableRegistry::exists('Articles') ?", $result);
  310. $this->assertContains("\$this->Articles = TableRegistry::get('Articles', \$config", $result);
  311. $this->assertContains('function tearDown()', $result);
  312. $this->assertContains('unset($this->Articles)', $result);
  313. }
  314. /**
  315. * test baking controller test files
  316. *
  317. * @return void
  318. */
  319. public function testBakeControllerTest() {
  320. Configure::write('App.namespace', 'TestApp');
  321. $this->Task->expects($this->once())
  322. ->method('createFile')
  323. ->will($this->returnValue(true));
  324. $result = $this->Task->bake('Controller', 'PostsController');
  325. $this->assertContains("use TestApp\Controller\PostsController", $result);
  326. $this->assertContains('class PostsControllerTest extends ControllerTestCase', $result);
  327. $this->assertNotContains('function setUp()', $result);
  328. $this->assertNotContains("\$this->Posts = new PostsController()", $result);
  329. $this->assertNotContains("\$this->Posts->constructClasses()", $result);
  330. $this->assertNotContains('function tearDown()', $result);
  331. $this->assertNotContains('unset($this->Posts)', $result);
  332. $this->assertContains("'app.post'", $result);
  333. }
  334. /**
  335. * test baking controller test files
  336. *
  337. * @return void
  338. */
  339. public function testBakePrefixControllerTest() {
  340. Configure::write('App.namespace', 'TestApp');
  341. $this->Task->expects($this->once())
  342. ->method('createFile')
  343. ->with($this->stringContains('Controller' . DS . 'Admin' . DS . 'PostsControllerTest.php'))
  344. ->will($this->returnValue(true));
  345. $result = $this->Task->bake('controller', 'Admin\Posts');
  346. $this->assertContains("use TestApp\Controller\Admin\PostsController", $result);
  347. $this->assertContains('class PostsControllerTest extends ControllerTestCase', $result);
  348. $this->assertNotContains('function setUp()', $result);
  349. $this->assertNotContains("\$this->Posts = new PostsController()", $result);
  350. $this->assertNotContains("\$this->Posts->constructClasses()", $result);
  351. $this->assertNotContains('function tearDown()', $result);
  352. $this->assertNotContains('unset($this->Posts)', $result);
  353. }
  354. /**
  355. * test baking component test files,
  356. *
  357. * @return void
  358. */
  359. public function testBakeComponentTest() {
  360. Configure::write('App.namespace', 'TestApp');
  361. $this->Task->expects($this->once())
  362. ->method('createFile')
  363. ->will($this->returnValue(true));
  364. $result = $this->Task->bake('Component', 'Apple');
  365. $this->assertContains('use Cake\Controller\ComponentRegistry', $result);
  366. $this->assertContains('use TestApp\Controller\Component\AppleComponent', $result);
  367. $this->assertContains('class AppleComponentTest extends TestCase', $result);
  368. $this->assertContains('function setUp()', $result);
  369. $this->assertContains("\$registry = new ComponentRegistry()", $result);
  370. $this->assertContains("\$this->Apple = new AppleComponent(\$registry)", $result);
  371. $this->assertContains('function testStartup()', $result);
  372. $this->assertContains('$this->markTestIncomplete(\'testStartup not implemented.\')', $result);
  373. $this->assertContains('function tearDown()', $result);
  374. $this->assertContains('unset($this->Apple)', $result);
  375. }
  376. /**
  377. * test baking behavior test files,
  378. *
  379. * @return void
  380. */
  381. public function testBakeBehaviorTest() {
  382. $this->Task->expects($this->once())
  383. ->method('createFile')
  384. ->will($this->returnValue(true));
  385. $result = $this->Task->bake('Behavior', 'Example');
  386. $this->assertContains("use App\Model\Behavior\ExampleBehavior;", $result);
  387. $this->assertContains('class ExampleBehaviorTest extends TestCase', $result);
  388. $this->assertContains('function setUp()', $result);
  389. $this->assertContains("\$this->Example = new ExampleBehavior()", $result);
  390. $this->assertContains('function tearDown()', $result);
  391. $this->assertContains('unset($this->Example)', $result);
  392. }
  393. /**
  394. * test baking helper test files,
  395. *
  396. * @return void
  397. */
  398. public function testBakeHelperTest() {
  399. $this->Task->expects($this->once())
  400. ->method('createFile')
  401. ->will($this->returnValue(true));
  402. $result = $this->Task->bake('Helper', 'Example');
  403. $this->assertContains("use Cake\View\View;", $result);
  404. $this->assertContains("use App\View\Helper\ExampleHelper;", $result);
  405. $this->assertContains('class ExampleHelperTest extends TestCase', $result);
  406. $this->assertContains('function setUp()', $result);
  407. $this->assertContains("\$view = new View()", $result);
  408. $this->assertContains("\$this->Example = new ExampleHelper(\$view)", $result);
  409. $this->assertContains('function tearDown()', $result);
  410. $this->assertContains('unset($this->Example)', $result);
  411. }
  412. /**
  413. * Test baking a test for a concrete model.
  414. *
  415. * @return void
  416. */
  417. public function testBakeShellTest() {
  418. $this->Task->expects($this->once())
  419. ->method('createFile')
  420. ->will($this->returnValue(true));
  421. $result = $this->Task->bake('Shell', 'Articles');
  422. $this->assertContains("use App\Console\Command\ArticlesShell", $result);
  423. $this->assertContains('class ArticlesShellTest extends TestCase', $result);
  424. $this->assertContains('function setUp()', $result);
  425. $this->assertContains("\$this->io = \$this->getMock('Cake\Console\ConsoleIo');", $result);
  426. $this->assertContains("\$this->Articles = new ArticlesShell(\$this->io);", $result);
  427. $this->assertContains('function tearDown()', $result);
  428. $this->assertContains('unset($this->Articles)', $result);
  429. }
  430. /**
  431. * test Constructor generation ensure that constructClasses is called for controllers
  432. *
  433. * @return void
  434. */
  435. public function testGenerateConstructor() {
  436. $result = $this->Task->generateConstructor('controller', 'PostsController');
  437. $expected = ['', '', ''];
  438. $this->assertEquals($expected, $result);
  439. $result = $this->Task->generateConstructor('table', 'App\Model\\Table\PostsTable');
  440. $expected = [
  441. "\$config = TableRegistry::exists('Posts') ? [] : ['className' => 'App\Model\\Table\PostsTable'];\n",
  442. "TableRegistry::get('Posts', \$config);\n",
  443. ''
  444. ];
  445. $this->assertEquals($expected, $result);
  446. $result = $this->Task->generateConstructor('helper', 'FormHelper');
  447. $expected = ["\$view = new View();\n", "new FormHelper(\$view);\n", ''];
  448. $this->assertEquals($expected, $result);
  449. $result = $this->Task->generateConstructor('entity', 'TestPlugin\Model\Entity\Article');
  450. $expected = ["", "new Article();\n", ''];
  451. $this->assertEquals($expected, $result);
  452. }
  453. /**
  454. * Test generateUses()
  455. *
  456. * @return void
  457. */
  458. public function testGenerateUses() {
  459. $result = $this->Task->generateUses('table', 'App\Model\Table\PostsTable');
  460. $expected = array(
  461. 'Cake\ORM\TableRegistry',
  462. 'App\Model\Table\PostsTable',
  463. );
  464. $this->assertEquals($expected, $result);
  465. $result = $this->Task->generateUses('controller', 'App\Controller\PostsController');
  466. $expected = array(
  467. 'App\Controller\PostsController',
  468. );
  469. $this->assertEquals($expected, $result);
  470. $result = $this->Task->generateUses('helper', 'App\View\Helper\FormHelper');
  471. $expected = array(
  472. 'Cake\View\View',
  473. 'App\View\Helper\FormHelper',
  474. );
  475. $this->assertEquals($expected, $result);
  476. $result = $this->Task->generateUses('component', 'App\Controller\Component\AuthComponent');
  477. $expected = array(
  478. 'Cake\Controller\ComponentRegistry',
  479. 'App\Controller\Component\AuthComponent',
  480. );
  481. $this->assertEquals($expected, $result);
  482. }
  483. /**
  484. * Test that mock class generation works for the appropriate classes
  485. *
  486. * @return void
  487. */
  488. public function testMockClassGeneration() {
  489. $result = $this->Task->hasMockClass('controller');
  490. $this->assertTrue($result);
  491. }
  492. /**
  493. * test bake() with a -plugin param
  494. *
  495. * @return void
  496. */
  497. public function testBakeWithPlugin() {
  498. $this->Task->plugin = 'TestPlugin';
  499. Plugin::load('TestPlugin');
  500. $path = TEST_APP . 'Plugin/TestPlugin/tests/TestCase/View/Helper/FormHelperTest.php';
  501. $path = str_replace('/', DS, $path);
  502. $this->Task->expects($this->once())->method('createFile')
  503. ->with($path, $this->anything());
  504. $this->Task->bake('Helper', 'Form');
  505. }
  506. /**
  507. * Provider for test case file names.
  508. *
  509. * @return array
  510. */
  511. public static function caseFileNameProvider() {
  512. return array(
  513. array('Table', 'App\Model\Table\PostsTable', 'TestCase/Model/Table/PostsTableTest.php'),
  514. array('Entity', 'App\Model\Entity\Article', 'TestCase/Model/Entity/ArticleTest.php'),
  515. array('Helper', 'App\View\Helper\FormHelper', 'TestCase/View/Helper/FormHelperTest.php'),
  516. array('Controller', 'App\Controller\PostsController', 'TestCase/Controller/PostsControllerTest.php'),
  517. array('Controller', 'App\Controller\Admin\PostsController', 'TestCase/Controller/Admin/PostsControllerTest.php'),
  518. array('Behavior', 'App\Model\Behavior\TreeBehavior', 'TestCase/Model/Behavior/TreeBehaviorTest.php'),
  519. array('Component', 'App\Controller\Component\AuthComponent', 'TestCase/Controller/Component/AuthComponentTest.php'),
  520. array('entity', 'App\Model\Entity\Article', 'TestCase/Model/Entity/ArticleTest.php'),
  521. array('table', 'App\Model\Table\PostsTable', 'TestCase/Model/Table/PostsTableTest.php'),
  522. array('helper', 'App\View\Helper\FormHelper', 'TestCase/View/Helper/FormHelperTest.php'),
  523. array('controller', 'App\Controller\PostsController', 'TestCase/Controller/PostsControllerTest.php'),
  524. array('behavior', 'App\Model\Behavior\TreeBehavior', 'TestCase/Model/Behavior/TreeBehaviorTest.php'),
  525. array('component', 'App\Controller\Component\AuthComponent', 'TestCase/Controller/Component/AuthComponentTest.php'),
  526. ['Shell', 'App\Console\Command\ExampleShell', 'TestCase/Console/Command/ExampleShellTest.php'],
  527. ['shell', 'App\Console\Command\ExampleShell', 'TestCase/Console/Command/ExampleShellTest.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. $result = $this->Task->testCaseFileName($type, $class);
  538. $expected = ROOT . DS . 'tests/' . $expected;
  539. $this->assertPathEquals($expected, $result);
  540. }
  541. /**
  542. * Test filename generation for plugins.
  543. *
  544. * @return void
  545. */
  546. public function testTestCaseFileNamePlugin() {
  547. $this->Task->path = DS . 'my/path/tests/';
  548. Plugin::load('TestPlugin');
  549. $this->Task->plugin = 'TestPlugin';
  550. $class = 'TestPlugin\Model\Entity\Post';
  551. $result = $this->Task->testCaseFileName('entity', $class);
  552. $expected = TEST_APP . 'Plugin/TestPlugin/tests/TestCase/Model/Entity/PostTest.php';
  553. $this->assertPathEquals($expected, $result);
  554. }
  555. /**
  556. * Data provider for mapType() tests.
  557. *
  558. * @return array
  559. */
  560. public static function mapTypeProvider() {
  561. return array(
  562. array('controller', 'Controller'),
  563. array('Controller', 'Controller'),
  564. array('component', 'Controller\Component'),
  565. array('Component', 'Controller\Component'),
  566. array('table', 'Model\Table'),
  567. array('Table', 'Model\Table'),
  568. array('entity', 'Model\Entity'),
  569. array('Entity', 'Model\Entity'),
  570. array('behavior', 'Model\Behavior'),
  571. array('Behavior', 'Model\Behavior'),
  572. array('helper', 'View\Helper'),
  573. array('Helper', 'View\Helper'),
  574. array('Helper', 'View\Helper'),
  575. );
  576. }
  577. /**
  578. * Test that mapType returns the correct package names.
  579. *
  580. * @dataProvider mapTypeProvider
  581. * @return void
  582. */
  583. public function testMapType($original, $expected) {
  584. $this->assertEquals($expected, $this->Task->mapType($original));
  585. }
  586. }