ControllerTaskTest.php 21 KB

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