ControllerTaskTest.php 21 KB

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