ModelTaskTest.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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 getting validation rules with the no-validation rule.
  315. *
  316. * @return void
  317. */
  318. public function testGetValidationDisabled() {
  319. $model = TableRegistry::get('BakeArticles');
  320. $this->Task->params['no-validation'] = true;
  321. $result = $this->Task->getValidation($model);
  322. $this->assertEquals([], $result);
  323. }
  324. /**
  325. * test getting validation rules.
  326. *
  327. * @return void
  328. */
  329. public function testGetValidation() {
  330. $model = TableRegistry::get('BakeArticles');
  331. $result = $this->Task->getValidation($model);
  332. $expected = [
  333. 'id' => ['rule' => 'numeric', 'allowEmpty' => true],
  334. 'bake_user_id' => ['rule' => 'numeric', 'allowEmpty' => true],
  335. 'title' => ['rule' => 'notEmpty', 'allowEmpty' => false],
  336. 'body' => ['rule' => 'notEmpty', 'allowEmpty' => false],
  337. 'published' => ['rule' => 'boolean', 'allowEmpty' => false],
  338. ];
  339. $this->assertEquals($expected, $result);
  340. }
  341. /**
  342. * test that individual field validation works, with interactive = false
  343. * tests the guessing features of validation
  344. *
  345. * @return void
  346. */
  347. public function testFieldValidationGuessing() {
  348. $this->markTestIncomplete('Not done here yet');
  349. $this->Task->interactive = false;
  350. $this->Task->initValidations();
  351. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  352. $expected = array('notEmpty' => 'notEmpty');
  353. $this->assertEquals($expected, $result);
  354. $result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false));
  355. $expected = array('date' => 'date');
  356. $this->assertEquals($expected, $result);
  357. $result = $this->Task->fieldValidation('text', array('type' => 'time', 'length' => 10, 'null' => false));
  358. $expected = array('time' => 'time');
  359. $this->assertEquals($expected, $result);
  360. $result = $this->Task->fieldValidation('email', array('type' => 'string', 'length' => 10, 'null' => false));
  361. $expected = array('email' => 'email');
  362. $this->assertEquals($expected, $result);
  363. $result = $this->Task->fieldValidation('test', array('type' => 'integer', 'length' => 10, 'null' => false));
  364. $expected = array('numeric' => 'numeric');
  365. $this->assertEquals($expected, $result);
  366. $result = $this->Task->fieldValidation('test', array('type' => 'boolean', 'length' => 10, 'null' => false));
  367. $expected = array('boolean' => 'boolean');
  368. $this->assertEquals($expected, $result);
  369. }
  370. /**
  371. * test that interactive field validation works and returns multiple validators.
  372. *
  373. * @return void
  374. */
  375. public function testInteractiveFieldValidation() {
  376. $this->markTestIncomplete('Not done here yet');
  377. $this->Task->initValidations();
  378. $this->Task->interactive = true;
  379. $this->Task->expects($this->any())->method('in')
  380. ->will($this->onConsecutiveCalls('24', 'y', '18', 'n'));
  381. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  382. $expected = array('notEmpty' => 'notEmpty', 'maxLength' => 'maxLength');
  383. $this->assertEquals($expected, $result);
  384. }
  385. /**
  386. * test that a bogus response doesn't cause errors to bubble up.
  387. *
  388. * @return void
  389. */
  390. public function testInteractiveFieldValidationWithBogusResponse() {
  391. $this->markTestIncomplete('Not done here yet');
  392. $this->_useMockedOut();
  393. $this->Task->initValidations();
  394. $this->Task->interactive = true;
  395. $this->Task->expects($this->any())->method('in')
  396. ->will($this->onConsecutiveCalls('999999', '24', 'n'));
  397. $this->Task->expects($this->at(10))->method('out')
  398. ->with($this->stringContains('make a valid'));
  399. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  400. $expected = array('notEmpty' => 'notEmpty');
  401. $this->assertEquals($expected, $result);
  402. }
  403. /**
  404. * test that a regular expression can be used for validation.
  405. *
  406. * @return void
  407. */
  408. public function testInteractiveFieldValidationWithRegexp() {
  409. $this->markTestIncomplete('Not done here yet');
  410. $this->Task->initValidations();
  411. $this->Task->interactive = true;
  412. $this->Task->expects($this->any())->method('in')
  413. ->will($this->onConsecutiveCalls('/^[a-z]{0,9}$/', 'n'));
  414. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  415. $expected = array('a_z_0_9' => '/^[a-z]{0,9}$/');
  416. $this->assertEquals($expected, $result);
  417. }
  418. /**
  419. * Test that skipping fields during rule choice works when doing interactive field validation.
  420. *
  421. * @return void
  422. */
  423. public function testSkippingChoiceInteractiveFieldValidation() {
  424. $this->markTestIncomplete('Not done here yet');
  425. $this->Task->initValidations();
  426. $this->Task->interactive = true;
  427. $this->Task->expects($this->any())->method('in')
  428. ->will($this->onConsecutiveCalls('24', 'y', 's'));
  429. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  430. $expected = array('notEmpty' => 'notEmpty', '_skipFields' => true);
  431. $this->assertEquals($expected, $result);
  432. }
  433. /**
  434. * Test that skipping fields after rule choice works when doing interactive field validation.
  435. *
  436. * @return void
  437. */
  438. public function testSkippingAnotherInteractiveFieldValidation() {
  439. $this->markTestIncomplete('Not done here yet');
  440. $this->Task->initValidations();
  441. $this->Task->interactive = true;
  442. $this->Task->expects($this->any())->method('in')
  443. ->will($this->onConsecutiveCalls('24', 's'));
  444. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  445. $expected = array('notEmpty' => 'notEmpty', '_skipFields' => true);
  446. $this->assertEquals($expected, $result);
  447. }
  448. /**
  449. * Test the validation generation routine with skipping the rest of the fields
  450. * when doing interactive field validation.
  451. *
  452. * @return void
  453. */
  454. public function testInteractiveDoValidationWithSkipping() {
  455. $this->markTestIncomplete('Not done here yet');
  456. $this->Task->expects($this->any())
  457. ->method('in')
  458. ->will($this->onConsecutiveCalls('35', '24', 'n', '11', 's'));
  459. $this->Task->interactive = true;
  460. $Model = $this->getMock('Model');
  461. $Model->primaryKey = 'id';
  462. $Model->expects($this->any())
  463. ->method('schema')
  464. ->will($this->returnValue(array(
  465. 'id' => array(
  466. 'type' => 'integer',
  467. 'length' => 11,
  468. 'null' => false,
  469. 'key' => 'primary',
  470. ),
  471. 'name' => array(
  472. 'type' => 'string',
  473. 'length' => 20,
  474. 'null' => false,
  475. ),
  476. 'email' => array(
  477. 'type' => 'string',
  478. 'length' => 255,
  479. 'null' => false,
  480. ),
  481. 'some_date' => array(
  482. 'type' => 'date',
  483. 'length' => '',
  484. 'null' => false,
  485. ),
  486. 'some_time' => array(
  487. 'type' => 'time',
  488. 'length' => '',
  489. 'null' => false,
  490. ),
  491. 'created' => array(
  492. 'type' => 'datetime',
  493. 'length' => '',
  494. 'null' => false,
  495. )
  496. )
  497. ));
  498. $result = $this->Task->doValidation($Model);
  499. $expected = array(
  500. 'name' => array(
  501. 'notEmpty' => 'notEmpty'
  502. ),
  503. 'email' => array(
  504. 'email' => 'email',
  505. ),
  506. );
  507. $this->assertEquals($expected, $result);
  508. }
  509. /**
  510. * test the validation Generation routine
  511. *
  512. * @return void
  513. */
  514. public function testNonInteractiveDoValidation() {
  515. $this->markTestIncomplete('Not done here yet');
  516. $Model = $this->getMock('Model');
  517. $Model->primaryKey = 'id';
  518. $Model->expects($this->any())
  519. ->method('schema')
  520. ->will($this->returnValue(array(
  521. 'id' => array(
  522. 'type' => 'integer',
  523. 'length' => 11,
  524. 'null' => false,
  525. 'key' => 'primary',
  526. ),
  527. 'name' => array(
  528. 'type' => 'string',
  529. 'length' => 20,
  530. 'null' => false,
  531. ),
  532. 'email' => array(
  533. 'type' => 'string',
  534. 'length' => 255,
  535. 'null' => false,
  536. ),
  537. 'some_date' => array(
  538. 'type' => 'date',
  539. 'length' => '',
  540. 'null' => false,
  541. ),
  542. 'some_time' => array(
  543. 'type' => 'time',
  544. 'length' => '',
  545. 'null' => false,
  546. ),
  547. 'created' => array(
  548. 'type' => 'datetime',
  549. 'length' => '',
  550. 'null' => false,
  551. )
  552. )
  553. ));
  554. $this->Task->interactive = false;
  555. $result = $this->Task->doValidation($Model);
  556. $expected = array(
  557. 'name' => array(
  558. 'notEmpty' => 'notEmpty'
  559. ),
  560. 'email' => array(
  561. 'email' => 'email',
  562. ),
  563. 'some_date' => array(
  564. 'date' => 'date'
  565. ),
  566. 'some_time' => array(
  567. 'time' => 'time'
  568. ),
  569. );
  570. $this->assertEquals($expected, $result);
  571. }
  572. /**
  573. * test non interactive doAssociations
  574. *
  575. * @return void
  576. */
  577. public function testDoAssociationsNonInteractive() {
  578. $this->markTestIncomplete('Not done here yet');
  579. $this->Task->connection = 'test';
  580. $this->Task->interactive = false;
  581. $model = new Model(array('ds' => 'test', 'name' => 'BakeArticle'));
  582. $result = $this->Task->doAssociations($model);
  583. $expected = array(
  584. 'belongsTo' => array(
  585. array(
  586. 'alias' => 'BakeUser',
  587. 'className' => 'BakeUser',
  588. 'foreignKey' => 'bake_user_id',
  589. ),
  590. ),
  591. 'hasMany' => array(
  592. array(
  593. 'alias' => 'BakeComment',
  594. 'className' => 'BakeComment',
  595. 'foreignKey' => 'bake_article_id',
  596. ),
  597. ),
  598. 'hasAndBelongsToMany' => array(
  599. array(
  600. 'alias' => 'BakeTag',
  601. 'className' => 'BakeTag',
  602. 'foreignKey' => 'bake_article_id',
  603. 'joinTable' => 'bake_articles_bake_tags',
  604. 'associationForeignKey' => 'bake_tag_id',
  605. ),
  606. ),
  607. );
  608. $this->assertEquals($expected, $result);
  609. }
  610. /**
  611. * test non interactive doActsAs
  612. *
  613. * @return void
  614. */
  615. public function testDoActsAs() {
  616. $this->markTestIncomplete('Not done here yet');
  617. $this->Task->connection = 'test';
  618. $this->Task->interactive = false;
  619. $model = new Model(array('ds' => 'test', 'name' => 'NumberTree'));
  620. $result = $this->Task->doActsAs($model);
  621. $this->assertEquals(array('Tree'), $result);
  622. }
  623. /**
  624. * Ensure that the fixture object is correctly called.
  625. *
  626. * @return void
  627. */
  628. public function testBakeFixture() {
  629. $this->Task->plugin = 'TestPlugin';
  630. $this->Task->Fixture->expects($this->at(0))
  631. ->method('bake')
  632. ->with('BakeArticle', 'bake_articles');
  633. $this->Task->bakeFixture('BakeArticle', 'bake_articles');
  634. $this->assertEquals($this->Task->plugin, $this->Task->Fixture->plugin);
  635. $this->assertEquals($this->Task->connection, $this->Task->Fixture->connection);
  636. $this->assertEquals($this->Task->interactive, $this->Task->Fixture->interactive);
  637. }
  638. /**
  639. * Ensure that the fixture baking can be disabled
  640. *
  641. * @return void
  642. */
  643. public function testBakeFixtureDisabled() {
  644. $this->Task->params['no-fixture'] = true;
  645. $this->Task->plugin = 'TestPlugin';
  646. $this->Task->Fixture->expects($this->never())
  647. ->method('bake');
  648. $this->Task->bakeFixture('BakeArticle', 'bake_articles');
  649. }
  650. /**
  651. * Ensure that the test object is correctly called.
  652. *
  653. * @return void
  654. */
  655. public function testBakeTest() {
  656. $this->Task->plugin = 'TestPlugin';
  657. $this->Task->Test->expects($this->at(0))
  658. ->method('bake')
  659. ->with('Model', 'BakeArticle');
  660. $this->Task->bakeTest('BakeArticle');
  661. $this->assertEquals($this->Task->plugin, $this->Task->Test->plugin);
  662. $this->assertEquals($this->Task->connection, $this->Task->Test->connection);
  663. $this->assertEquals($this->Task->interactive, $this->Task->Test->interactive);
  664. }
  665. /**
  666. * Ensure that test baking can be disabled.
  667. *
  668. * @return void
  669. */
  670. public function testBakeTestDisabled() {
  671. $this->Task->params['no-test'] = true;
  672. $this->Task->plugin = 'TestPlugin';
  673. $this->Task->Test->expects($this->never())
  674. ->method('bake');
  675. $this->Task->bakeTest('BakeArticle');
  676. }
  677. /**
  678. * test confirming of associations, and that when an association is hasMany
  679. * a question for the hasOne is also not asked.
  680. *
  681. * @return void
  682. */
  683. public function testConfirmAssociations() {
  684. $this->markTestIncomplete('Not done here yet');
  685. $associations = array(
  686. 'hasOne' => array(
  687. array(
  688. 'alias' => 'ChildCategoryThread',
  689. 'className' => 'CategoryThread',
  690. 'foreignKey' => 'parent_id',
  691. ),
  692. ),
  693. 'hasMany' => array(
  694. array(
  695. 'alias' => 'ChildCategoryThread',
  696. 'className' => 'CategoryThread',
  697. 'foreignKey' => 'parent_id',
  698. ),
  699. ),
  700. 'belongsTo' => array(
  701. array(
  702. 'alias' => 'User',
  703. 'className' => 'User',
  704. 'foreignKey' => 'user_id',
  705. ),
  706. )
  707. );
  708. $model = new Model(array('ds' => 'test', 'name' => 'CategoryThread'));
  709. $this->Task->expects($this->any())->method('in')
  710. ->will($this->onConsecutiveCalls('n', 'y', 'n', 'n', 'n'));
  711. $result = $this->Task->confirmAssociations($model, $associations);
  712. $this->assertTrue(empty($result['hasOne']));
  713. $result = $this->Task->confirmAssociations($model, $associations);
  714. $this->assertTrue(empty($result['hasMany']));
  715. $this->assertTrue(empty($result['hasOne']));
  716. }
  717. /**
  718. * test that inOptions generates questions and only accepts a valid answer
  719. *
  720. * @return void
  721. */
  722. public function testInOptions() {
  723. $this->markTestIncomplete('Not done here yet');
  724. $this->_useMockedOut();
  725. $options = array('one', 'two', 'three');
  726. $this->Task->expects($this->at(0))->method('out')->with('1. one');
  727. $this->Task->expects($this->at(1))->method('out')->with('2. two');
  728. $this->Task->expects($this->at(2))->method('out')->with('3. three');
  729. $this->Task->expects($this->at(3))->method('in')->will($this->returnValue(10));
  730. $this->Task->expects($this->at(4))->method('out')->with('1. one');
  731. $this->Task->expects($this->at(5))->method('out')->with('2. two');
  732. $this->Task->expects($this->at(6))->method('out')->with('3. three');
  733. $this->Task->expects($this->at(7))->method('in')->will($this->returnValue(2));
  734. $result = $this->Task->inOptions($options, 'Pick a number');
  735. $this->assertEquals(1, $result);
  736. }
  737. /**
  738. * test baking validation
  739. *
  740. * @return void
  741. */
  742. public function testBakeValidation() {
  743. $this->markTestIncomplete('Not done here yet');
  744. $validate = array(
  745. 'name' => array(
  746. 'notempty' => 'notEmpty'
  747. ),
  748. 'email' => array(
  749. 'email' => 'email',
  750. ),
  751. 'some_date' => array(
  752. 'date' => 'date'
  753. ),
  754. 'some_time' => array(
  755. 'time' => 'time'
  756. )
  757. );
  758. $result = $this->Task->bake('BakeArticle', compact('validate'));
  759. $this->assertRegExp('/class BakeArticle extends AppModel \{/', $result);
  760. $this->assertRegExp('/\$validate \= array\(/', $result);
  761. $expected = <<< STRINGEND
  762. array(
  763. 'notempty' => array(
  764. 'rule' => array('notEmpty'),
  765. //'message' => 'Your custom message here',
  766. //'allowEmpty' => false,
  767. //'required' => false,
  768. //'last' => false, // Stop validation after this rule
  769. //'on' => 'create', // Limit validation to 'create' or 'update' operations
  770. ),
  771. STRINGEND;
  772. $this->assertRegExp('/' . preg_quote(str_replace("\r\n", "\n", $expected), '/') . '/', $result);
  773. }
  774. /**
  775. * test baking relations
  776. *
  777. * @return void
  778. */
  779. public function testBakeRelations() {
  780. $this->markTestIncomplete('Not done here yet');
  781. $associations = array(
  782. 'belongsTo' => array(
  783. array(
  784. 'alias' => 'SomethingElse',
  785. 'className' => 'SomethingElse',
  786. 'foreignKey' => 'something_else_id',
  787. ),
  788. array(
  789. 'alias' => 'BakeUser',
  790. 'className' => 'BakeUser',
  791. 'foreignKey' => 'bake_user_id',
  792. ),
  793. ),
  794. 'hasOne' => array(
  795. array(
  796. 'alias' => 'OtherModel',
  797. 'className' => 'OtherModel',
  798. 'foreignKey' => 'other_model_id',
  799. ),
  800. ),
  801. 'hasMany' => array(
  802. array(
  803. 'alias' => 'BakeComment',
  804. 'className' => 'BakeComment',
  805. 'foreignKey' => 'parent_id',
  806. ),
  807. ),
  808. 'hasAndBelongsToMany' => array(
  809. array(
  810. 'alias' => 'BakeTag',
  811. 'className' => 'BakeTag',
  812. 'foreignKey' => 'bake_article_id',
  813. 'joinTable' => 'bake_articles_bake_tags',
  814. 'associationForeignKey' => 'bake_tag_id',
  815. ),
  816. )
  817. );
  818. $result = $this->Task->bake('BakeArticle', compact('associations'));
  819. $this->assertContains(' * @property BakeUser $BakeUser', $result);
  820. $this->assertContains(' * @property OtherModel $OtherModel', $result);
  821. $this->assertContains(' * @property BakeComment $BakeComment', $result);
  822. $this->assertContains(' * @property BakeTag $BakeTag', $result);
  823. $this->assertRegExp('/\$hasAndBelongsToMany \= array\(/', $result);
  824. $this->assertRegExp('/\$hasMany \= array\(/', $result);
  825. $this->assertRegExp('/\$belongsTo \= array\(/', $result);
  826. $this->assertRegExp('/\$hasOne \= array\(/', $result);
  827. $this->assertRegExp('/BakeTag/', $result);
  828. $this->assertRegExp('/OtherModel/', $result);
  829. $this->assertRegExp('/SomethingElse/', $result);
  830. $this->assertRegExp('/BakeComment/', $result);
  831. }
  832. /**
  833. * test bake() with a -plugin param
  834. *
  835. * @return void
  836. */
  837. public function testBakeWithPlugin() {
  838. $this->markTestIncomplete('Not done here yet');
  839. $this->Task->plugin = 'ControllerTest';
  840. //fake plugin path
  841. Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/'));
  842. $path = APP . 'Plugin/ControllerTest/Model/BakeArticle.php';
  843. $this->Task->expects($this->once())->method('createFile')
  844. ->with($path, $this->stringContains('BakeArticle extends ControllerTestAppModel'));
  845. $result = $this->Task->bake('BakeArticle', array(), array());
  846. $this->assertContains("App::uses('ControllerTestAppModel', 'ControllerTest.Model');", $result);
  847. $this->assertEquals(count(ClassRegistry::keys()), 0);
  848. $this->assertEquals(count(ClassRegistry::mapKeys()), 0);
  849. }
  850. /**
  851. * test bake() for models with behaviors
  852. *
  853. * @return void
  854. */
  855. public function testBakeWithBehaviors() {
  856. $this->markTestIncomplete('Not done here yet');
  857. $result = $this->Task->bake('NumberTree', array('actsAs' => array('Tree', 'PluginName.Sluggable')));
  858. $expected = <<<TEXT
  859. /**
  860. * Behaviors
  861. *
  862. * @var array
  863. */
  864. public \$actsAs = array(
  865. 'Tree',
  866. 'PluginName.Sluggable',
  867. );
  868. TEXT;
  869. $this->assertTextContains($expected, $result);
  870. }
  871. /**
  872. * test that execute passes runs bake depending with named model.
  873. *
  874. * @return void
  875. */
  876. public function testExecuteWithNamedModel() {
  877. $this->markTestIncomplete('Not done here yet');
  878. $this->Task->connection = 'test';
  879. $this->Task->path = '/my/path/';
  880. $this->Task->args = array('BakeArticle');
  881. $filename = '/my/path/BakeArticle.php';
  882. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
  883. $this->Task->expects($this->once())->method('createFile')
  884. ->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
  885. $this->Task->execute();
  886. $this->assertEquals(count(ClassRegistry::keys()), 0);
  887. $this->assertEquals(count(ClassRegistry::mapKeys()), 0);
  888. }
  889. /**
  890. * data provider for testExecuteWithNamedModelVariations
  891. *
  892. * @return void
  893. */
  894. public static function nameVariations() {
  895. return array(
  896. array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
  897. );
  898. }
  899. /**
  900. * test that execute passes with different inflections of the same name.
  901. *
  902. * @dataProvider nameVariations
  903. * @return void
  904. */
  905. public function testExecuteWithNamedModelVariations($name) {
  906. $this->markTestIncomplete('Not done here yet');
  907. $this->Task->connection = 'test';
  908. $this->Task->path = '/my/path/';
  909. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
  910. $this->Task->args = array($name);
  911. $filename = '/my/path/BakeArticle.php';
  912. $this->Task->expects($this->at(0))->method('createFile')
  913. ->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
  914. $this->Task->execute();
  915. }
  916. /**
  917. * test that execute with a model name picks up hasMany associations.
  918. *
  919. * @return void
  920. */
  921. public function testExecuteWithNamedModelHasManyCreated() {
  922. $this->markTestIncomplete('Not done here yet');
  923. $this->Task->connection = 'test';
  924. $this->Task->path = '/my/path/';
  925. $this->Task->args = array('BakeArticle');
  926. $filename = '/my/path/BakeArticle.php';
  927. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
  928. $this->Task->expects($this->at(0))->method('createFile')
  929. ->with($filename, $this->stringContains("'BakeComment' => array("));
  930. $this->Task->execute();
  931. }
  932. /**
  933. * test that execute runs all() when args[0] = all
  934. *
  935. * @return void
  936. */
  937. public function testExecuteIntoAll() {
  938. $this->markTestIncomplete('Not done here yet');
  939. $count = count($this->Task->listAll('test'));
  940. if ($count != count($this->fixtures)) {
  941. $this->markTestSkipped('Additional tables detected.');
  942. }
  943. $this->Task->connection = 'test';
  944. $this->Task->path = '/my/path/';
  945. $this->Task->args = array('all');
  946. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  947. $this->Task->Fixture->expects($this->exactly(5))->method('bake');
  948. $this->Task->Test->expects($this->exactly(5))->method('bake');
  949. $filename = '/my/path/BakeArticle.php';
  950. $this->Task->expects($this->at(1))->method('createFile')
  951. ->with($filename, $this->stringContains('class BakeArticle'));
  952. $filename = '/my/path/BakeArticlesBakeTag.php';
  953. $this->Task->expects($this->at(2))->method('createFile')
  954. ->with($filename, $this->stringContains('class BakeArticlesBakeTag'));
  955. $filename = '/my/path/BakeComment.php';
  956. $this->Task->expects($this->at(3))->method('createFile')
  957. ->with($filename, $this->stringContains('class BakeComment'));
  958. $filename = '/my/path/BakeComment.php';
  959. $this->Task->expects($this->at(3))->method('createFile')
  960. ->with($filename, $this->stringContains('public $primaryKey = \'otherid\';'));
  961. $filename = '/my/path/BakeTag.php';
  962. $this->Task->expects($this->at(4))->method('createFile')
  963. ->with($filename, $this->stringContains('class BakeTag'));
  964. $filename = '/my/path/BakeTag.php';
  965. $this->Task->expects($this->at(4))->method('createFile')
  966. ->with($filename, $this->logicalNot($this->stringContains('public $primaryKey')));
  967. $filename = '/my/path/CategoryThread.php';
  968. $this->Task->expects($this->at(5))->method('createFile')
  969. ->with($filename, $this->stringContains('class CategoryThread'));
  970. $this->Task->execute();
  971. $this->assertEquals(count(ClassRegistry::keys()), 0);
  972. $this->assertEquals(count(ClassRegistry::mapKeys()), 0);
  973. }
  974. /**
  975. * test that odd tablenames aren't inflected back from modelname
  976. *
  977. * @return void
  978. */
  979. public function testExecuteIntoAllOddTables() {
  980. $this->markTestIncomplete('Not done here yet');
  981. $out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false);
  982. $in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
  983. $this->Task = $this->getMock('Cake\Console\Command\Task\ModelTask',
  984. array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'bake', 'bakeFixture'),
  985. array($out, $out, $in)
  986. );
  987. $this->_setupOtherMocks();
  988. $this->Task->connection = 'test';
  989. $this->Task->path = '/my/path/';
  990. $this->Task->args = array('all');
  991. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  992. $this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('bake_odd')));
  993. $object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
  994. $this->Task->expects($this->once())->method('_getModelObject')->with('BakeOdd', 'bake_odd')->will($this->returnValue($object));
  995. $this->Task->expects($this->at(3))->method('bake')->with($object, false)->will($this->returnValue(true));
  996. $this->Task->expects($this->once())->method('bakeFixture')->with('BakeOdd', 'bake_odd');
  997. $this->Task->execute();
  998. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  999. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  1000. $this->Task = $this->getMock('ModelTask',
  1001. array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'doActsAs', 'createFile'),
  1002. array($out, $out, $in)
  1003. );
  1004. $this->_setupOtherMocks();
  1005. $this->Task->connection = 'test';
  1006. $this->Task->path = '/my/path/';
  1007. $this->Task->args = array('all');
  1008. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  1009. $this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('bake_odd')));
  1010. $object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
  1011. $this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object));
  1012. $this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array()));
  1013. $this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array()));
  1014. $this->Task->expects($this->once())->method('doActsAs')->will($this->returnValue(array()));
  1015. $filename = '/my/path/BakeOdd.php';
  1016. $this->Task->expects($this->once())->method('createFile')
  1017. ->with($filename, $this->stringContains('class BakeOdd'));
  1018. $filename = '/my/path/BakeOdd.php';
  1019. $this->Task->expects($this->once())->method('createFile')
  1020. ->with($filename, $this->stringContains('public $useTable = \'bake_odd\''));
  1021. $this->Task->execute();
  1022. }
  1023. /**
  1024. * test that odd tablenames aren't inflected back from modelname
  1025. *
  1026. * @return void
  1027. */
  1028. public function testExecuteIntoBakeOddTables() {
  1029. $this->markTestIncomplete('Not done here yet');
  1030. $out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false);
  1031. $in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
  1032. $this->Task = $this->getMock('Cake\Console\Command\Task\ModelTask',
  1033. array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'bake', 'bakeFixture'),
  1034. array($out, $out, $in)
  1035. );
  1036. $this->_setupOtherMocks();
  1037. $this->Task->connection = 'test';
  1038. $this->Task->path = '/my/path/';
  1039. $this->Task->args = array('BakeOdd');
  1040. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  1041. $this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
  1042. $object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
  1043. $this->Task->expects($this->once())->method('_getModelObject')->with('BakeOdd', 'bake_odd')->will($this->returnValue($object));
  1044. $this->Task->expects($this->once())->method('bake')->with($object, false)->will($this->returnValue(true));
  1045. $this->Task->expects($this->once())->method('bakeFixture')->with('BakeOdd', 'bake_odd');
  1046. $this->Task->execute();
  1047. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  1048. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  1049. $this->Task = $this->getMock('ModelTask',
  1050. array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'doActsAs', 'createFile'),
  1051. array($out, $out, $in)
  1052. );
  1053. $this->_setupOtherMocks();
  1054. $this->Task->connection = 'test';
  1055. $this->Task->path = '/my/path/';
  1056. $this->Task->args = array('BakeOdd');
  1057. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  1058. $this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
  1059. $object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
  1060. $this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object));
  1061. $this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array()));
  1062. $this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array()));
  1063. $this->Task->expects($this->once())->method('doActsAs')->will($this->returnValue(array()));
  1064. $filename = '/my/path/BakeOdd.php';
  1065. $this->Task->expects($this->once())->method('createFile')
  1066. ->with($filename, $this->stringContains('class BakeOdd'));
  1067. $filename = '/my/path/BakeOdd.php';
  1068. $this->Task->expects($this->once())->method('createFile')
  1069. ->with($filename, $this->stringContains('public $useTable = \'bake_odd\''));
  1070. $this->Task->execute();
  1071. }
  1072. /**
  1073. * test that skipTables changes how all() works.
  1074. *
  1075. * @return void
  1076. */
  1077. public function testSkipTablesAndAll() {
  1078. $this->markTestIncomplete('Not done here yet');
  1079. $count = count($this->Task->listAll('test'));
  1080. if ($count != count($this->fixtures)) {
  1081. $this->markTestSkipped('Additional tables detected.');
  1082. }
  1083. $this->Task->connection = 'test';
  1084. $this->Task->path = '/my/path/';
  1085. $this->Task->args = array('all');
  1086. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  1087. $this->Task->skipTables = array('bake_tags');
  1088. $this->Task->Fixture->expects($this->exactly(4))->method('bake');
  1089. $this->Task->Test->expects($this->exactly(4))->method('bake');
  1090. $filename = '/my/path/BakeArticle.php';
  1091. $this->Task->expects($this->at(1))->method('createFile')
  1092. ->with($filename, $this->stringContains('class BakeArticle'));
  1093. $filename = '/my/path/BakeArticlesBakeTag.php';
  1094. $this->Task->expects($this->at(2))->method('createFile')
  1095. ->with($filename, $this->stringContains('class BakeArticlesBakeTag'));
  1096. $filename = '/my/path/BakeComment.php';
  1097. $this->Task->expects($this->at(3))->method('createFile')
  1098. ->with($filename, $this->stringContains('class BakeComment'));
  1099. $filename = '/my/path/CategoryThread.php';
  1100. $this->Task->expects($this->at(4))->method('createFile')
  1101. ->with($filename, $this->stringContains('class CategoryThread'));
  1102. $this->Task->execute();
  1103. }
  1104. /**
  1105. * test the interactive side of bake.
  1106. *
  1107. * @return void
  1108. */
  1109. public function testExecuteIntoInteractive() {
  1110. $this->markTestIncomplete('Not done here yet');
  1111. $tables = $this->Task->listAll('test');
  1112. $article = array_search('bake_articles', $tables) + 1;
  1113. $this->Task->connection = 'test';
  1114. $this->Task->path = '/my/path/';
  1115. $this->Task->interactive = true;
  1116. $this->Task->expects($this->any())->method('in')
  1117. ->will($this->onConsecutiveCalls(
  1118. $article, // article
  1119. 'n', // no validation
  1120. 'y', // associations
  1121. 'y', // comment relation
  1122. 'y', // user relation
  1123. 'y', // tag relation
  1124. 'n', // additional assocs
  1125. 'y' // looks good?
  1126. ));
  1127. $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
  1128. $this->Task->Test->expects($this->once())->method('bake');
  1129. $this->Task->Fixture->expects($this->once())->method('bake');
  1130. $filename = '/my/path/BakeArticle.php';
  1131. $this->Task->expects($this->once())->method('createFile')
  1132. ->with($filename, $this->stringContains('class BakeArticle'));
  1133. $this->Task->execute();
  1134. $this->assertEquals(count(ClassRegistry::keys()), 0);
  1135. $this->assertEquals(count(ClassRegistry::mapKeys()), 0);
  1136. }
  1137. /**
  1138. * test using bake interactively with a table that does not exist.
  1139. *
  1140. * @return void
  1141. */
  1142. public function testExecuteWithNonExistantTableName() {
  1143. $this->markTestIncomplete('Not done here yet');
  1144. $this->Task->connection = 'test';
  1145. $this->Task->path = '/my/path/';
  1146. $this->Task->expects($this->any())->method('in')
  1147. ->will($this->onConsecutiveCalls(
  1148. 'Foobar', // Or type in the name of the model
  1149. 'y', // Do you want to use this table
  1150. 'n' // Doesn't exist, continue anyway?
  1151. ));
  1152. $this->Task->execute();
  1153. }
  1154. /**
  1155. * test using bake interactively with a table that does not exist.
  1156. *
  1157. * @return void
  1158. */
  1159. public function testForcedExecuteWithNonExistantTableName() {
  1160. $this->markTestIncomplete('Not done here yet');
  1161. $this->Task->connection = 'test';
  1162. $this->Task->path = '/my/path/';
  1163. $this->Task->expects($this->any())->method('in')
  1164. ->will($this->onConsecutiveCalls(
  1165. 'Foobar', // Or type in the name of the model
  1166. 'y', // Do you want to use this table
  1167. 'y', // Doesn't exist, continue anyway?
  1168. 'id', // Primary key
  1169. 'y' // Looks good?
  1170. ));
  1171. $this->Task->execute();
  1172. }
  1173. }