ControllerTaskTest.php 21 KB

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