ControllerTaskTest.php 21 KB

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