TestTaskTest.php 21 KB

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