ViewTaskTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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\Controller\Controller;
  17. use Cake\Core\Configure;
  18. use Cake\Core\Plugin;
  19. use Cake\ORM\Table;
  20. use Cake\ORM\TableRegistry;
  21. use Cake\Shell\Task\TemplateTask;
  22. use Cake\Shell\Task\ViewTask;
  23. use Cake\TestSuite\TestCase;
  24. /**
  25. * Test View Task Comment Model
  26. */
  27. class ViewTaskCommentsTable extends Table {
  28. public function initialize(array $config) {
  29. $this->table('comments');
  30. $this->belongsTo('Articles', [
  31. 'foreignKey' => 'article_id'
  32. ]);
  33. }
  34. }
  35. /**
  36. * Test View Task Article Model
  37. */
  38. class ViewTaskArticlesTable extends Table {
  39. public function intialize(array $config) {
  40. $this->table('articles');
  41. }
  42. }
  43. /**
  44. * Test View Task Comments Controller
  45. */
  46. class ViewTaskCommentsController extends Controller {
  47. public $modelClass = 'Cake\Test\TestCase\Shell\Task\ViewTaskCommentsTable';
  48. /**
  49. * Testing public controller action
  50. *
  51. * @return void
  52. */
  53. public function index() {
  54. }
  55. /**
  56. * Testing public controller action
  57. *
  58. * @return void
  59. */
  60. public function add() {
  61. }
  62. }
  63. /**
  64. * ViewTaskTest class
  65. */
  66. class ViewTaskTest extends TestCase {
  67. /**
  68. * Fixtures
  69. *
  70. * @var array
  71. */
  72. public $fixtures = array(
  73. 'core.articles', 'core.posts', 'core.comments',
  74. 'core.articles_tags',
  75. 'core.tags',
  76. 'core.test_plugin_comments',
  77. 'core.category_threads',
  78. );
  79. /**
  80. * setUp method
  81. *
  82. * Ensure that the default template is used
  83. *
  84. * @return void
  85. */
  86. public function setUp() {
  87. parent::setUp();
  88. Configure::write('App.namespace', 'TestApp');
  89. $this->_setupTask(['in', 'err', 'error', 'createFile', '_stop']);
  90. TableRegistry::get('ViewTaskComments', [
  91. 'className' => __NAMESPACE__ . '\ViewTaskCommentsTable',
  92. ]);
  93. }
  94. /**
  95. * Generate the mock objects used in tests.
  96. *
  97. * @return void
  98. */
  99. protected function _setupTask($methods) {
  100. $io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
  101. $this->Task = $this->getMock('Cake\Shell\Task\ViewTask',
  102. $methods,
  103. [$io]
  104. );
  105. $this->Task->Template = new TemplateTask($io);
  106. $this->Task->Model = $this->getMock('Cake\Shell\Task\ModelTask', [], [$io]);
  107. $this->Task->Template->params['template'] = 'default';
  108. $this->Task->Template->templatePaths = ['default' => CAKE . 'Template/Bake/default/'];
  109. }
  110. /**
  111. * tearDown method
  112. *
  113. * @return void
  114. */
  115. public function tearDown() {
  116. parent::tearDown();
  117. TableRegistry::clear();
  118. unset($this->Task);
  119. }
  120. /**
  121. * Test the controller() method.
  122. *
  123. * @return void
  124. */
  125. public function testController() {
  126. $this->Task->controller('Comments');
  127. $this->assertEquals('Comments', $this->Task->controllerName);
  128. $this->assertEquals(
  129. 'TestApp\Controller\CommentsController',
  130. $this->Task->controllerClass
  131. );
  132. }
  133. /**
  134. * Test the controller() method.
  135. *
  136. * @dataProvider nameVariations
  137. * @return void
  138. */
  139. public function testControllerVariations($name) {
  140. $this->Task->controller($name);
  141. $this->assertEquals('ViewTaskComments', $this->Task->controllerName);
  142. }
  143. /**
  144. * Test controller method with plugins.
  145. *
  146. * @return void
  147. */
  148. public function testControllerPlugin() {
  149. $this->Task->params['plugin'] = 'TestPlugin';
  150. $this->Task->controller('Tests');
  151. $this->assertEquals('Tests', $this->Task->controllerName);
  152. $this->assertEquals(
  153. 'TestPlugin\Controller\TestsController',
  154. $this->Task->controllerClass
  155. );
  156. }
  157. /**
  158. * Test controller method with prefixes.
  159. *
  160. * @return void
  161. */
  162. public function testControllerPrefix() {
  163. $this->Task->params['prefix'] = 'Admin';
  164. $this->Task->controller('Posts');
  165. $this->assertEquals('Posts', $this->Task->controllerName);
  166. $this->assertEquals(
  167. 'TestApp\Controller\Admin\PostsController',
  168. $this->Task->controllerClass
  169. );
  170. $this->Task->params['plugin'] = 'TestPlugin';
  171. $this->Task->controller('Comments');
  172. $this->assertEquals('Comments', $this->Task->controllerName);
  173. $this->assertEquals(
  174. 'TestPlugin\Controller\Admin\CommentsController',
  175. $this->Task->controllerClass
  176. );
  177. }
  178. /**
  179. * test controller with a non-conventional controller name
  180. *
  181. * @return void
  182. */
  183. public function testControllerWithOverride() {
  184. $this->Task->controller('Comments', 'Posts');
  185. $this->assertEquals('Posts', $this->Task->controllerName);
  186. $this->assertEquals(
  187. 'TestApp\Controller\PostsController',
  188. $this->Task->controllerClass
  189. );
  190. }
  191. /**
  192. * Test the model() method.
  193. *
  194. * @return void
  195. */
  196. public function testModel() {
  197. $this->Task->model('Articles');
  198. $this->assertEquals('Articles', $this->Task->modelName);
  199. $this->Task->model('NotThere');
  200. $this->assertEquals('NotThere', $this->Task->modelName);
  201. }
  202. /**
  203. * Test model() method with plugins.
  204. *
  205. * @return void
  206. */
  207. public function testModelPlugin() {
  208. $this->Task->params['plugin'] = 'TestPlugin';
  209. $this->Task->model('TestPluginComments');
  210. $this->assertEquals(
  211. 'TestPlugin.TestPluginComments',
  212. $this->Task->modelName
  213. );
  214. }
  215. /**
  216. * Test getPath()
  217. *
  218. * @return void
  219. */
  220. public function testGetPath() {
  221. $this->Task->controllerName = 'Posts';
  222. $result = $this->Task->getPath();
  223. $this->assertPathEquals(APP . 'Template/Posts/', $result);
  224. $this->Task->params['prefix'] = 'admin';
  225. $result = $this->Task->getPath();
  226. $this->assertPathEquals(APP . 'Template/Admin/Posts/', $result);
  227. }
  228. /**
  229. * Test getPath with plugins.
  230. *
  231. * @return void
  232. */
  233. public function testGetPathPlugin() {
  234. $this->Task->controllerName = 'Posts';
  235. $pluginPath = APP . 'Plugin/TestPlugin/';
  236. Plugin::load('TestPlugin', array('path' => $pluginPath));
  237. $this->Task->params['plugin'] = $this->Task->plugin = 'TestPlugin';
  238. $result = $this->Task->getPath();
  239. $this->assertPathEquals($pluginPath . 'src/Template/Posts/', $result);
  240. $this->Task->params['prefix'] = 'admin';
  241. $result = $this->Task->getPath();
  242. $this->assertPathEquals($pluginPath . 'src/Template/Admin/Posts/', $result);
  243. Plugin::unload('TestPlugin');
  244. }
  245. /**
  246. * Test getContent and parsing of Templates.
  247. *
  248. * @return void
  249. */
  250. public function testGetContent() {
  251. $vars = array(
  252. 'modelClass' => 'TestViewModel',
  253. 'schema' => TableRegistry::get('ViewTaskComments')->schema(),
  254. 'primaryKey' => ['id'],
  255. 'displayField' => 'name',
  256. 'singularVar' => 'testViewModel',
  257. 'pluralVar' => 'testViewModels',
  258. 'singularHumanName' => 'Test View Model',
  259. 'pluralHumanName' => 'Test View Models',
  260. 'fields' => ['id', 'name', 'body'],
  261. 'associations' => [],
  262. 'keyFields' => [],
  263. );
  264. $result = $this->Task->getContent('view', $vars);
  265. $this->assertContains('Delete Test View Model', $result);
  266. $this->assertContains('Edit Test View Model', $result);
  267. $this->assertContains('List Test View Models', $result);
  268. $this->assertContains('New Test View Model', $result);
  269. $this->assertContains('$testViewModel->id', $result);
  270. $this->assertContains('$testViewModel->name', $result);
  271. $this->assertContains('$testViewModel->body', $result);
  272. }
  273. /**
  274. * Test getContent with no pk
  275. *
  276. * @return void
  277. */
  278. public function testGetContentWithNoPrimaryKey() {
  279. $vars = array(
  280. 'modelClass' => 'TestViewModel',
  281. 'schema' => TableRegistry::get('ViewTaskComments')->schema(),
  282. 'primaryKey' => [],
  283. 'displayField' => 'name',
  284. 'singularVar' => 'testViewModel',
  285. 'pluralVar' => 'testViewModels',
  286. 'singularHumanName' => 'Test View Model',
  287. 'pluralHumanName' => 'Test View Models',
  288. 'fields' => ['id', 'name', 'body'],
  289. 'associations' => [],
  290. 'keyFields' => [],
  291. );
  292. $this->Task->expects($this->once())
  293. ->method('error')
  294. ->with($this->stringContains('Cannot generate views for models'));
  295. $result = $this->Task->getContent('view', $vars);
  296. $this->assertFalse($result);
  297. }
  298. /**
  299. * test getContent() using a routing prefix action.
  300. *
  301. * @return void
  302. */
  303. public function testGetContentWithRoutingPrefix() {
  304. $vars = array(
  305. 'modelClass' => 'TestViewModel',
  306. 'schema' => TableRegistry::get('ViewTaskComments')->schema(),
  307. 'primaryKey' => ['id'],
  308. 'displayField' => 'name',
  309. 'singularVar' => 'testViewModel',
  310. 'pluralVar' => 'testViewModels',
  311. 'singularHumanName' => 'Test View Model',
  312. 'pluralHumanName' => 'Test View Models',
  313. 'fields' => ['id', 'name', 'body'],
  314. 'keyFields' => [],
  315. 'associations' => []
  316. );
  317. $this->Task->params['prefix'] = 'Admin';
  318. $result = $this->Task->getContent('view', $vars);
  319. $this->assertContains('Delete Test View Model', $result);
  320. $this->assertContains('Edit Test View Model', $result);
  321. $this->assertContains('List Test View Models', $result);
  322. $this->assertContains('New Test View Model', $result);
  323. $this->assertContains('$testViewModel->id', $result);
  324. $this->assertContains('$testViewModel->name', $result);
  325. $this->assertContains('$testViewModel->body', $result);
  326. $result = $this->Task->getContent('add', $vars);
  327. $this->assertContains("input('name')", $result);
  328. $this->assertContains("input('body')", $result);
  329. $this->assertContains('List Test View Models', $result);
  330. }
  331. /**
  332. * test Bake method
  333. *
  334. * @return void
  335. */
  336. public function testBakeView() {
  337. $this->Task->controllerName = 'ViewTaskComments';
  338. $this->Task->modelName = 'ViewTaskComments';
  339. $this->Task->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController';
  340. $this->Task->expects($this->at(0))
  341. ->method('createFile')
  342. ->with(
  343. $this->_normalizePath(APP . 'Template/ViewTaskComments/view.ctp'),
  344. $this->stringContains('View Task Comments')
  345. );
  346. $this->Task->bake('view', true);
  347. }
  348. /**
  349. * test baking an edit file
  350. *
  351. * @return void
  352. */
  353. public function testBakeEdit() {
  354. $this->Task->controllerName = 'ViewTaskComments';
  355. $this->Task->modelName = 'ViewTaskComments';
  356. $this->Task->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController';
  357. $this->Task->expects($this->at(0))->method('createFile')
  358. ->with(
  359. $this->_normalizePath(APP . 'Template/ViewTaskComments/edit.ctp'),
  360. $this->anything()
  361. );
  362. $result = $this->Task->bake('edit', true);
  363. $this->assertNotContains("Form->input('id')", $result);
  364. $this->assertContains("Form->input('article_id', ['options' => \$articles])", $result);
  365. }
  366. /**
  367. * test baking an index
  368. *
  369. * @return void
  370. */
  371. public function testBakeIndex() {
  372. $this->Task->controllerName = 'ViewTaskComments';
  373. $this->Task->modelName = 'ViewTaskComments';
  374. $this->Task->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController';
  375. $this->Task->expects($this->at(0))->method('createFile')
  376. ->with(
  377. $this->_normalizePath(APP . 'Template/ViewTaskComments/index.ctp'),
  378. $this->stringContains("\$viewTaskComment->article->title")
  379. );
  380. $this->Task->bake('index', true);
  381. }
  382. /**
  383. * test Bake with plugins
  384. *
  385. * @return void
  386. */
  387. public function testBakeIndexPlugin() {
  388. $this->Task->controllerName = 'ViewTaskComments';
  389. $this->Task->modelName = 'TestPlugin.TestPluginComments';
  390. $this->Task->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController';
  391. $table = TableRegistry::get('TestPlugin.TestPluginComments');
  392. $table->belongsTo('Articles');
  393. $this->Task->expects($this->at(0))
  394. ->method('createFile')
  395. ->with(
  396. $this->_normalizePath(APP . 'Template/ViewTaskComments/index.ctp'),
  397. $this->stringContains('$viewTaskComment->article->id')
  398. );
  399. $this->Task->bake('index', true);
  400. }
  401. /**
  402. * Ensure that models associated with themselves do not have action
  403. * links generated.
  404. *
  405. * @return void
  406. */
  407. public function testBakeSelfAssociations() {
  408. $this->Task->controllerName = 'CategoryThreads';
  409. $this->Task->modelName = 'TestApp\Model\Table\CategoryThreadsTable';
  410. $this->Task->expects($this->once())
  411. ->method('createFile')
  412. ->with(
  413. $this->_normalizePath(APP . 'Template/CategoryThreads/index.ctp'),
  414. $this->logicalNot($this->stringContains('ParentCategoryThread'))
  415. );
  416. $this->Task->bake('index', true);
  417. }
  418. /**
  419. * test that baking a view with no template doesn't make a file.
  420. *
  421. * @return void
  422. */
  423. public function testBakeWithNoTemplate() {
  424. $this->Task->controllerName = 'ViewTaskComments';
  425. $this->Task->modelName = 'ViewTaskComments';
  426. $this->Task->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController';
  427. $this->Task->expects($this->never())->method('createFile');
  428. $this->Task->bake('delete', true);
  429. }
  430. /**
  431. * test bake actions baking multiple actions.
  432. *
  433. * @return void
  434. */
  435. public function testBakeActions() {
  436. $this->Task->controllerName = 'ViewTaskComments';
  437. $this->Task->modelName = 'ViewTaskComments';
  438. $this->Task->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController';
  439. $this->Task->expects($this->at(0))
  440. ->method('createFile')
  441. ->with(
  442. $this->_normalizePath(APP . 'Template/ViewTaskComments/view.ctp'),
  443. $this->stringContains('View Task Comments')
  444. );
  445. $this->Task->expects($this->at(1))->method('createFile')
  446. ->with(
  447. $this->_normalizePath(APP . 'Template/ViewTaskComments/edit.ctp'),
  448. $this->stringContains('Edit View Task Comment')
  449. );
  450. $this->Task->expects($this->at(2))->method('createFile')
  451. ->with(
  452. $this->_normalizePath(APP . 'Template/ViewTaskComments/index.ctp'),
  453. $this->stringContains('ViewTaskComment')
  454. );
  455. $this->Task->bakeActions(array('view', 'edit', 'index'), array());
  456. }
  457. /**
  458. * test baking a customAction (non crud)
  459. *
  460. * @return void
  461. */
  462. public function testCustomAction() {
  463. $this->Task->controllerName = 'ViewTaskComments';
  464. $this->Task->modelName = 'ViewTaskComments';
  465. $this->Task->controllerClass = __NAMESPACE__ . '\ViewTaskCommentsController';
  466. $this->Task->expects($this->any())->method('in')
  467. ->will($this->onConsecutiveCalls('', 'my_action', 'y'));
  468. $this->Task->expects($this->once())->method('createFile')
  469. ->with(
  470. $this->_normalizePath(APP . 'Template/ViewTaskComments/my_action.ctp'),
  471. $this->anything()
  472. );
  473. $this->Task->customAction();
  474. }
  475. /**
  476. * Test execute no args.
  477. *
  478. * @return void
  479. */
  480. public function testMainNoArgs() {
  481. $this->_setupTask(['in', 'err', 'bake', 'createFile', '_stop']);
  482. $this->Task->Model->expects($this->once())
  483. ->method('listAll')
  484. ->will($this->returnValue(['comments', 'articles']));
  485. $this->Task->expects($this->never())
  486. ->method('bake');
  487. $this->Task->main();
  488. }
  489. /**
  490. * Test all() calls execute
  491. *
  492. * @return void
  493. */
  494. public function testAllCallsMain() {
  495. $this->_setupTask(['in', 'err', 'createFile', 'main', '_stop']);
  496. $this->Task->Model->expects($this->once())
  497. ->method('listAll')
  498. ->will($this->returnValue(['comments', 'articles']));
  499. $this->Task->expects($this->exactly(2))
  500. ->method('main');
  501. $this->Task->expects($this->at(0))
  502. ->method('main')
  503. ->with('comments');
  504. $this->Task->expects($this->at(1))
  505. ->method('main')
  506. ->with('articles');
  507. $this->Task->all();
  508. }
  509. /**
  510. * test `cake bake view $controller view`
  511. *
  512. * @return void
  513. */
  514. public function testMainWithActionParam() {
  515. $this->_setupTask(['in', 'err', 'createFile', 'bake', '_stop']);
  516. $this->Task->expects($this->once())
  517. ->method('bake')
  518. ->with('view', true);
  519. $this->Task->main('ViewTaskComments', 'view');
  520. }
  521. /**
  522. * test `cake bake view $controller`
  523. * Ensure that views are only baked for actions that exist in the controller.
  524. *
  525. * @return void
  526. */
  527. public function testMainWithController() {
  528. $this->_setupTask(['in', 'err', 'createFile', 'bake', '_stop']);
  529. $this->Task->expects($this->exactly(4))
  530. ->method('bake');
  531. $this->Task->expects($this->at(0))
  532. ->method('bake')
  533. ->with('index', $this->anything());
  534. $this->Task->expects($this->at(1))
  535. ->method('bake')
  536. ->with('view', $this->anything());
  537. $this->Task->expects($this->at(2))
  538. ->method('bake')
  539. ->with('add', $this->anything());
  540. $this->Task->expects($this->at(3))
  541. ->method('bake')
  542. ->with('edit', $this->anything());
  543. $this->Task->main('ViewTaskComments');
  544. }
  545. /**
  546. * test that plugin.name works.
  547. *
  548. * @return void
  549. */
  550. public function testMainWithPluginName() {
  551. $this->_setupTask(['in', 'err', 'createFile']);
  552. $this->Task->connection = 'test';
  553. $filename = $this->_normalizePath(TEST_APP . 'Plugin/TestPlugin/src/Template/ViewTaskComments/index.ctp');
  554. Plugin::load('TestPlugin');
  555. $this->Task->expects($this->at(0))
  556. ->method('createFile')
  557. ->with($filename);
  558. $this->Task->main('TestPlugin.ViewTaskComments');
  559. }
  560. /**
  561. * static dataprovider for test cases
  562. *
  563. * @return void
  564. */
  565. public static function nameVariations() {
  566. return [['ViewTaskComments'], ['view_task_comments']];
  567. }
  568. /**
  569. * test `cake bake view $table --controller Blog`
  570. *
  571. * @return void
  572. */
  573. public function testMainWithControllerFlag() {
  574. $this->Task->params['controller'] = 'Blog';
  575. $this->Task->expects($this->exactly(4))
  576. ->method('createFile');
  577. $views = array('index.ctp', 'view.ctp', 'add.ctp', 'edit.ctp');
  578. foreach ($views as $i => $view) {
  579. $this->Task->expects($this->at($i))->method('createFile')
  580. ->with(
  581. $this->_normalizePath(APP . 'Template/Blog/' . $view),
  582. $this->anything()
  583. );
  584. }
  585. $this->Task->main('Posts');
  586. }
  587. /**
  588. * test `cake bake view $controller --prefix Admin`
  589. *
  590. * @return void
  591. */
  592. public function testMainWithControllerAndAdminFlag() {
  593. $this->Task->params['prefix'] = 'Admin';
  594. $this->Task->expects($this->exactly(2))
  595. ->method('createFile');
  596. $views = array('index.ctp', 'add.ctp');
  597. foreach ($views as $i => $view) {
  598. $this->Task->expects($this->at($i))->method('createFile')
  599. ->with(
  600. $this->_normalizePath(APP . 'Template/Admin/Posts/' . $view),
  601. $this->anything()
  602. );
  603. }
  604. $this->Task->main('Posts');
  605. }
  606. /**
  607. * test `cake bake view posts index list`
  608. *
  609. * @return void
  610. */
  611. public function testMainWithAlternateTemplates() {
  612. $this->_setupTask(['in', 'err', 'createFile', 'bake', '_stop']);
  613. $this->Task->connection = 'test';
  614. $this->Task->params = [];
  615. $this->Task->expects($this->once())
  616. ->method('bake')
  617. ->with('list', true);
  618. $this->Task->main('ViewTaskComments', 'index', 'list');
  619. }
  620. /**
  621. * test getting templates, make sure noTemplateActions works and prefixed template is used before generic one.
  622. *
  623. * @return void
  624. */
  625. public function testGetTemplate() {
  626. $result = $this->Task->getTemplate('delete');
  627. $this->assertFalse($result);
  628. $result = $this->Task->getTemplate('add');
  629. $this->assertEquals('form', $result);
  630. $result = $this->Task->getTemplate('edit');
  631. $this->assertEquals('form', $result);
  632. $result = $this->Task->getTemplate('view');
  633. $this->assertEquals('view', $result);
  634. $result = $this->Task->getTemplate('index');
  635. $this->assertEquals('index', $result);
  636. }
  637. /**
  638. * Test getting prefixed views.
  639. *
  640. * @return void
  641. */
  642. public function testGetTemplatePrefixed() {
  643. $this->Task->params['prefix'] = 'Admin';
  644. $result = $this->Task->getTemplate('add');
  645. $this->assertEquals('form', $result);
  646. $this->Task->Template->templatePaths = array(
  647. 'test' => CORE_TESTS . '/test_app/TestApp/Template/Bake/test/'
  648. );
  649. $this->Task->Template->params['template'] = 'test';
  650. $result = $this->Task->getTemplate('edit');
  651. $this->assertEquals('admin_edit', $result);
  652. $result = $this->Task->getTemplate('add');
  653. $this->assertEquals('admin_form', $result);
  654. $result = $this->Task->getTemplate('view');
  655. $this->assertEquals('view', $result);
  656. }
  657. }