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(' Text, Number, CustomOne '));
  172. $result = $this->Task->doHelpers();
  173. $expected = array('Text', 'Number', '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(' Text, Number, CustomOne, , '));
  184. $result = $this->Task->doHelpers();
  185. $expected = array('Text', 'Number', '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('Js', '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\tJs, 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('Js', '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('Js', '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("\$options = array('conditions' => array('BakeArticle.' . \$this->BakeArticle->primaryKey => \$id));", $result);
  307. $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result);
  308. $this->assertContains('function add()', $result);
  309. $this->assertContains("if (\$this->request->is('post'))", $result);
  310. $this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);
  311. $this->assertContains("\$this->Session->setFlash(__('The bake article has been saved'));", $result);
  312. $this->assertContains('function edit($id = null)', $result);
  313. $this->assertContains("\$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));", $result);
  314. $this->assertContains('function delete($id = null)', $result);
  315. $this->assertContains('if ($this->BakeArticle->delete())', $result);
  316. $this->assertContains("\$this->Session->setFlash(__('Bake article deleted'));", $result);
  317. $result = $this->Task->bakeActions('BakeArticles', 'admin_', true);
  318. $this->assertContains('function admin_index() {', $result);
  319. $this->assertContains('function admin_add()', $result);
  320. $this->assertContains('function admin_view($id = null)', $result);
  321. $this->assertContains('function admin_edit($id = null)', $result);
  322. $this->assertContains('function admin_delete($id = null)', $result);
  323. }
  324. /**
  325. * Test baking with Controller::flash() or no sessions.
  326. *
  327. * @return void
  328. */
  329. public function testBakeActionsWithNoSessions() {
  330. $result = $this->Task->bakeActions('BakeArticles', null, false);
  331. $this->assertContains('function index() {', $result);
  332. $this->assertContains('$this->BakeArticle->recursive = 0;', $result);
  333. $this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result);
  334. $this->assertContains('function view($id = null)', $result);
  335. $this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
  336. $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result);
  337. $this->assertContains('function add()', $result);
  338. $this->assertContains("if (\$this->request->is('post'))", $result);
  339. $this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);
  340. $this->assertContains("\$this->flash(__('The bake article has been saved.'), array('action' => 'index'))", $result);
  341. $this->assertContains('function edit($id = null)', $result);
  342. $this->assertContains("\$this->BakeArticle->BakeTag->find('list')", $result);
  343. $this->assertContains("\$this->set(compact('bakeTags'))", $result);
  344. $this->assertContains('function delete($id = null)', $result);
  345. $this->assertContains("\$this->request->onlyAllow('post', 'delete')", $result);
  346. $this->assertContains('if ($this->BakeArticle->delete())', $result);
  347. $this->assertContains("\$this->flash(__('Bake article deleted'), array('action' => 'index'))", $result);
  348. }
  349. /**
  350. * test baking a test
  351. *
  352. * @return void
  353. */
  354. public function testBakeTest() {
  355. $this->Task->plugin = 'ControllerTest';
  356. $this->Task->connection = 'test';
  357. $this->Task->interactive = false;
  358. $this->Task->Test->expects($this->once())->method('bake')->with('Controller', 'BakeArticles');
  359. $this->Task->bakeTest('BakeArticles');
  360. $this->assertEquals($this->Task->plugin, $this->Task->Test->plugin);
  361. $this->assertEquals($this->Task->connection, $this->Task->Test->connection);
  362. $this->assertEquals($this->Task->interactive, $this->Task->Test->interactive);
  363. }
  364. /**
  365. * test Interactive mode.
  366. *
  367. * @return void
  368. */
  369. public function testInteractive() {
  370. $count = count($this->Task->listAll('test'));
  371. if ($count != count($this->fixtures)) {
  372. $this->markTestSkipped('Additional tables detected.');
  373. }
  374. $this->Task->connection = 'test';
  375. $this->Task->path = '/my/path/';
  376. $this->Task->expects($this->any())->method('in')
  377. ->will($this->onConsecutiveCalls(
  378. '1',
  379. 'y', // build interactive
  380. 'n', // build no scaffolds
  381. 'y', // build normal methods
  382. 'n', // build admin methods
  383. 'n', // helpers?
  384. 'n', // components?
  385. 'y', // sessions ?
  386. 'y' // looks good?
  387. ));
  388. $filename = '/my/path/BakeArticlesController.php';
  389. $this->Task->expects($this->once())->method('createFile')->with(
  390. $filename,
  391. $this->stringContains('class BakeArticlesController')
  392. );
  393. $this->Task->execute();
  394. }
  395. /**
  396. * test Interactive mode.
  397. *
  398. * @return void
  399. */
  400. public function testInteractiveAdminMethodsNotInteractive() {
  401. $count = count($this->Task->listAll('test'));
  402. if ($count != count($this->fixtures)) {
  403. $this->markTestSkipped('Additional tables detected.');
  404. }
  405. $this->Task->connection = 'test';
  406. $this->Task->interactive = true;
  407. $this->Task->path = '/my/path/';
  408. $this->Task->expects($this->any())->method('in')
  409. ->will($this->onConsecutiveCalls(
  410. '1',
  411. 'y', // build interactive
  412. 'n', // build no scaffolds
  413. 'y', // build normal methods
  414. 'y', // build admin methods
  415. 'n', // helpers?
  416. 'n', // components?
  417. 'y', // sessions ?
  418. 'y' // looks good?
  419. ));
  420. $this->Task->Project->expects($this->any())
  421. ->method('getPrefix')
  422. ->will($this->returnValue('admin_'));
  423. $filename = '/my/path/BakeArticlesController.php';
  424. $this->Task->expects($this->once())->method('createFile')->with(
  425. $filename,
  426. $this->stringContains('class BakeArticlesController')
  427. )->will($this->returnValue(true));
  428. $result = $this->Task->execute();
  429. $this->assertRegExp('/admin_index/', $result);
  430. }
  431. /**
  432. * test that execute runs all when the first arg == all
  433. *
  434. * @return void
  435. */
  436. public function testExecuteIntoAll() {
  437. $count = count($this->Task->listAll('test'));
  438. if ($count != count($this->fixtures)) {
  439. $this->markTestSkipped('Additional tables detected.');
  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 execute() with all and --admin
  455. *
  456. * @return void
  457. */
  458. public function testExecuteIntoAllAdmin() {
  459. $count = count($this->Task->listAll('test'));
  460. if ($count != count($this->fixtures)) {
  461. $this->markTestSkipped('Additional tables detected.');
  462. }
  463. $this->Task->connection = 'test';
  464. $this->Task->path = '/my/path/';
  465. $this->Task->args = array('all');
  466. $this->Task->params['admin'] = true;
  467. $this->Task->Project->expects($this->any())
  468. ->method('getPrefix')
  469. ->will($this->returnValue('admin_'));
  470. $this->Task->expects($this->any())
  471. ->method('_checkUnitTest')
  472. ->will($this->returnValue(true));
  473. $this->Task->Test->expects($this->once())->method('bake');
  474. $filename = '/my/path/BakeArticlesController.php';
  475. $this->Task->expects($this->once())->method('createFile')->with(
  476. $filename,
  477. $this->stringContains('function admin_index')
  478. )->will($this->returnValue(true));
  479. $this->Task->execute();
  480. }
  481. /**
  482. * test that `cake bake controller foos` works.
  483. *
  484. * @return void
  485. */
  486. public function testExecuteWithController() {
  487. $this->Task->connection = 'test';
  488. $this->Task->path = '/my/path/';
  489. $this->Task->args = array('BakeArticles');
  490. $filename = '/my/path/BakeArticlesController.php';
  491. $this->Task->expects($this->once())->method('createFile')->with(
  492. $filename,
  493. $this->stringContains('$scaffold')
  494. );
  495. $this->Task->execute();
  496. }
  497. /**
  498. * data provider for testExecuteWithControllerNameVariations
  499. *
  500. * @return void
  501. */
  502. public static function nameVariations() {
  503. return array(
  504. array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
  505. );
  506. }
  507. /**
  508. * test that both plural and singular forms work for controller baking.
  509. *
  510. * @dataProvider nameVariations
  511. * @return void
  512. */
  513. public function testExecuteWithControllerNameVariations($name) {
  514. $this->Task->connection = 'test';
  515. $this->Task->path = '/my/path/';
  516. $this->Task->args = array($name);
  517. $filename = '/my/path/BakeArticlesController.php';
  518. $this->Task->expects($this->once())->method('createFile')->with(
  519. $filename, $this->stringContains('$scaffold')
  520. );
  521. $this->Task->execute();
  522. }
  523. /**
  524. * test that `cake bake controller foo scaffold` works.
  525. *
  526. * @return void
  527. */
  528. public function testExecuteWithPublicParam() {
  529. $this->Task->connection = 'test';
  530. $this->Task->path = '/my/path/';
  531. $this->Task->args = array('BakeArticles');
  532. $this->Task->params = array('public' => true);
  533. $filename = '/my/path/BakeArticlesController.php';
  534. $expected = new PHPUnit_Framework_Constraint_Not($this->stringContains('$scaffold'));
  535. $this->Task->expects($this->once())->method('createFile')->with(
  536. $filename, $expected
  537. );
  538. $this->Task->execute();
  539. }
  540. /**
  541. * test that `cake bake controller foos both` works.
  542. *
  543. * @return void
  544. */
  545. public function testExecuteWithControllerAndBoth() {
  546. $this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
  547. $this->Task->connection = 'test';
  548. $this->Task->path = '/my/path/';
  549. $this->Task->args = array('BakeArticles');
  550. $this->Task->params = array('public' => true, 'admin' => true);
  551. $filename = '/my/path/BakeArticlesController.php';
  552. $this->Task->expects($this->once())->method('createFile')->with(
  553. $filename, $this->stringContains('admin_index')
  554. );
  555. $this->Task->execute();
  556. }
  557. /**
  558. * test that `cake bake controller foos admin` works.
  559. *
  560. * @return void
  561. */
  562. public function testExecuteWithControllerAndAdmin() {
  563. $this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
  564. $this->Task->connection = 'test';
  565. $this->Task->path = '/my/path/';
  566. $this->Task->args = array('BakeArticles');
  567. $this->Task->params = array('admin' => true);
  568. $filename = '/my/path/BakeArticlesController.php';
  569. $this->Task->expects($this->once())->method('createFile')->with(
  570. $filename, $this->stringContains('admin_index')
  571. );
  572. $this->Task->execute();
  573. }
  574. }