ControllerTaskTest.php 21 KB

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