ControllerTaskTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <?php
  2. /**
  3. * ControllerTask Test Case
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package Cake.Test.Case.Console.Command.Task
  16. * @since CakePHP(tm) v 1.3
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('ConsoleOutput', 'Console');
  20. App::uses('ConsoleInput', 'Console');
  21. App::uses('ShellDispatcher', 'Console');
  22. App::uses('Shell', 'Console');
  23. App::uses('CakeSchema', 'Model');
  24. App::uses('ClassRegistry', 'Utility');
  25. App::uses('Helper', 'View/Helper');
  26. App::uses('ProjectTask', 'Console/Command/Task');
  27. App::uses('ControllerTask', 'Console/Command/Task');
  28. App::uses('ModelTask', 'Console/Command/Task');
  29. App::uses('TemplateTask', 'Console/Command/Task');
  30. App::uses('TestTask', 'Console/Command/Task');
  31. App::uses('Model', 'Model');
  32. App::uses('BakeArticle', 'Model');
  33. App::uses('BakeComment', 'Model');
  34. App::uses('BakeTags', 'Model');
  35. $imported = class_exists('BakeArticle') || class_exists('BakeComment') || class_exists('BakeTag');
  36. if (!$imported) {
  37. define('ARTICLE_MODEL_CREATED', true);
  38. class BakeArticle extends Model {
  39. public $name = 'BakeArticle';
  40. public $hasMany = array('BakeComment');
  41. public $hasAndBelongsToMany = array('BakeTag');
  42. }
  43. }
  44. /**
  45. * ControllerTaskTest class
  46. *
  47. * @package Cake.Test.Case.Console.Command.Task
  48. */
  49. class ControllerTaskTest extends CakeTestCase {
  50. /**
  51. * fixtures
  52. *
  53. * @var array
  54. */
  55. public $fixtures = array('core.bake_article', 'core.bake_articles_bake_tag', 'core.bake_comment', 'core.bake_tag');
  56. /**
  57. * setUp method
  58. *
  59. * @return void
  60. */
  61. public function setUp() {
  62. parent::setUp();
  63. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  64. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  65. $this->Task = $this->getMock('ControllerTask',
  66. array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
  67. array($out, $out, $in)
  68. );
  69. $this->Task->name = 'Controller';
  70. $this->Task->Template = new TemplateTask($out, $out, $in);
  71. $this->Task->Template->params['theme'] = 'default';
  72. $this->Task->Model = $this->getMock('ModelTask',
  73. array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest'),
  74. array($out, $out, $in)
  75. );
  76. $this->Task->Project = $this->getMock('ProjectTask',
  77. array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix'),
  78. array($out, $out, $in)
  79. );
  80. $this->Task->Test = $this->getMock('TestTask', array(), array($out, $out, $in));
  81. }
  82. /**
  83. * tearDown method
  84. *
  85. * @return void
  86. */
  87. public function tearDown() {
  88. unset($this->Task);
  89. ClassRegistry::flush();
  90. App::build();
  91. parent::tearDown();
  92. }
  93. /**
  94. * test ListAll
  95. *
  96. * @return void
  97. */
  98. public function testListAll() {
  99. $count = count($this->Task->listAll('test'));
  100. if ($count != count($this->fixtures)) {
  101. $this->markTestSkipped('Additional tables detected.');
  102. }
  103. $this->Task->connection = 'test';
  104. $this->Task->interactive = true;
  105. $this->Task->expects($this->at(2))->method('out')->with(' 1. BakeArticles');
  106. $this->Task->expects($this->at(3))->method('out')->with(' 2. BakeArticlesBakeTags');
  107. $this->Task->expects($this->at(4))->method('out')->with(' 3. BakeComments');
  108. $this->Task->expects($this->at(5))->method('out')->with(' 4. BakeTags');
  109. $expected = array('BakeArticles', 'BakeArticlesBakeTags', 'BakeComments', 'BakeTags');
  110. $result = $this->Task->listAll('test');
  111. $this->assertEquals($expected, $result);
  112. $this->Task->interactive = false;
  113. $result = $this->Task->listAll();
  114. $expected = array('bake_articles', 'bake_articles_bake_tags', 'bake_comments', 'bake_tags');
  115. $this->assertEquals($expected, $result);
  116. }
  117. /**
  118. * Test that getName interacts with the user and returns the controller name.
  119. *
  120. * @return void
  121. */
  122. public function testGetNameValidIndex() {
  123. $count = count($this->Task->listAll('test'));
  124. if ($count != count($this->fixtures)) {
  125. $this->markTestSkipped('Additional tables detected.');
  126. }
  127. $this->Task->interactive = true;
  128. $this->Task->expects($this->any())->method('in')->will(
  129. $this->onConsecutiveCalls(3, 1)
  130. );
  131. $result = $this->Task->getName('test');
  132. $expected = 'BakeComments';
  133. $this->assertEquals($expected, $result);
  134. $result = $this->Task->getName('test');
  135. $expected = 'BakeArticles';
  136. $this->assertEquals($expected, $result);
  137. }
  138. /**
  139. * test getting invalid indexes.
  140. *
  141. * @return void
  142. */
  143. public function testGetNameInvalidIndex() {
  144. $this->Task->interactive = true;
  145. $this->Task->expects($this->any())->method('in')
  146. ->will($this->onConsecutiveCalls(50, 'q'));
  147. $this->Task->expects($this->once())->method('err');
  148. $this->Task->expects($this->once())->method('_stop');
  149. $this->Task->getName('test');
  150. }
  151. /**
  152. * test helper interactions
  153. *
  154. * @return void
  155. */
  156. public function testDoHelpersNo() {
  157. $this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
  158. $result = $this->Task->doHelpers();
  159. $this->assertSame(array(), $result);
  160. }
  161. /**
  162. * test getting helper values
  163. *
  164. * @return void
  165. */
  166. public function testDoHelpersTrailingSpace() {
  167. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  168. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne '));
  169. $result = $this->Task->doHelpers();
  170. $expected = array('Javascript', 'Ajax', 'CustomOne');
  171. $this->assertEquals($expected, $result);
  172. }
  173. /**
  174. * test doHelpers with extra commas
  175. *
  176. * @return void
  177. */
  178. public function testDoHelpersTrailingCommas() {
  179. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  180. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne, , '));
  181. $result = $this->Task->doHelpers();
  182. $expected = array('Javascript', 'Ajax', 'CustomOne');
  183. $this->assertEquals($expected, $result);
  184. }
  185. /**
  186. * test component interactions
  187. *
  188. * @return void
  189. */
  190. public function testDoComponentsNo() {
  191. $this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
  192. $result = $this->Task->doComponents();
  193. $this->assertSame(array(), $result);
  194. }
  195. /**
  196. * test components with spaces
  197. *
  198. * @return void
  199. */
  200. public function testDoComponentsTrailingSpaces() {
  201. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  202. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security '));
  203. $result = $this->Task->doComponents();
  204. $expected = array('RequestHandler', 'Security');
  205. $this->assertEquals($expected, $result);
  206. }
  207. /**
  208. * test components with commas
  209. *
  210. * @return void
  211. */
  212. public function testDoComponentsTrailingCommas() {
  213. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  214. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security, , '));
  215. $result = $this->Task->doComponents();
  216. $expected = array('RequestHandler', 'Security');
  217. $this->assertEquals($expected, $result);
  218. }
  219. /**
  220. * test Confirming controller user interaction
  221. *
  222. * @return void
  223. */
  224. public function testConfirmController() {
  225. $controller = 'Posts';
  226. $scaffold = false;
  227. $helpers = array('Ajax', 'Time');
  228. $components = array('Acl', 'Auth');
  229. $this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller");
  230. $this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tAjax, Time");
  231. $this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth");
  232. $this->Task->confirmController($controller, $scaffold, $helpers, $components);
  233. }
  234. /**
  235. * test the bake method
  236. *
  237. * @return void
  238. */
  239. public function testBake() {
  240. $helpers = array('Ajax', 'Time');
  241. $components = array('Acl', 'Auth');
  242. $this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));
  243. $result = $this->Task->bake('Articles', '--actions--', $helpers, $components);
  244. $this->assertContains(' * @property Article $Article', $result);
  245. $this->assertContains(' * @property AclComponent $Acl', $result);
  246. $this->assertContains(' * @property AuthComponent $Auth', $result);
  247. $this->assertContains('class ArticlesController extends AppController', $result);
  248. $this->assertContains("public \$components = array('Acl', 'Auth')", $result);
  249. $this->assertContains("public \$helpers = array('Ajax', 'Time')", $result);
  250. $this->assertContains("--actions--", $result);
  251. $result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
  252. $this->assertContains("class ArticlesController extends AppController", $result);
  253. $this->assertContains("public \$scaffold", $result);
  254. $this->assertNotContains('@property', $result);
  255. $this->assertNotContains('helpers', $result);
  256. $this->assertNotContains('components', $result);
  257. $result = $this->Task->bake('Articles', '--actions--', array(), array());
  258. $this->assertContains('class ArticlesController extends AppController', $result);
  259. $this->assertSame(substr_count($result, '@property'), 1);
  260. $this->assertNotContains('components', $result);
  261. $this->assertNotContains('helpers', $result);
  262. $this->assertContains('--actions--', $result);
  263. }
  264. /**
  265. * test bake() with a -plugin param
  266. *
  267. * @return void
  268. */
  269. public function testBakeWithPlugin() {
  270. $this->Task->plugin = 'ControllerTest';
  271. //fake plugin path
  272. CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));
  273. $path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Controller' . DS . 'ArticlesController.php';
  274. $this->Task->expects($this->at(1))->method('createFile')->with(
  275. $path,
  276. new PHPUnit_Framework_Constraint_IsAnything()
  277. );
  278. $this->Task->expects($this->at(3))->method('createFile')->with(
  279. $path,
  280. $this->stringContains('ArticlesController extends ControllerTestAppController')
  281. )->will($this->returnValue(true));
  282. $this->Task->bake('Articles', '--actions--', array(), array(), array());
  283. $this->Task->plugin = 'ControllerTest';
  284. $path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Controller' . DS . 'ArticlesController.php';
  285. $result = $this->Task->bake('Articles', '--actions--', array(), array(), array());
  286. $this->assertContains("App::uses('ControllerTestAppController', 'ControllerTest.Controller');", $result);
  287. $this->assertEquals('ControllerTest', $this->Task->Template->templateVars['plugin']);
  288. $this->assertEquals('ControllerTest.', $this->Task->Template->templateVars['pluginPath']);
  289. CakePlugin::unload();
  290. }
  291. /**
  292. * test that bakeActions is creating the correct controller Code. (Using sessions)
  293. *
  294. * @return void
  295. */
  296. public function testBakeActionsUsingSessions() {
  297. $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Comment & Tag Model to be undefined.');
  298. $result = $this->Task->bakeActions('BakeArticles', null, true);
  299. $this->assertContains('function index() {', $result);
  300. $this->assertContains('$this->BakeArticle->recursive = 0;', $result);
  301. $this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result);
  302. $this->assertContains('function view($id = null)', $result);
  303. $this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
  304. $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
  305. $this->assertContains('function add()', $result);
  306. $this->assertContains("if (\$this->request->is('post'))", $result);
  307. $this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);
  308. $this->assertContains("\$this->Session->setFlash(__('The bake article has been saved'));", $result);
  309. $this->assertContains('function edit($id = null)', $result);
  310. $this->assertContains("\$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));", $result);
  311. $this->assertContains('function delete($id = null)', $result);
  312. $this->assertContains('if ($this->BakeArticle->delete())', $result);
  313. $this->assertContains("\$this->Session->setFlash(__('Bake article deleted'));", $result);
  314. $result = $this->Task->bakeActions('BakeArticles', 'admin_', true);
  315. $this->assertContains('function admin_index() {', $result);
  316. $this->assertContains('function admin_add()', $result);
  317. $this->assertContains('function admin_view($id = null)', $result);
  318. $this->assertContains('function admin_edit($id = null)', $result);
  319. $this->assertContains('function admin_delete($id = null)', $result);
  320. }
  321. /**
  322. * Test baking with Controller::flash() or no sessions.
  323. *
  324. * @return void
  325. */
  326. public function testBakeActionsWithNoSessions() {
  327. $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Tag, Comment Models to be undefined.');
  328. $result = $this->Task->bakeActions('BakeArticles', null, false);
  329. $this->assertContains('function index() {', $result);
  330. $this->assertContains('$this->BakeArticle->recursive = 0;', $result);
  331. $this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result);
  332. $this->assertContains('function view($id = null)', $result);
  333. $this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
  334. $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
  335. $this->assertContains('function add()', $result);
  336. $this->assertContains("if (\$this->request->is('post'))", $result);
  337. $this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);
  338. $this->assertContains("\$this->flash(__('The bake article has been saved.'), array('action' => 'index'))", $result);
  339. $this->assertContains('function edit($id = null)', $result);
  340. $this->assertContains("\$this->BakeArticle->BakeTag->find('list')", $result);
  341. $this->assertContains("\$this->set(compact('bakeTags'))", $result);
  342. $this->assertContains('function delete($id = null)', $result);
  343. $this->assertContains('if ($this->BakeArticle->delete())', $result);
  344. $this->assertContains("\$this->flash(__('Bake article deleted'), array('action' => 'index'))", $result);
  345. }
  346. /**
  347. * test baking a test
  348. *
  349. * @return void
  350. */
  351. public function testBakeTest() {
  352. $this->Task->plugin = 'ControllerTest';
  353. $this->Task->connection = 'test';
  354. $this->Task->interactive = false;
  355. $this->Task->Test->expects($this->once())->method('bake')->with('Controller', 'BakeArticles');
  356. $this->Task->bakeTest('BakeArticles');
  357. $this->assertEquals($this->Task->plugin, $this->Task->Test->plugin);
  358. $this->assertEquals($this->Task->connection, $this->Task->Test->connection);
  359. $this->assertEquals($this->Task->interactive, $this->Task->Test->interactive);
  360. }
  361. /**
  362. * test Interactive mode.
  363. *
  364. * @return void
  365. */
  366. public function testInteractive() {
  367. $count = count($this->Task->listAll('test'));
  368. if ($count != count($this->fixtures)) {
  369. $this->markTestSkipped('Additional tables detected.');
  370. }
  371. $this->Task->connection = 'test';
  372. $this->Task->path = '/my/path/';
  373. $this->Task->expects($this->any())->method('in')
  374. ->will($this->onConsecutiveCalls(
  375. '1',
  376. 'y', // build interactive
  377. 'n', // build no scaffolds
  378. 'y', // build normal methods
  379. 'n', // build admin methods
  380. 'n', // helpers?
  381. 'n', // components?
  382. 'y', // sessions ?
  383. 'y' // looks good?
  384. ));
  385. $filename = '/my/path/BakeArticlesController.php';
  386. $this->Task->expects($this->once())->method('createFile')->with(
  387. $filename,
  388. $this->stringContains('class BakeArticlesController')
  389. );
  390. $this->Task->execute();
  391. }
  392. /**
  393. * test Interactive mode.
  394. *
  395. * @return void
  396. */
  397. public function testInteractiveAdminMethodsNotInteractive() {
  398. $count = count($this->Task->listAll('test'));
  399. if ($count != count($this->fixtures)) {
  400. $this->markTestSkipped('Additional tables detected.');
  401. }
  402. $this->Task->connection = 'test';
  403. $this->Task->interactive = true;
  404. $this->Task->path = '/my/path/';
  405. $this->Task->expects($this->any())->method('in')
  406. ->will($this->onConsecutiveCalls(
  407. '1',
  408. 'y', // build interactive
  409. 'n', // build no scaffolds
  410. 'y', // build normal methods
  411. 'y', // build admin methods
  412. 'n', // helpers?
  413. 'n', // components?
  414. 'y', // sessions ?
  415. 'y' // looks good?
  416. ));
  417. $this->Task->Project->expects($this->any())
  418. ->method('getPrefix')
  419. ->will($this->returnValue('admin_'));
  420. $filename = '/my/path/BakeArticlesController.php';
  421. $this->Task->expects($this->once())->method('createFile')->with(
  422. $filename,
  423. $this->stringContains('class BakeArticlesController')
  424. )->will($this->returnValue(true));
  425. $result = $this->Task->execute();
  426. $this->assertRegExp('/admin_index/', $result);
  427. }
  428. /**
  429. * test that execute runs all when the first arg == all
  430. *
  431. * @return void
  432. */
  433. public function testExecuteIntoAll() {
  434. $count = count($this->Task->listAll('test'));
  435. if ($count != count($this->fixtures)) {
  436. $this->markTestSkipped('Additional tables detected.');
  437. }
  438. if (!defined('ARTICLE_MODEL_CREATED')) {
  439. $this->markTestSkipped('Execute into all could not be run as an Article, Tag or Comment model was already loaded.');
  440. }
  441. $this->Task->connection = 'test';
  442. $this->Task->path = '/my/path/';
  443. $this->Task->args = array('all');
  444. $this->Task->expects($this->any())->method('_checkUnitTest')->will($this->returnValue(true));
  445. $this->Task->Test->expects($this->once())->method('bake');
  446. $filename = '/my/path/BakeArticlesController.php';
  447. $this->Task->expects($this->once())->method('createFile')->with(
  448. $filename,
  449. $this->stringContains('class BakeArticlesController')
  450. )->will($this->returnValue(true));
  451. $this->Task->execute();
  452. }
  453. /**
  454. * test that `cake bake controller foos` works.
  455. *
  456. * @return void
  457. */
  458. public function testExecuteWithController() {
  459. if (!defined('ARTICLE_MODEL_CREATED')) {
  460. $this->markTestSkipped('Execute with scaffold param requires no Article, Tag or Comment model to be defined');
  461. }
  462. $this->Task->connection = 'test';
  463. $this->Task->path = '/my/path/';
  464. $this->Task->args = array('BakeArticles');
  465. $filename = '/my/path/BakeArticlesController.php';
  466. $this->Task->expects($this->once())->method('createFile')->with(
  467. $filename,
  468. $this->stringContains('$scaffold')
  469. );
  470. $this->Task->execute();
  471. }
  472. /**
  473. * data provider for testExecuteWithControllerNameVariations
  474. *
  475. * @return void
  476. */
  477. public static function nameVariations() {
  478. return array(
  479. array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
  480. );
  481. }
  482. /**
  483. * test that both plural and singular forms work for controller baking.
  484. *
  485. * @dataProvider nameVariations
  486. * @return void
  487. */
  488. public function testExecuteWithControllerNameVariations($name) {
  489. if (!defined('ARTICLE_MODEL_CREATED')) {
  490. $this->markTestSkipped('Execute with scaffold param requires no Article, Tag or Comment model to be defined.');
  491. }
  492. $this->Task->connection = 'test';
  493. $this->Task->path = '/my/path/';
  494. $this->Task->args = array($name);
  495. $filename = '/my/path/BakeArticlesController.php';
  496. $this->Task->expects($this->once())->method('createFile')->with(
  497. $filename, $this->stringContains('$scaffold')
  498. );
  499. $this->Task->execute();
  500. }
  501. /**
  502. * test that `cake bake controller foo scaffold` works.
  503. *
  504. * @return void
  505. */
  506. public function testExecuteWithPublicParam() {
  507. if (!defined('ARTICLE_MODEL_CREATED')) {
  508. $this->markTestSkipped('Execute with public param requires no Article, Tag or Comment model to be defined.');
  509. }
  510. $this->Task->connection = 'test';
  511. $this->Task->path = '/my/path/';
  512. $this->Task->args = array('BakeArticles');
  513. $this->Task->params = array('public' => true);
  514. $filename = '/my/path/BakeArticlesController.php';
  515. $expected = new PHPUnit_Framework_Constraint_Not($this->stringContains('$scaffold'));
  516. $this->Task->expects($this->once())->method('createFile')->with(
  517. $filename, $expected
  518. );
  519. $this->Task->execute();
  520. }
  521. /**
  522. * test that `cake bake controller foos both` works.
  523. *
  524. * @return void
  525. */
  526. public function testExecuteWithControllerAndBoth() {
  527. if (!defined('ARTICLE_MODEL_CREATED')) {
  528. $this->markTestSkipped('Execute with controller and both requires no Article, Tag or Comment model to be defined.');
  529. }
  530. $this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
  531. $this->Task->connection = 'test';
  532. $this->Task->path = '/my/path/';
  533. $this->Task->args = array('BakeArticles');
  534. $this->Task->params = array('public' => true, 'admin' => true);
  535. $filename = '/my/path/BakeArticlesController.php';
  536. $this->Task->expects($this->once())->method('createFile')->with(
  537. $filename, $this->stringContains('admin_index')
  538. );
  539. $this->Task->execute();
  540. }
  541. /**
  542. * test that `cake bake controller foos admin` works.
  543. *
  544. * @return void
  545. */
  546. public function testExecuteWithControllerAndAdmin() {
  547. if (!defined('ARTICLE_MODEL_CREATED')) {
  548. $this->markTestSkipped('Execute with controller and admin requires no Article, Tag or Comment model to be defined.');
  549. }
  550. $this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
  551. $this->Task->connection = 'test';
  552. $this->Task->path = '/my/path/';
  553. $this->Task->args = array('BakeArticles');
  554. $this->Task->params = array('admin' => true);
  555. $filename = '/my/path/BakeArticlesController.php';
  556. $this->Task->expects($this->once())->method('createFile')->with(
  557. $filename, $this->stringContains('admin_index')
  558. );
  559. $this->Task->execute();
  560. }
  561. }