ControllerTaskTest.php 21 KB

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