ControllerTaskTest.php 21 KB

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