ModelTaskTest.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP Project
  12. * @since CakePHP v 1.2.6
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Console\Command\Task;
  16. use Cake\Console\Command\Task\ModelTask;
  17. use Cake\Console\Command\Task\TemplateTask;
  18. use Cake\Core\Plugin;
  19. use Cake\Model\Model;
  20. use Cake\ORM\TableRegistry;
  21. use Cake\TestSuite\TestCase;
  22. use Cake\Utility\ClassRegistry;
  23. use Cake\Utility\Inflector;
  24. /**
  25. * ModelTaskTest class
  26. *
  27. */
  28. class ModelTaskTest extends TestCase {
  29. /**
  30. * fixtures
  31. *
  32. * @var array
  33. */
  34. public $fixtures = array(
  35. 'core.bake_article', 'core.bake_comment', 'core.bake_articles_bake_tag',
  36. 'core.bake_tag', 'core.category_thread', 'core.number_tree'
  37. );
  38. /**
  39. * setUp method
  40. *
  41. * @return void
  42. */
  43. public function setUp() {
  44. parent::setUp();
  45. $out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
  46. $in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);
  47. $this->Task = $this->getMock('Cake\Console\Command\Task\ModelTask',
  48. array('in', 'err', 'createFile', '_stop', '_checkUnitTest'),
  49. array($out, $out, $in)
  50. );
  51. $this->Task->connection = 'test';
  52. $this->_setupOtherMocks();
  53. }
  54. /**
  55. * Setup a mock that has out mocked. Normally this is not used as it makes $this->at() really tricky.
  56. *
  57. * @return void
  58. */
  59. protected function _useMockedOut() {
  60. $out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
  61. $in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);
  62. $this->Task = $this->getMock('Cake\Console\Command\Task\ModelTask',
  63. array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
  64. array($out, $out, $in)
  65. );
  66. $this->_setupOtherMocks();
  67. }
  68. /**
  69. * sets up the rest of the dependencies for Model Task
  70. *
  71. * @return void
  72. */
  73. protected function _setupOtherMocks() {
  74. $out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
  75. $in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);
  76. $this->Task->Fixture = $this->getMock('Cake\Console\Command\Task\FixtureTask', [], [$out, $out, $in]);
  77. $this->Task->Test = $this->getMock('Cake\Console\Command\Task\FixtureTask', [], [$out, $out, $in]);
  78. $this->Task->Template = new TemplateTask($out, $out, $in);
  79. $this->Task->name = 'Model';
  80. }
  81. /**
  82. * tearDown method
  83. *
  84. * @return void
  85. */
  86. public function tearDown() {
  87. parent::tearDown();
  88. unset($this->Task);
  89. }
  90. /**
  91. * Test that listAll uses the connection property
  92. *
  93. * @return void
  94. */
  95. public function testListAllConnection() {
  96. $this->_useMockedOut();
  97. $this->Task->connection = 'test';
  98. $result = $this->Task->listAll();
  99. $this->assertContains('bake_articles', $result);
  100. $this->assertContains('bake_articles_bake_tags', $result);
  101. $this->assertContains('bake_tags', $result);
  102. $this->assertContains('bake_comments', $result);
  103. $this->assertContains('category_threads', $result);
  104. }
  105. /**
  106. * Test getName() method.
  107. *
  108. * @return void
  109. */
  110. public function testGetTable() {
  111. $this->Task->args[0] = 'BakeArticle';
  112. $result = $this->Task->getTable();
  113. $this->assertEquals('bake_articles', $result);
  114. $this->Task->args[0] = 'BakeArticles';
  115. $result = $this->Task->getTable();
  116. $this->assertEquals('bake_articles', $result);
  117. $this->Task->args[0] = 'Article';
  118. $this->Task->params['table'] = 'bake_articles';
  119. $result = $this->Task->getTable();
  120. $this->assertEquals('bake_articles', $result);
  121. }
  122. /**
  123. * Test getting the a table class.
  124. *
  125. * @return void
  126. */
  127. public function testGetTableObject() {
  128. $result = $this->Task->getTableObject('Article', 'bake_articles');
  129. $this->assertInstanceOf('Cake\ORM\Table', $result);
  130. $this->assertEquals('bake_articles', $result->table());
  131. $this->assertEquals('Article', $result->alias());
  132. }
  133. /**
  134. * Test getAssociations with off flag.
  135. *
  136. * @return void
  137. */
  138. public function testGetAssociationsNoFlag() {
  139. $this->Task->params['no-associations'] = true;
  140. $articles = TableRegistry::get('BakeArticle');
  141. $this->assertEquals([], $this->Task->getAssociations($articles));
  142. }
  143. /**
  144. * Test getAssociations
  145. *
  146. * @return void
  147. */
  148. public function testGetAssociations() {
  149. $articles = TableRegistry::get('BakeArticles');
  150. $result = $this->Task->getAssociations($articles);
  151. $expected = [
  152. 'belongsTo' => [
  153. [
  154. 'alias' => 'BakeUsers',
  155. 'className' => 'BakeUsers',
  156. 'foreignKey' => 'bake_user_id',
  157. ],
  158. ],
  159. 'hasMany' => [
  160. [
  161. 'alias' => 'BakeComments',
  162. 'className' => 'BakeComments',
  163. 'foreignKey' => 'bake_article_id',
  164. ],
  165. ],
  166. 'belongsToMany' => [
  167. [
  168. 'alias' => 'BakeTags',
  169. 'className' => 'BakeTags',
  170. 'foreignKey' => 'bake_article_id',
  171. 'joinTable' => 'bake_articles_bake_tags',
  172. 'targetForeignKey' => 'bake_tag_id',
  173. ],
  174. ],
  175. ];
  176. $this->assertEquals($expected, $result);
  177. }
  178. /**
  179. * test that belongsTo generation works.
  180. *
  181. * @return void
  182. */
  183. public function testBelongsToGeneration() {
  184. $model = TableRegistry::get('BakeComments');
  185. $result = $this->Task->findBelongsTo($model, []);
  186. $expected = [
  187. 'belongsTo' => [
  188. [
  189. 'alias' => 'BakeArticles',
  190. 'className' => 'BakeArticles',
  191. 'foreignKey' => 'bake_article_id',
  192. ],
  193. [
  194. 'alias' => 'BakeUsers',
  195. 'className' => 'BakeUsers',
  196. 'foreignKey' => 'bake_user_id',
  197. ],
  198. ]
  199. ];
  200. $this->assertEquals($expected, $result);
  201. $model = TableRegistry::get('CategoryThreads');
  202. $result = $this->Task->findBelongsTo($model, array());
  203. $expected = [
  204. 'belongsTo' => [
  205. [
  206. 'alias' => 'ParentCategoryThreads',
  207. 'className' => 'CategoryThreads',
  208. 'foreignKey' => 'parent_id',
  209. ],
  210. ]
  211. ];
  212. $this->assertEquals($expected, $result);
  213. }
  214. /**
  215. * test that hasOne and/or hasMany relations are generated properly.
  216. *
  217. * @return void
  218. */
  219. public function testHasManyGeneration() {
  220. $this->Task->connection = 'test';
  221. $model = TableRegistry::get('BakeArticles');
  222. $result = $this->Task->findHasMany($model, []);
  223. $expected = [
  224. 'hasMany' => [
  225. [
  226. 'alias' => 'BakeComments',
  227. 'className' => 'BakeComments',
  228. 'foreignKey' => 'bake_article_id',
  229. ],
  230. ],
  231. ];
  232. $this->assertEquals($expected, $result);
  233. $model = TableRegistry::get('CategoryThreads');
  234. $result = $this->Task->findHasMany($model, []);
  235. $expected = [
  236. 'hasMany' => [
  237. [
  238. 'alias' => 'ChildCategoryThreads',
  239. 'className' => 'CategoryThreads',
  240. 'foreignKey' => 'parent_id',
  241. ],
  242. ]
  243. ];
  244. $this->assertEquals($expected, $result);
  245. }
  246. /**
  247. * Test that HABTM generation works
  248. *
  249. * @return void
  250. */
  251. public function testHasAndBelongsToManyGeneration() {
  252. $this->Task->connection = 'test';
  253. $model = TableRegistry::get('BakeArticles');
  254. $result = $this->Task->findBelongsToMany($model, []);
  255. $expected = [
  256. 'belongsToMany' => [
  257. [
  258. 'alias' => 'BakeTags',
  259. 'className' => 'BakeTags',
  260. 'foreignKey' => 'bake_article_id',
  261. 'joinTable' => 'bake_articles_bake_tags',
  262. 'targetForeignKey' => 'bake_tag_id',
  263. ],
  264. ],
  265. ];
  266. $this->assertEquals($expected, $result);
  267. }
  268. /**
  269. * Test getting accessible fields.
  270. *
  271. * @return void
  272. */
  273. public function testFields() {
  274. $model = TableRegistry::get('BakeArticles');
  275. $result = $this->Task->getFields($model);
  276. $expected = [
  277. 'id',
  278. 'bake_user_id',
  279. 'title',
  280. 'body',
  281. 'published',
  282. ];
  283. $this->assertEquals($expected, $result);
  284. }
  285. /**
  286. * Test getting field with the no- option
  287. *
  288. * @return void
  289. */
  290. public function testFieldsDisabled() {
  291. $model = TableRegistry::get('BakeArticles');
  292. $this->Task->params['no-fields'] = true;
  293. $result = $this->Task->getFields($model);
  294. $this->assertEquals([], $result);
  295. }
  296. /**
  297. * Test getting field with a whitelist
  298. *
  299. * @return void
  300. */
  301. public function testFieldsWhiteList() {
  302. $model = TableRegistry::get('BakeArticles');
  303. $this->Task->params['fields'] = 'id, title , , body , created';
  304. $result = $this->Task->getFields($model);
  305. $expected = [
  306. 'id',
  307. 'title',
  308. 'body',
  309. 'created',
  310. ];
  311. $this->assertEquals($expected, $result);
  312. }
  313. /**
  314. * test that initializing the validations works.
  315. *
  316. * @return void
  317. */
  318. public function testInitValidations() {
  319. $result = $this->Task->initValidations();
  320. $this->assertTrue(in_array('notEmpty', $result));
  321. }
  322. /**
  323. * test that individual field validation works, with interactive = false
  324. * tests the guessing features of validation
  325. *
  326. * @return void
  327. */
  328. public function testFieldValidationGuessing() {
  329. $this->markTestIncomplete('Not done here yet');
  330. $this->Task->interactive = false;
  331. $this->Task->initValidations();
  332. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  333. $expected = array('notEmpty' => 'notEmpty');
  334. $this->assertEquals($expected, $result);
  335. $result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false));
  336. $expected = array('date' => 'date');
  337. $this->assertEquals($expected, $result);
  338. $result = $this->Task->fieldValidation('text', array('type' => 'time', 'length' => 10, 'null' => false));
  339. $expected = array('time' => 'time');
  340. $this->assertEquals($expected, $result);
  341. $result = $this->Task->fieldValidation('email', array('type' => 'string', 'length' => 10, 'null' => false));
  342. $expected = array('email' => 'email');
  343. $this->assertEquals($expected, $result);
  344. $result = $this->Task->fieldValidation('test', array('type' => 'integer', 'length' => 10, 'null' => false));
  345. $expected = array('numeric' => 'numeric');
  346. $this->assertEquals($expected, $result);
  347. $result = $this->Task->fieldValidation('test', array('type' => 'boolean', 'length' => 10, 'null' => false));
  348. $expected = array('boolean' => 'boolean');
  349. $this->assertEquals($expected, $result);
  350. }
  351. /**
  352. * test that interactive field validation works and returns multiple validators.
  353. *
  354. * @return void
  355. */
  356. public function testInteractiveFieldValidation() {
  357. $this->markTestIncomplete('Not done here yet');
  358. $this->Task->initValidations();
  359. $this->Task->interactive = true;
  360. $this->Task->expects($this->any())->method('in')
  361. ->will($this->onConsecutiveCalls('24', 'y', '18', 'n'));
  362. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  363. $expected = array('notEmpty' => 'notEmpty', 'maxLength' => 'maxLength');
  364. $this->assertEquals($expected, $result);
  365. }
  366. /**
  367. * test that a bogus response doesn't cause errors to bubble up.
  368. *
  369. * @return void
  370. */
  371. public function testInteractiveFieldValidationWithBogusResponse() {
  372. $this->markTestIncomplete('Not done here yet');
  373. $this->_useMockedOut();
  374. $this->Task->initValidations();
  375. $this->Task->interactive = true;
  376. $this->Task->expects($this->any())->method('in')
  377. ->will($this->onConsecutiveCalls('999999', '24', 'n'));
  378. $this->Task->expects($this->at(10))->method('out')
  379. ->with($this->stringContains('make a valid'));
  380. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  381. $expected = array('notEmpty' => 'notEmpty');
  382. $this->assertEquals($expected, $result);
  383. }
  384. /**
  385. * test that a regular expression can be used for validation.
  386. *
  387. * @return void
  388. */
  389. public function testInteractiveFieldValidationWithRegexp() {
  390. $this->markTestIncomplete('Not done here yet');
  391. $this->Task->initValidations();
  392. $this->Task->interactive = true;
  393. $this->Task->expects($this->any())->method('in')
  394. ->will($this->onConsecutiveCalls('/^[a-z]{0,9}$/', 'n'));
  395. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  396. $expected = array('a_z_0_9' => '/^[a-z]{0,9}$/');
  397. $this->assertEquals($expected, $result);
  398. }
  399. /**
  400. * Test that skipping fields during rule choice works when doing interactive field validation.
  401. *
  402. * @return void
  403. */
  404. public function testSkippingChoiceInteractiveFieldValidation() {
  405. $this->markTestIncomplete('Not done here yet');
  406. $this->Task->initValidations();
  407. $this->Task->interactive = true;
  408. $this->Task->expects($this->any())->method('in')
  409. ->will($this->onConsecutiveCalls('24', 'y', 's'));
  410. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  411. $expected = array('notEmpty' => 'notEmpty', '_skipFields' => true);
  412. $this->assertEquals($expected, $result);
  413. }
  414. /**
  415. * Test that skipping fields after rule choice works when doing interactive field validation.
  416. *
  417. * @return void
  418. */
  419. public function testSkippingAnotherInteractiveFieldValidation() {
  420. $this->markTestIncomplete('Not done here yet');
  421. $this->Task->initValidations();
  422. $this->Task->interactive = true;
  423. $this->Task->expects($this->any())->method('in')
  424. ->will($this->onConsecutiveCalls('24', 's'));
  425. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  426. $expected = array('notEmpty' => 'notEmpty', '_skipFields' => true);
  427. $this->assertEquals($expected, $result);
  428. }
  429. /**
  430. * Test the validation generation routine with skipping the rest of the fields
  431. * when doing interactive field validation.
  432. *
  433. * @return void
  434. */
  435. public function testInteractiveDoValidationWithSkipping() {
  436. $this->markTestIncomplete('Not done here yet');
  437. $this->Task->expects($this->any())
  438. ->method('in')
  439. ->will($this->onConsecutiveCalls('35', '24', 'n', '11', 's'));
  440. $this->Task->interactive = true;
  441. $Model = $this->getMock('Model');
  442. $Model->primaryKey = 'id';
  443. $Model->expects($this->any())
  444. ->method('schema')
  445. ->will($this->returnValue(array(
  446. 'id' => array(
  447. 'type' => 'integer',
  448. 'length' => 11,
  449. 'null' => false,
  450. 'key' => 'primary',
  451. ),
  452. 'name' => array(
  453. 'type' => 'string',
  454. 'length' => 20,
  455. 'null' => false,
  456. ),
  457. 'email' => array(
  458. 'type' => 'string',
  459. 'length' => 255,
  460. 'null' => false,
  461. ),
  462. 'some_date' => array(
  463. 'type' => 'date',
  464. 'length' => '',
  465. 'null' => false,
  466. ),
  467. 'some_time' => array(
  468. 'type' => 'time',
  469. 'length' => '',
  470. 'null' => false,
  471. ),
  472. 'created' => array(
  473. 'type' => 'datetime',
  474. 'length' => '',
  475. 'null' => false,
  476. )
  477. )
  478. ));
  479. $result = $this->Task->doValidation($Model);
  480. $expected = array(
  481. 'name' => array(
  482. 'notEmpty' => 'notEmpty'
  483. ),
  484. 'email' => array(
  485. 'email' => 'email',
  486. ),
  487. );
  488. $this->assertEquals($expected, $result);
  489. }
  490. /**
  491. * test the validation Generation routine
  492. *
  493. * @return void
  494. */
  495. public function testNonInteractiveDoValidation() {
  496. $this->markTestIncomplete('Not done here yet');
  497. $Model = $this->getMock('Model');
  498. $Model->primaryKey = 'id';
  499. $Model->expects($this->any())
  500. ->method('schema')
  501. ->will($this->returnValue(array(
  502. 'id' => array(
  503. 'type' => 'integer',
  504. 'length' => 11,
  505. 'null' => false,
  506. 'key' => 'primary',
  507. ),
  508. 'name' => array(
  509. 'type' => 'string',
  510. 'length' => 20,
  511. 'null' => false,
  512. ),
  513. 'email' => array(
  514. 'type' => 'string',
  515. 'length' => 255,
  516. 'null' => false,
  517. ),
  518. 'some_date' => array(
  519. 'type' => 'date',
  520. 'length' => '',
  521. 'null' => false,
  522. ),
  523. 'some_time' => array(
  524. 'type' => 'time',
  525. 'length' => '',
  526. 'null' => false,
  527. ),
  528. 'created' => array(
  529. 'type' => 'datetime',
  530. 'length' => '',
  531. 'null' => false,
  532. )
  533. )
  534. ));
  535. $this->Task->interactive = false;
  536. $result = $this->Task->doValidation($Model);
  537. $expected = array(
  538. 'name' => array(
  539. 'notEmpty' => 'notEmpty'
  540. ),
  541. 'email' => array(
  542. 'email' => 'email',
  543. ),
  544. 'some_date' => array(
  545. 'date' => 'date'
  546. ),
  547. 'some_time' => array(
  548. 'time' => 'time'
  549. ),
  550. );
  551. $this->assertEquals($expected, $result);
  552. }
  553. /**
  554. * test non interactive doAssociations
  555. *
  556. * @return void
  557. */
  558. public function testDoAssociationsNonInteractive() {
  559. $this->markTestIncomplete('Not done here yet');
  560. $this->Task->connection = 'test';
  561. $this->Task->interactive = false;
  562. $model = new Model(array('ds' => 'test', 'name' => 'BakeArticle'));
  563. $result = $this->Task->doAssociations($model);
  564. $expected = array(
  565. 'belongsTo' => array(
  566. array(
  567. 'alias' => 'BakeUser',
  568. 'className' => 'BakeUser',
  569. 'foreignKey' => 'bake_user_id',
  570. ),
  571. ),
  572. 'hasMany' => array(
  573. array(
  574. 'alias' => 'BakeComment',
  575. 'className' => 'BakeComment',
  576. 'foreignKey' => 'bake_article_id',
  577. ),
  578. ),
  579. 'hasAndBelongsToMany' => array(
  580. array(
  581. 'alias' => 'BakeTag',
  582. 'className' => 'BakeTag',
  583. 'foreignKey' => 'bake_article_id',
  584. 'joinTable' => 'bake_articles_bake_tags',
  585. 'associationForeignKey' => 'bake_tag_id',
  586. ),
  587. ),
  588. );
  589. $this->assertEquals($expected, $result);
  590. }
  591. /**
  592. * test non interactive doActsAs
  593. *
  594. * @return void
  595. */
  596. public function testDoActsAs() {
  597. $this->markTestIncomplete('Not done here yet');
  598. $this->Task->connection = 'test';
  599. $this->Task->interactive = false;
  600. $model = new Model(array('ds' => 'test', 'name' => 'NumberTree'));
  601. $result = $this->Task->doActsAs($model);
  602. $this->assertEquals(array('Tree'), $result);
  603. }
  604. /**
  605. * Ensure that the fixture object is correctly called.
  606. *
  607. * @return void
  608. */
  609. public function testBakeFixture() {
  610. $this->Task->plugin = 'TestPlugin';
  611. $this->Task->Fixture->expects($this->at(0))
  612. ->method('bake')
  613. ->with('BakeArticle', 'bake_articles');
  614. $this->Task->bakeFixture('BakeArticle', 'bake_articles');
  615. $this->assertEquals($this->Task->plugin, $this->Task->Fixture->plugin);
  616. $this->assertEquals($this->Task->connection, $this->Task->Fixture->connection);
  617. $this->assertEquals($this->Task->interactive, $this->Task->Fixture->interactive);
  618. }
  619. /**
  620. * Ensure that the fixture baking can be disabled
  621. *
  622. * @return void
  623. */
  624. public function testBakeFixtureDisabled() {
  625. $this->Task->params['no-fixture'] = true;
  626. $this->Task->plugin = 'TestPlugin';
  627. $this->Task->Fixture->expects($this->never())
  628. ->method('bake');
  629. $this->Task->bakeFixture('BakeArticle', 'bake_articles');
  630. }
  631. /**
  632. * Ensure that the test object is correctly called.
  633. *
  634. * @return void
  635. */
  636. public function testBakeTest() {
  637. $this->Task->plugin = 'TestPlugin';
  638. $this->Task->Test->expects($this->at(0))
  639. ->method('bake')
  640. ->with('Model', 'BakeArticle');
  641. $this->Task->bakeTest('BakeArticle');
  642. $this->assertEquals($this->Task->plugin, $this->Task->Test->plugin);
  643. $this->assertEquals($this->Task->connection, $this->Task->Test->connection);
  644. $this->assertEquals($this->Task->interactive, $this->Task->Test->interactive);
  645. }
  646. /**
  647. * Ensure that test baking can be disabled.
  648. *
  649. * @return void
  650. */
  651. public function testBakeTestDisabled() {
  652. $this->Task->params['no-test'] = true;
  653. $this->Task->plugin = 'TestPlugin';
  654. $this->Task->Test->expects($this->never())
  655. ->method('bake');
  656. $this->Task->bakeTest('BakeArticle');
  657. }
  658. /**
  659. * test confirming of associations, and that when an association is hasMany
  660. * a question for the hasOne is also not asked.
  661. *
  662. * @return void
  663. */
  664. public function testConfirmAssociations() {
  665. $this->markTestIncomplete('Not done here yet');
  666. $associations = array(
  667. 'hasOne' => array(
  668. array(
  669. 'alias' => 'ChildCategoryThread',
  670. 'className' => 'CategoryThread',
  671. 'foreignKey' => 'parent_id',
  672. ),
  673. ),
  674. 'hasMany' => array(
  675. array(
  676. 'alias' => 'ChildCategoryThread',
  677. 'className' => 'CategoryThread',
  678. 'foreignKey' => 'parent_id',
  679. ),
  680. ),
  681. 'belongsTo' => array(
  682. array(
  683. 'alias' => 'User',
  684. 'className' => 'User',
  685. 'foreignKey' => 'user_id',
  686. ),
  687. )
  688. );
  689. $model = new Model(array('ds' => 'test', 'name' => 'CategoryThread'));
  690. $this->Task->expects($this->any())->method('in')
  691. ->will($this->onConsecutiveCalls('n', 'y', 'n', 'n', 'n'));
  692. $result = $this->Task->confirmAssociations($model, $associations);
  693. $this->assertTrue(empty($result['hasOne']));
  694. $result = $this->Task->confirmAssociations($model, $associations);
  695. $this->assertTrue(empty($result['hasMany']));
  696. $this->assertTrue(empty($result['hasOne']));
  697. }
  698. /**
  699. * test that inOptions generates questions and only accepts a valid answer
  700. *
  701. * @return void
  702. */
  703. public function testInOptions() {
  704. $this->markTestIncomplete('Not done here yet');
  705. $this->_useMockedOut();
  706. $options = array('one', 'two', 'three');
  707. $this->Task->expects($this->at(0))->method('out')->with('1. one');
  708. $this->Task->expects($this->at(1))->method('out')->with('2. two');
  709. $this->Task->expects($this->at(2))->method('out')->with('3. three');
  710. $this->Task->expects($this->at(3))->method('in')->will($this->returnValue(10));
  711. $this->Task->expects($this->at(4))->method('out')->with('1. one');
  712. $this->Task->expects($this->at(5))->method('out')->with('2. two');
  713. $this->Task->expects($this->at(6))->method('out')->with('3. three');
  714. $this->Task->expects($this->at(7))->method('in')->will($this->returnValue(2));
  715. $result = $this->Task->inOptions($options, 'Pick a number');
  716. $this->assertEquals(1, $result);
  717. }
  718. /**
  719. * test baking validation
  720. *
  721. * @return void
  722. */
  723. public function testBakeValidation() {
  724. $this->markTestIncomplete('Not done here yet');
  725. $validate = array(
  726. 'name' => array(
  727. 'notempty' => 'notEmpty'
  728. ),
  729. 'email' => array(
  730. 'email' => 'email',
  731. ),
  732. 'some_date' => array(
  733. 'date' => 'date'
  734. ),
  735. 'some_time' => array(
  736. 'time' => 'time'
  737. )
  738. );
  739. $result = $this->Task->bake('BakeArticle', compact('validate'));
  740. $this->assertRegExp('/class BakeArticle extends AppModel \{/', $result);
  741. $this->assertRegExp('/\$validate \= array\(/', $result);
  742. $expected = <<< STRINGEND
  743. array(
  744. 'notempty' => array(
  745. 'rule' => array('notEmpty'),
  746. //'message' => 'Your custom message here',
  747. //'allowEmpty' => false,
  748. //'required' => false,
  749. //'last' => false, // Stop validation after this rule
  750. //'on' => 'create', // Limit validation to 'create' or 'update' operations
  751. ),
  752. STRINGEND;
  753. $this->assertRegExp('/' . preg_quote(str_replace("\r\n", "\n", $expected), '/') . '/', $result);
  754. }
  755. /**
  756. * test baking relations
  757. *
  758. * @return void
  759. */
  760. public function testBakeRelations() {
  761. $this->markTestIncomplete('Not done here yet');
  762. $associations = array(
  763. 'belongsTo' => array(
  764. array(
  765. 'alias' => 'SomethingElse',
  766. 'className' => 'SomethingElse',
  767. 'foreignKey' => 'something_else_id',
  768. ),
  769. array(
  770. 'alias' => 'BakeUser',
  771. 'className' => 'BakeUser',
  772. 'foreignKey' => 'bake_user_id',
  773. ),
  774. ),
  775. 'hasOne' => array(
  776. array(
  777. 'alias' => 'OtherModel',
  778. 'className' => 'OtherModel',
  779. 'foreignKey' => 'other_model_id',
  780. ),
  781. ),
  782. 'hasMany' => array(
  783. array(
  784. 'alias' => 'BakeComment',
  785. 'className' => 'BakeComment',
  786. 'foreignKey' => 'parent_id',
  787. ),
  788. ),
  789. 'hasAndBelongsToMany' => array(
  790. array(
  791. 'alias' => 'BakeTag',
  792. 'className' => 'BakeTag',
  793. 'foreignKey' => 'bake_article_id',
  794. 'joinTable' => 'bake_articles_bake_tags',
  795. 'associationForeignKey' => 'bake_tag_id',
  796. ),
  797. )
  798. );
  799. $result = $this->Task->bake('BakeArticle', compact('associations'));
  800. $this->assertContains(' * @property BakeUser $BakeUser', $result);
  801. $this->assertContains(' * @property OtherModel $OtherModel', $result);
  802. $this->assertContains(' * @property BakeComment $BakeComment', $result);
  803. $this->assertContains(' * @property BakeTag $BakeTag', $result);
  804. $this->assertRegExp('/\$hasAndBelongsToMany \= array\(/', $result);
  805. $this->assertRegExp('/\$hasMany \= array\(/', $result);
  806. $this->assertRegExp('/\$belongsTo \= array\(/', $result);
  807. $this->assertRegExp('/\$hasOne \= array\(/', $result);
  808. $this->assertRegExp('/BakeTag/', $result);
  809. $this->assertRegExp('/OtherModel/', $result);
  810. $this->assertRegExp('/SomethingElse/', $result);
  811. $this->assertRegExp('/BakeComment/', $result);
  812. }
  813. /**
  814. * test bake() with a -plugin param
  815. *
  816. * @return void
  817. */
  818. public function testBakeWithPlugin() {
  819. $this->markTestIncomplete('Not done here yet');
  820. $this->Task->plugin = 'ControllerTest';
  821. //fake plugin path
  822. Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/'));
  823. $path = APP . 'Plugin/ControllerTest/Model/BakeArticle.php';
  824. $this->Task->expects($this->once())->method('createFile')
  825. ->with($path, $this->stringContains('BakeArticle extends ControllerTestAppModel'));
  826. $result = $this->Task->bake('BakeArticle', array(), array());
  827. $this->assertContains("App::uses('ControllerTestAppModel', 'ControllerTest.Model');", $result);
  828. $this->assertEquals(count(ClassRegistry::keys()), 0);
  829. $this->assertEquals(count(ClassRegistry::mapKeys()), 0);
  830. }
  831. /**
  832. * test bake() for models with behaviors
  833. *
  834. * @return void
  835. */
  836. public function testBakeWithBehaviors() {
  837. $this->markTestIncomplete('Not done here yet');
  838. $result = $this->Task->bake('NumberTree', array('actsAs' => array('Tree', 'PluginName.Sluggable')));
  839. $expected = <<<TEXT
  840. /**
  841. * Behaviors
  842. *
  843. * @var array
  844. */
  845. public \$actsAs = array(
  846. 'Tree',
  847. 'PluginName.Sluggable',
  848. );
  849. TEXT;
  850. $this->assertTextContains($expected, $result);
  851. }
  852. /**
  853. * test that execute passes runs bake depending with named model.
  854. *
  855. * @return void
  856. */
  857. public function testExecuteWithNamedModel() {
  858. $this->markTestIncomplete('Not done here yet');
  859. $this->Task->connection = 'test';
  860. $this->Task->path = '/my/path/';
  861. $this->Task->args = array('BakeArticle');
  862. $filename = '/my/path/BakeArticle.php';
  863. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
  864. $this->Task->expects($this->once())->method('createFile')
  865. ->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
  866. $this->Task->execute();
  867. $this->assertEquals(count(ClassRegistry::keys()), 0);
  868. $this->assertEquals(count(ClassRegistry::mapKeys()), 0);
  869. }
  870. /**
  871. * data provider for testExecuteWithNamedModelVariations
  872. *
  873. * @return void
  874. */
  875. public static function nameVariations() {
  876. return array(
  877. array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
  878. );
  879. }
  880. /**
  881. * test that execute passes with different inflections of the same name.
  882. *
  883. * @dataProvider nameVariations
  884. * @return void
  885. */
  886. public function testExecuteWithNamedModelVariations($name) {
  887. $this->markTestIncomplete('Not done here yet');
  888. $this->Task->connection = 'test';
  889. $this->Task->path = '/my/path/';
  890. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
  891. $this->Task->args = array($name);
  892. $filename = '/my/path/BakeArticle.php';
  893. $this->Task->expects($this->at(0))->method('createFile')
  894. ->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
  895. $this->Task->execute();
  896. }
  897. /**
  898. * test that execute with a model name picks up hasMany associations.
  899. *
  900. * @return void
  901. */
  902. public function testExecuteWithNamedModelHasManyCreated() {
  903. $this->markTestIncomplete('Not done here yet');
  904. $this->Task->connection = 'test';
  905. $this->Task->path = '/my/path/';
  906. $this->Task->args = array('BakeArticle');
  907. $filename = '/my/path/BakeArticle.php';
  908. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
  909. $this->Task->expects($this->at(0))->method('createFile')
  910. ->with($filename, $this->stringContains("'BakeComment' => array("));
  911. $this->Task->execute();
  912. }
  913. /**
  914. * test that execute runs all() when args[0] = all
  915. *
  916. * @return void
  917. */
  918. public function testExecuteIntoAll() {
  919. $this->markTestIncomplete('Not done here yet');
  920. $count = count($this->Task->listAll('test'));
  921. if ($count != count($this->fixtures)) {
  922. $this->markTestSkipped('Additional tables detected.');
  923. }
  924. $this->Task->connection = 'test';
  925. $this->Task->path = '/my/path/';
  926. $this->Task->args = array('all');
  927. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  928. $this->Task->Fixture->expects($this->exactly(5))->method('bake');
  929. $this->Task->Test->expects($this->exactly(5))->method('bake');
  930. $filename = '/my/path/BakeArticle.php';
  931. $this->Task->expects($this->at(1))->method('createFile')
  932. ->with($filename, $this->stringContains('class BakeArticle'));
  933. $filename = '/my/path/BakeArticlesBakeTag.php';
  934. $this->Task->expects($this->at(2))->method('createFile')
  935. ->with($filename, $this->stringContains('class BakeArticlesBakeTag'));
  936. $filename = '/my/path/BakeComment.php';
  937. $this->Task->expects($this->at(3))->method('createFile')
  938. ->with($filename, $this->stringContains('class BakeComment'));
  939. $filename = '/my/path/BakeComment.php';
  940. $this->Task->expects($this->at(3))->method('createFile')
  941. ->with($filename, $this->stringContains('public $primaryKey = \'otherid\';'));
  942. $filename = '/my/path/BakeTag.php';
  943. $this->Task->expects($this->at(4))->method('createFile')
  944. ->with($filename, $this->stringContains('class BakeTag'));
  945. $filename = '/my/path/BakeTag.php';
  946. $this->Task->expects($this->at(4))->method('createFile')
  947. ->with($filename, $this->logicalNot($this->stringContains('public $primaryKey')));
  948. $filename = '/my/path/CategoryThread.php';
  949. $this->Task->expects($this->at(5))->method('createFile')
  950. ->with($filename, $this->stringContains('class CategoryThread'));
  951. $this->Task->execute();
  952. $this->assertEquals(count(ClassRegistry::keys()), 0);
  953. $this->assertEquals(count(ClassRegistry::mapKeys()), 0);
  954. }
  955. /**
  956. * test that odd tablenames aren't inflected back from modelname
  957. *
  958. * @return void
  959. */
  960. public function testExecuteIntoAllOddTables() {
  961. $this->markTestIncomplete('Not done here yet');
  962. $out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false);
  963. $in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
  964. $this->Task = $this->getMock('Cake\Console\Command\Task\ModelTask',
  965. array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'bake', 'bakeFixture'),
  966. array($out, $out, $in)
  967. );
  968. $this->_setupOtherMocks();
  969. $this->Task->connection = 'test';
  970. $this->Task->path = '/my/path/';
  971. $this->Task->args = array('all');
  972. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  973. $this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('bake_odd')));
  974. $object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
  975. $this->Task->expects($this->once())->method('_getModelObject')->with('BakeOdd', 'bake_odd')->will($this->returnValue($object));
  976. $this->Task->expects($this->at(3))->method('bake')->with($object, false)->will($this->returnValue(true));
  977. $this->Task->expects($this->once())->method('bakeFixture')->with('BakeOdd', 'bake_odd');
  978. $this->Task->execute();
  979. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  980. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  981. $this->Task = $this->getMock('ModelTask',
  982. array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'doActsAs', 'createFile'),
  983. array($out, $out, $in)
  984. );
  985. $this->_setupOtherMocks();
  986. $this->Task->connection = 'test';
  987. $this->Task->path = '/my/path/';
  988. $this->Task->args = array('all');
  989. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  990. $this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('bake_odd')));
  991. $object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
  992. $this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object));
  993. $this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array()));
  994. $this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array()));
  995. $this->Task->expects($this->once())->method('doActsAs')->will($this->returnValue(array()));
  996. $filename = '/my/path/BakeOdd.php';
  997. $this->Task->expects($this->once())->method('createFile')
  998. ->with($filename, $this->stringContains('class BakeOdd'));
  999. $filename = '/my/path/BakeOdd.php';
  1000. $this->Task->expects($this->once())->method('createFile')
  1001. ->with($filename, $this->stringContains('public $useTable = \'bake_odd\''));
  1002. $this->Task->execute();
  1003. }
  1004. /**
  1005. * test that odd tablenames aren't inflected back from modelname
  1006. *
  1007. * @return void
  1008. */
  1009. public function testExecuteIntoBakeOddTables() {
  1010. $this->markTestIncomplete('Not done here yet');
  1011. $out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false);
  1012. $in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
  1013. $this->Task = $this->getMock('Cake\Console\Command\Task\ModelTask',
  1014. array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'bake', 'bakeFixture'),
  1015. array($out, $out, $in)
  1016. );
  1017. $this->_setupOtherMocks();
  1018. $this->Task->connection = 'test';
  1019. $this->Task->path = '/my/path/';
  1020. $this->Task->args = array('BakeOdd');
  1021. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  1022. $this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
  1023. $object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
  1024. $this->Task->expects($this->once())->method('_getModelObject')->with('BakeOdd', 'bake_odd')->will($this->returnValue($object));
  1025. $this->Task->expects($this->once())->method('bake')->with($object, false)->will($this->returnValue(true));
  1026. $this->Task->expects($this->once())->method('bakeFixture')->with('BakeOdd', 'bake_odd');
  1027. $this->Task->execute();
  1028. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  1029. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  1030. $this->Task = $this->getMock('ModelTask',
  1031. array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'doActsAs', 'createFile'),
  1032. array($out, $out, $in)
  1033. );
  1034. $this->_setupOtherMocks();
  1035. $this->Task->connection = 'test';
  1036. $this->Task->path = '/my/path/';
  1037. $this->Task->args = array('BakeOdd');
  1038. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  1039. $this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
  1040. $object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
  1041. $this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object));
  1042. $this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array()));
  1043. $this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array()));
  1044. $this->Task->expects($this->once())->method('doActsAs')->will($this->returnValue(array()));
  1045. $filename = '/my/path/BakeOdd.php';
  1046. $this->Task->expects($this->once())->method('createFile')
  1047. ->with($filename, $this->stringContains('class BakeOdd'));
  1048. $filename = '/my/path/BakeOdd.php';
  1049. $this->Task->expects($this->once())->method('createFile')
  1050. ->with($filename, $this->stringContains('public $useTable = \'bake_odd\''));
  1051. $this->Task->execute();
  1052. }
  1053. /**
  1054. * test that skipTables changes how all() works.
  1055. *
  1056. * @return void
  1057. */
  1058. public function testSkipTablesAndAll() {
  1059. $this->markTestIncomplete('Not done here yet');
  1060. $count = count($this->Task->listAll('test'));
  1061. if ($count != count($this->fixtures)) {
  1062. $this->markTestSkipped('Additional tables detected.');
  1063. }
  1064. $this->Task->connection = 'test';
  1065. $this->Task->path = '/my/path/';
  1066. $this->Task->args = array('all');
  1067. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  1068. $this->Task->skipTables = array('bake_tags');
  1069. $this->Task->Fixture->expects($this->exactly(4))->method('bake');
  1070. $this->Task->Test->expects($this->exactly(4))->method('bake');
  1071. $filename = '/my/path/BakeArticle.php';
  1072. $this->Task->expects($this->at(1))->method('createFile')
  1073. ->with($filename, $this->stringContains('class BakeArticle'));
  1074. $filename = '/my/path/BakeArticlesBakeTag.php';
  1075. $this->Task->expects($this->at(2))->method('createFile')
  1076. ->with($filename, $this->stringContains('class BakeArticlesBakeTag'));
  1077. $filename = '/my/path/BakeComment.php';
  1078. $this->Task->expects($this->at(3))->method('createFile')
  1079. ->with($filename, $this->stringContains('class BakeComment'));
  1080. $filename = '/my/path/CategoryThread.php';
  1081. $this->Task->expects($this->at(4))->method('createFile')
  1082. ->with($filename, $this->stringContains('class CategoryThread'));
  1083. $this->Task->execute();
  1084. }
  1085. /**
  1086. * test the interactive side of bake.
  1087. *
  1088. * @return void
  1089. */
  1090. public function testExecuteIntoInteractive() {
  1091. $this->markTestIncomplete('Not done here yet');
  1092. $tables = $this->Task->listAll('test');
  1093. $article = array_search('bake_articles', $tables) + 1;
  1094. $this->Task->connection = 'test';
  1095. $this->Task->path = '/my/path/';
  1096. $this->Task->interactive = true;
  1097. $this->Task->expects($this->any())->method('in')
  1098. ->will($this->onConsecutiveCalls(
  1099. $article, // article
  1100. 'n', // no validation
  1101. 'y', // associations
  1102. 'y', // comment relation
  1103. 'y', // user relation
  1104. 'y', // tag relation
  1105. 'n', // additional assocs
  1106. 'y' // looks good?
  1107. ));
  1108. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  1109. $this->Task->Test->expects($this->once())->method('bake');
  1110. $this->Task->Fixture->expects($this->once())->method('bake');
  1111. $filename = '/my/path/BakeArticle.php';
  1112. $this->Task->expects($this->once())->method('createFile')
  1113. ->with($filename, $this->stringContains('class BakeArticle'));
  1114. $this->Task->execute();
  1115. $this->assertEquals(count(ClassRegistry::keys()), 0);
  1116. $this->assertEquals(count(ClassRegistry::mapKeys()), 0);
  1117. }
  1118. /**
  1119. * test using bake interactively with a table that does not exist.
  1120. *
  1121. * @return void
  1122. */
  1123. public function testExecuteWithNonExistantTableName() {
  1124. $this->markTestIncomplete('Not done here yet');
  1125. $this->Task->connection = 'test';
  1126. $this->Task->path = '/my/path/';
  1127. $this->Task->expects($this->any())->method('in')
  1128. ->will($this->onConsecutiveCalls(
  1129. 'Foobar', // Or type in the name of the model
  1130. 'y', // Do you want to use this table
  1131. 'n' // Doesn't exist, continue anyway?
  1132. ));
  1133. $this->Task->execute();
  1134. }
  1135. /**
  1136. * test using bake interactively with a table that does not exist.
  1137. *
  1138. * @return void
  1139. */
  1140. public function testForcedExecuteWithNonExistantTableName() {
  1141. $this->markTestIncomplete('Not done here yet');
  1142. $this->Task->connection = 'test';
  1143. $this->Task->path = '/my/path/';
  1144. $this->Task->expects($this->any())->method('in')
  1145. ->will($this->onConsecutiveCalls(
  1146. 'Foobar', // Or type in the name of the model
  1147. 'y', // Do you want to use this table
  1148. 'y', // Doesn't exist, continue anyway?
  1149. 'id', // Primary key
  1150. 'y' // Looks good?
  1151. ));
  1152. $this->Task->execute();
  1153. }
  1154. }