TestTaskTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. CommentsTable'));
  167. $this->io->expects($this->at(2))
  168. ->method('out')
  169. ->with($this->stringContains('2. TestPluginCommentsTable'));
  170. $this->Task->outputClassChoices('Table');
  171. }
  172. /**
  173. * Test that method introspection pulls all relevant non parent class
  174. * methods into the test case.
  175. *
  176. * @return void
  177. */
  178. public function testMethodIntrospection() {
  179. $result = $this->Task->getTestableMethods('TestApp\Model\Table\ArticlesTable');
  180. $expected = array('dosomething', 'dosomethingelse');
  181. $this->assertEquals($expected, array_map('strtolower', $result));
  182. }
  183. /**
  184. * test that the generation of fixtures works correctly.
  185. *
  186. * @return void
  187. */
  188. public function testFixtureArrayGenerationFromModel() {
  189. $subject = new ArticlesTable();
  190. $result = $this->Task->generateFixtureList($subject);
  191. $expected = [
  192. 'app.article',
  193. 'app.author',
  194. 'app.tag',
  195. 'app.articles_tag'
  196. ];
  197. $this->assertEquals($expected, $result);
  198. }
  199. /**
  200. * test that the generation of fixtures works correctly.
  201. *
  202. * @return void
  203. */
  204. public function testFixtureArrayGenerationFromController() {
  205. $subject = new PostsController(new Request(), new Response());
  206. $result = $this->Task->generateFixtureList($subject);
  207. $expected = [
  208. 'app.post',
  209. ];
  210. $this->assertEquals($expected, $result);
  211. }
  212. /**
  213. * creating test subjects should clear the registry so the registry is always fresh
  214. *
  215. * @return void
  216. */
  217. public function testRegistryClearWhenBuildingTestObjects() {
  218. $articles = TableRegistry::get('Articles');
  219. $this->Task->buildTestSubject('Table', 'Posts');
  220. $this->assertFalse(TableRegistry::exists('Articles'));
  221. }
  222. /**
  223. * Dataprovider for class name generation.
  224. *
  225. * @return array
  226. */
  227. public static function realClassProvider() {
  228. return [
  229. ['Entity', 'Article', 'App\Model\Entity\Article'],
  230. ['entity', 'ArticleEntity', 'App\Model\Entity\ArticleEntity'],
  231. ['Table', 'Posts', 'App\Model\Table\PostsTable'],
  232. ['table', 'PostsTable', 'App\Model\Table\PostsTable'],
  233. ['Controller', 'Posts', 'App\Controller\PostsController'],
  234. ['controller', 'PostsController', 'App\Controller\PostsController'],
  235. ['Behavior', 'Timestamp', 'App\Model\Behavior\TimestampBehavior'],
  236. ['behavior', 'TimestampBehavior', 'App\Model\Behavior\TimestampBehavior'],
  237. ['Helper', 'Form', 'App\View\Helper\FormHelper'],
  238. ['helper', 'FormHelper', 'App\View\Helper\FormHelper'],
  239. ['Component', 'Auth', 'App\Controller\Component\AuthComponent'],
  240. ['component', 'AuthComponent', 'App\Controller\Component\AuthComponent'],
  241. ['Shell', 'Example', 'App\Console\Command\ExampleShell'],
  242. ['shell', 'Example', 'App\Console\Command\ExampleShell'],
  243. ['Cell', 'Example', 'App\View\Cell\ExampleCell'],
  244. ['cell', 'Example', 'App\View\Cell\ExampleCell'],
  245. ];
  246. }
  247. /**
  248. * test that resolving class names works
  249. *
  250. * @dataProvider realClassProvider
  251. * @return void
  252. */
  253. public function testGetRealClassname($type, $name, $expected) {
  254. $result = $this->Task->getRealClassname($type, $name);
  255. $this->assertEquals($expected, $result);
  256. }
  257. /**
  258. * test resolving class names with plugins
  259. *
  260. * @return void
  261. */
  262. public function testGetRealClassnamePlugin() {
  263. Plugin::load('TestPlugin');
  264. $this->Task->plugin = 'TestPlugin';
  265. $result = $this->Task->getRealClassname('Helper', 'Asset');
  266. $expected = 'TestPlugin\View\Helper\AssetHelper';
  267. $this->assertEquals($expected, $result);
  268. }
  269. /**
  270. * Test baking a test for a concrete model with fixtures arg
  271. *
  272. * @return void
  273. */
  274. public function testBakeFixturesParam() {
  275. $this->Task->expects($this->once())
  276. ->method('createFile')
  277. ->will($this->returnValue(true));
  278. $this->Task->params['fixtures'] = 'app.post, app.comments , app.user ,';
  279. $result = $this->Task->bake('Table', 'Articles');
  280. $this->assertContains('public $fixtures = [', $result);
  281. $this->assertContains('app.post', $result);
  282. $this->assertContains('app.comments', $result);
  283. $this->assertContains('app.user', $result);
  284. $this->assertNotContains("''", $result);
  285. }
  286. /**
  287. * Test baking a test for a cell.
  288. *
  289. * @return void
  290. */
  291. public function testBakeCellTest() {
  292. $this->Task->expects($this->once())
  293. ->method('createFile')
  294. ->will($this->returnValue(true));
  295. $result = $this->Task->bake('Cell', 'Articles');
  296. $this->assertContains("use App\View\Cell\ArticlesCell", $result);
  297. $this->assertContains('class ArticlesCellTest extends TestCase', $result);
  298. $this->assertContains('function setUp()', $result);
  299. $this->assertContains("\$this->request = \$this->getMock('Cake\Network\Request')", $result);
  300. $this->assertContains("\$this->response = \$this->getMock('Cake\Network\Response')", $result);
  301. $this->assertContains("\$this->Articles = new ArticlesCell(\$this->request, \$this->response", $result);
  302. }
  303. /**
  304. * Test baking a test for a concrete model.
  305. *
  306. * @return void
  307. */
  308. public function testBakeModelTest() {
  309. $this->Task->expects($this->once())
  310. ->method('createFile')
  311. ->will($this->returnValue(true));
  312. $result = $this->Task->bake('Table', 'Articles');
  313. $this->assertContains("use App\Model\Table\ArticlesTable", $result);
  314. $this->assertContains('class ArticlesTableTest extends TestCase', $result);
  315. $this->assertContains('function setUp()', $result);
  316. $this->assertContains("\$config = TableRegistry::exists('Articles') ?", $result);
  317. $this->assertContains("\$this->Articles = TableRegistry::get('Articles', \$config", $result);
  318. $this->assertContains('function tearDown()', $result);
  319. $this->assertContains('unset($this->Articles)', $result);
  320. }
  321. /**
  322. * test baking controller test files
  323. *
  324. * @return void
  325. */
  326. public function testBakeControllerTest() {
  327. Configure::write('App.namespace', 'TestApp');
  328. $this->Task->expects($this->once())
  329. ->method('createFile')
  330. ->will($this->returnValue(true));
  331. $result = $this->Task->bake('Controller', 'PostsController');
  332. $this->assertContains("use TestApp\Controller\PostsController", $result);
  333. $this->assertContains('class PostsControllerTest extends ControllerTestCase', $result);
  334. $this->assertNotContains('function setUp()', $result);
  335. $this->assertNotContains("\$this->Posts = new PostsController()", $result);
  336. $this->assertNotContains("\$this->Posts->constructClasses()", $result);
  337. $this->assertNotContains('function tearDown()', $result);
  338. $this->assertNotContains('unset($this->Posts)', $result);
  339. $this->assertContains("'app.post'", $result);
  340. }
  341. /**
  342. * test baking controller test files
  343. *
  344. * @return void
  345. */
  346. public function testBakePrefixControllerTest() {
  347. Configure::write('App.namespace', 'TestApp');
  348. $this->Task->expects($this->once())
  349. ->method('createFile')
  350. ->with($this->stringContains('Controller' . DS . 'Admin' . DS . 'PostsControllerTest.php'))
  351. ->will($this->returnValue(true));
  352. $result = $this->Task->bake('controller', 'Admin\Posts');
  353. $this->assertContains("use TestApp\Controller\Admin\PostsController", $result);
  354. $this->assertContains('class PostsControllerTest extends ControllerTestCase', $result);
  355. $this->assertNotContains('function setUp()', $result);
  356. $this->assertNotContains("\$this->Posts = new PostsController()", $result);
  357. $this->assertNotContains("\$this->Posts->constructClasses()", $result);
  358. $this->assertNotContains('function tearDown()', $result);
  359. $this->assertNotContains('unset($this->Posts)', $result);
  360. }
  361. /**
  362. * test baking component test files,
  363. *
  364. * @return void
  365. */
  366. public function testBakeComponentTest() {
  367. Configure::write('App.namespace', 'TestApp');
  368. $this->Task->expects($this->once())
  369. ->method('createFile')
  370. ->will($this->returnValue(true));
  371. $result = $this->Task->bake('Component', 'Apple');
  372. $this->assertContains('use Cake\Controller\ComponentRegistry', $result);
  373. $this->assertContains('use TestApp\Controller\Component\AppleComponent', $result);
  374. $this->assertContains('class AppleComponentTest extends TestCase', $result);
  375. $this->assertContains('function setUp()', $result);
  376. $this->assertContains("\$registry = new ComponentRegistry()", $result);
  377. $this->assertContains("\$this->Apple = new AppleComponent(\$registry)", $result);
  378. $this->assertContains('function testStartup()', $result);
  379. $this->assertContains('$this->markTestIncomplete(\'testStartup not implemented.\')', $result);
  380. $this->assertContains('function tearDown()', $result);
  381. $this->assertContains('unset($this->Apple)', $result);
  382. }
  383. /**
  384. * test baking behavior test files,
  385. *
  386. * @return void
  387. */
  388. public function testBakeBehaviorTest() {
  389. $this->Task->expects($this->once())
  390. ->method('createFile')
  391. ->will($this->returnValue(true));
  392. $result = $this->Task->bake('Behavior', 'Example');
  393. $this->assertContains("use App\Model\Behavior\ExampleBehavior;", $result);
  394. $this->assertContains('class ExampleBehaviorTest extends TestCase', $result);
  395. $this->assertContains('function setUp()', $result);
  396. $this->assertContains("\$this->Example = new ExampleBehavior()", $result);
  397. $this->assertContains('function tearDown()', $result);
  398. $this->assertContains('unset($this->Example)', $result);
  399. }
  400. /**
  401. * test baking helper test files,
  402. *
  403. * @return void
  404. */
  405. public function testBakeHelperTest() {
  406. $this->Task->expects($this->once())
  407. ->method('createFile')
  408. ->will($this->returnValue(true));
  409. $result = $this->Task->bake('Helper', 'Example');
  410. $this->assertContains("use Cake\View\View;", $result);
  411. $this->assertContains("use App\View\Helper\ExampleHelper;", $result);
  412. $this->assertContains('class ExampleHelperTest extends TestCase', $result);
  413. $this->assertContains('function setUp()', $result);
  414. $this->assertContains("\$view = new View()", $result);
  415. $this->assertContains("\$this->Example = new ExampleHelper(\$view)", $result);
  416. $this->assertContains('function tearDown()', $result);
  417. $this->assertContains('unset($this->Example)', $result);
  418. }
  419. /**
  420. * Test baking a test for a concrete model.
  421. *
  422. * @return void
  423. */
  424. public function testBakeShellTest() {
  425. $this->Task->expects($this->once())
  426. ->method('createFile')
  427. ->will($this->returnValue(true));
  428. $result = $this->Task->bake('Shell', 'Articles');
  429. $this->assertContains("use App\Console\Command\ArticlesShell", $result);
  430. $this->assertContains('class ArticlesShellTest extends TestCase', $result);
  431. $this->assertContains('function setUp()', $result);
  432. $this->assertContains("\$this->io = \$this->getMock('Cake\Console\ConsoleIo');", $result);
  433. $this->assertContains("\$this->Articles = new ArticlesShell(\$this->io);", $result);
  434. $this->assertContains('function tearDown()', $result);
  435. $this->assertContains('unset($this->Articles)', $result);
  436. }
  437. /**
  438. * test Constructor generation ensure that constructClasses is called for controllers
  439. *
  440. * @return void
  441. */
  442. public function testGenerateConstructor() {
  443. $result = $this->Task->generateConstructor('controller', 'PostsController');
  444. $expected = ['', '', ''];
  445. $this->assertEquals($expected, $result);
  446. $result = $this->Task->generateConstructor('table', 'App\Model\\Table\PostsTable');
  447. $expected = [
  448. "\$config = TableRegistry::exists('Posts') ? [] : ['className' => 'App\Model\\Table\PostsTable'];\n",
  449. "TableRegistry::get('Posts', \$config);\n",
  450. ''
  451. ];
  452. $this->assertEquals($expected, $result);
  453. $result = $this->Task->generateConstructor('helper', 'FormHelper');
  454. $expected = ["\$view = new View();\n", "new FormHelper(\$view);\n", ''];
  455. $this->assertEquals($expected, $result);
  456. $result = $this->Task->generateConstructor('entity', 'TestPlugin\Model\Entity\Article');
  457. $expected = ["", "new Article();\n", ''];
  458. $this->assertEquals($expected, $result);
  459. }
  460. /**
  461. * Test generateUses()
  462. *
  463. * @return void
  464. */
  465. public function testGenerateUses() {
  466. $result = $this->Task->generateUses('table', 'App\Model\Table\PostsTable');
  467. $expected = array(
  468. 'Cake\ORM\TableRegistry',
  469. 'App\Model\Table\PostsTable',
  470. );
  471. $this->assertEquals($expected, $result);
  472. $result = $this->Task->generateUses('controller', 'App\Controller\PostsController');
  473. $expected = array(
  474. 'App\Controller\PostsController',
  475. );
  476. $this->assertEquals($expected, $result);
  477. $result = $this->Task->generateUses('helper', 'App\View\Helper\FormHelper');
  478. $expected = array(
  479. 'Cake\View\View',
  480. 'App\View\Helper\FormHelper',
  481. );
  482. $this->assertEquals($expected, $result);
  483. $result = $this->Task->generateUses('component', 'App\Controller\Component\AuthComponent');
  484. $expected = array(
  485. 'Cake\Controller\ComponentRegistry',
  486. 'App\Controller\Component\AuthComponent',
  487. );
  488. $this->assertEquals($expected, $result);
  489. }
  490. /**
  491. * Test that mock class generation works for the appropriate classes
  492. *
  493. * @return void
  494. */
  495. public function testMockClassGeneration() {
  496. $result = $this->Task->hasMockClass('controller');
  497. $this->assertTrue($result);
  498. }
  499. /**
  500. * test bake() with a -plugin param
  501. *
  502. * @return void
  503. */
  504. public function testBakeWithPlugin() {
  505. $this->Task->plugin = 'TestPlugin';
  506. Plugin::load('TestPlugin');
  507. $path = TEST_APP . 'Plugin/TestPlugin/tests/TestCase/View/Helper/FormHelperTest.php';
  508. $path = str_replace('/', DS, $path);
  509. $this->Task->expects($this->once())->method('createFile')
  510. ->with($path, $this->anything());
  511. $this->Task->bake('Helper', 'Form');
  512. }
  513. /**
  514. * Provider for test case file names.
  515. *
  516. * @return array
  517. */
  518. public static function caseFileNameProvider() {
  519. return array(
  520. array('Table', 'App\Model\Table\PostsTable', 'TestCase/Model/Table/PostsTableTest.php'),
  521. array('Entity', 'App\Model\Entity\Article', 'TestCase/Model/Entity/ArticleTest.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('Controller', 'App\Controller\Admin\PostsController', 'TestCase/Controller/Admin/PostsControllerTest.php'),
  525. array('Behavior', 'App\Model\Behavior\TreeBehavior', 'TestCase/Model/Behavior/TreeBehaviorTest.php'),
  526. array('Component', 'App\Controller\Component\AuthComponent', 'TestCase/Controller/Component/AuthComponentTest.php'),
  527. array('entity', 'App\Model\Entity\Article', 'TestCase/Model/Entity/ArticleTest.php'),
  528. array('table', 'App\Model\Table\PostsTable', 'TestCase/Model/Table/PostsTableTest.php'),
  529. array('helper', 'App\View\Helper\FormHelper', 'TestCase/View/Helper/FormHelperTest.php'),
  530. array('controller', 'App\Controller\PostsController', 'TestCase/Controller/PostsControllerTest.php'),
  531. array('behavior', 'App\Model\Behavior\TreeBehavior', 'TestCase/Model/Behavior/TreeBehaviorTest.php'),
  532. array('component', 'App\Controller\Component\AuthComponent', 'TestCase/Controller/Component/AuthComponentTest.php'),
  533. ['Shell', 'App\Console\Command\ExampleShell', 'TestCase/Console/Command/ExampleShellTest.php'],
  534. ['shell', 'App\Console\Command\ExampleShell', 'TestCase/Console/Command/ExampleShellTest.php'],
  535. );
  536. }
  537. /**
  538. * Test filename generation for each type + plugins
  539. *
  540. * @dataProvider caseFileNameProvider
  541. * @return void
  542. */
  543. public function testTestCaseFileName($type, $class, $expected) {
  544. $result = $this->Task->testCaseFileName($type, $class);
  545. $expected = ROOT . DS . 'Test/' . $expected;
  546. $this->assertPathEquals($expected, $result);
  547. }
  548. /**
  549. * Test filename generation for plugins.
  550. *
  551. * @return void
  552. */
  553. public function testTestCaseFileNamePlugin() {
  554. $this->Task->path = DS . 'my/path/tests/';
  555. Plugin::load('TestPlugin');
  556. $this->Task->plugin = 'TestPlugin';
  557. $class = 'TestPlugin\Model\Entity\Post';
  558. $result = $this->Task->testCaseFileName('entity', $class);
  559. $expected = TEST_APP . 'Plugin/TestPlugin/tests/TestCase/Model/Entity/PostTest.php';
  560. $this->assertPathEquals($expected, $result);
  561. }
  562. /**
  563. * Data provider for mapType() tests.
  564. *
  565. * @return array
  566. */
  567. public static function mapTypeProvider() {
  568. return array(
  569. array('controller', 'Controller'),
  570. array('Controller', 'Controller'),
  571. array('component', 'Controller\Component'),
  572. array('Component', 'Controller\Component'),
  573. array('table', 'Model\Table'),
  574. array('Table', 'Model\Table'),
  575. array('entity', 'Model\Entity'),
  576. array('Entity', 'Model\Entity'),
  577. array('behavior', 'Model\Behavior'),
  578. array('Behavior', 'Model\Behavior'),
  579. array('helper', 'View\Helper'),
  580. array('Helper', 'View\Helper'),
  581. array('Helper', 'View\Helper'),
  582. );
  583. }
  584. /**
  585. * Test that mapType returns the correct package names.
  586. *
  587. * @dataProvider mapTypeProvider
  588. * @return void
  589. */
  590. public function testMapType($original, $expected) {
  591. $this->assertEquals($expected, $this->Task->mapType($original));
  592. }
  593. }