TestTaskTest.php 21 KB

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