ViewTaskTest.php 19 KB

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