PageRenderTime 45ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/tests/cases/console/libs/tasks/model.test.php

https://github.com/msadouni/cakephp2x
PHP | 773 lines | 512 code | 72 blank | 189 comment | 2 complexity | 952d9fc024357f7974b2db06186944a7 MD5 | raw file
  1. <?php
  2. /**
  3. * ModelTaskTest file
  4. *
  5. * Test Case for test generation shell task
  6. *
  7. * PHP Version 5.x
  8. *
  9. * CakePHP : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2006-2009, Cake Software Foundation, Inc.
  11. *
  12. * Licensed under The MIT License
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright 2006-2009, Cake Software Foundation, Inc.
  16. * @link http://cakephp.org CakePHP Project
  17. * @package cake
  18. * @subpackage cake.tests.cases.console.libs.tasks
  19. * @since CakePHP v 1.2.6
  20. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  21. */
  22. App::import('Shell', 'Shell', false);
  23. if (!defined('DISABLE_AUTO_DISPATCH')) {
  24. define('DISABLE_AUTO_DISPATCH', true);
  25. }
  26. if (!class_exists('ShellDispatcher')) {
  27. ob_start();
  28. $argv = false;
  29. require CAKE . 'console' . DS . 'cake.php';
  30. ob_end_clean();
  31. }
  32. require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
  33. require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
  34. require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
  35. Mock::generatePartial(
  36. 'ShellDispatcher', 'TestModelTaskMockShellDispatcher',
  37. array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  38. );
  39. Mock::generatePartial(
  40. 'ModelTask', 'MockModelTask',
  41. array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
  42. );
  43. Mock::generate(
  44. 'Model', 'MockModelTaskModel'
  45. );
  46. Mock::generate(
  47. 'FixtureTask', 'MockModelTaskFixtureTask'
  48. );
  49. /**
  50. * ModelTaskTest class
  51. *
  52. * @package cake
  53. * @subpackage cake.tests.cases.console.libs.tasks
  54. */
  55. class ModelTaskTest extends CakeTestCase {
  56. /**
  57. * fixtures
  58. *
  59. * @var array
  60. */
  61. public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag', 'core.category_thread');
  62. /**
  63. * starTest method
  64. *
  65. * @return void
  66. * @access public
  67. */
  68. public function startTest() {
  69. $this->Dispatcher =& new TestModelTaskMockShellDispatcher();
  70. $this->Task =& new MockModelTask($this->Dispatcher);
  71. $this->Task->Dispatch =& $this->Dispatcher;
  72. $this->Task->Dispatch->shellPaths = App::path('shells');
  73. $this->Task->Template =& new TemplateTask($this->Task->Dispatch);
  74. $this->Task->Fixture =& new MockModelTaskFixtureTask();
  75. $this->Task->Test =& new MockModelTaskFixtureTask();
  76. }
  77. /**
  78. * endTest method
  79. *
  80. * @return void
  81. * @access public
  82. */
  83. public function endTest() {
  84. unset($this->Task, $this->Dispatcher);
  85. ClassRegistry::flush();
  86. }
  87. /**
  88. * Test that listAll scans the database connection and lists all the tables in it.s
  89. *
  90. * @return void
  91. * @access public
  92. */
  93. public function testListAll() {
  94. $this->Task->expectAt(1, 'out', array('1. Article'));
  95. $this->Task->expectAt(2, 'out', array('2. ArticlesTag'));
  96. $this->Task->expectAt(3, 'out', array('3. CategoryThread'));
  97. $this->Task->expectAt(4, 'out', array('4. Comment'));
  98. $this->Task->expectAt(5, 'out', array('5. Tag'));
  99. $result = $this->Task->listAll('test_suite');
  100. $expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
  101. $this->assertEqual($result, $expected);
  102. $this->Task->expectAt(7, 'out', array('1. Article'));
  103. $this->Task->expectAt(8, 'out', array('2. ArticlesTag'));
  104. $this->Task->expectAt(9, 'out', array('3. CategoryThread'));
  105. $this->Task->expectAt(10, 'out', array('4. Comment'));
  106. $this->Task->expectAt(11, 'out', array('5. Tag'));
  107. $this->Task->connection = 'test_suite';
  108. $result = $this->Task->listAll();
  109. $expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
  110. $this->assertEqual($result, $expected);
  111. }
  112. /**
  113. * Test that getName interacts with the user and returns the model name.
  114. *
  115. * @return void
  116. * @access public
  117. */
  118. public function testGetName() {
  119. $this->Task->setReturnValue('in', 1);
  120. $this->Task->setReturnValueAt(0, 'in', 'q');
  121. $this->Task->expectOnce('_stop');
  122. $this->Task->getName('test_suite');
  123. $this->Task->setReturnValueAt(1, 'in', 1);
  124. $result = $this->Task->getName('test_suite');
  125. $expected = 'Article';
  126. $this->assertEqual($result, $expected);
  127. $this->Task->setReturnValueAt(2, 'in', 4);
  128. $result = $this->Task->getName('test_suite');
  129. $expected = 'Comment';
  130. $this->assertEqual($result, $expected);
  131. $this->Task->setReturnValueAt(3, 'in', 10);
  132. $result = $this->Task->getName('test_suite');
  133. $this->Task->expectOnce('err');
  134. }
  135. /**
  136. * Test table name interactions
  137. *
  138. * @return void
  139. * @access public
  140. */
  141. public function testGetTableName() {
  142. $this->Task->setReturnValueAt(0, 'in', 'y');
  143. $result = $this->Task->getTable('Article', 'test_suite');
  144. $expected = 'articles';
  145. $this->assertEqual($result, $expected);
  146. $this->Task->setReturnValueAt(1, 'in', 'n');
  147. $this->Task->setReturnValueAt(2, 'in', 'my_table');
  148. $result = $this->Task->getTable('Article', 'test_suite');
  149. $expected = 'my_table';
  150. $this->assertEqual($result, $expected);
  151. }
  152. /**
  153. * test that initializing the validations works.
  154. *
  155. * @return void
  156. * @access public
  157. */
  158. public function testInitValidations() {
  159. $result = $this->Task->initValidations();
  160. $this->assertTrue(in_array('notempty', $result));
  161. }
  162. /**
  163. * test that individual field validation works, with interactive = false
  164. * tests the guessing features of validation
  165. *
  166. * @return void
  167. * @access public
  168. */
  169. public function testFieldValidationGuessing() {
  170. $this->Task->interactive = false;
  171. $this->Task->initValidations();
  172. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  173. $expected = array('notempty' => 'notempty');
  174. $result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false));
  175. $expected = array('date' => 'date');
  176. $result = $this->Task->fieldValidation('text', array('type' => 'time', 'length' => 10, 'null' => false));
  177. $expected = array('time' => 'time');
  178. $result = $this->Task->fieldValidation('email', array('type' => 'string', 'length' => 10, 'null' => false));
  179. $expected = array('email' => 'email');
  180. $result = $this->Task->fieldValidation('test', array('type' => 'integer', 'length' => 10, 'null' => false));
  181. $expected = array('numeric' => 'numeric');
  182. $result = $this->Task->fieldValidation('test', array('type' => 'boolean', 'length' => 10, 'null' => false));
  183. $expected = array('numeric' => 'numeric');
  184. }
  185. /**
  186. * test that interactive field validation works and returns multiple validators.
  187. *
  188. * @return void
  189. * @access public
  190. */
  191. public function testInteractiveFieldValidation() {
  192. $this->Task->initValidations();
  193. $this->Task->interactive = true;
  194. $this->Task->setReturnValueAt(0, 'in', '20');
  195. $this->Task->setReturnValueAt(1, 'in', 'y');
  196. $this->Task->setReturnValueAt(2, 'in', '16');
  197. $this->Task->setReturnValueAt(3, 'in', 'n');
  198. $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
  199. $expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength');
  200. $this->assertEqual($result, $expected);
  201. }
  202. /**
  203. * test the validation Generation routine
  204. *
  205. * @return void
  206. * @access public
  207. */
  208. public function testNonInteractiveDoValidation() {
  209. $Model =& new MockModelTaskModel();
  210. $Model->primaryKey = 'id';
  211. $Model->setReturnValue('schema', array(
  212. 'id' => array(
  213. 'type' => 'integer',
  214. 'length' => 11,
  215. 'null' => false,
  216. 'key' => 'primary',
  217. ),
  218. 'name' => array(
  219. 'type' => 'string',
  220. 'length' => 20,
  221. 'null' => false,
  222. ),
  223. 'email' => array(
  224. 'type' => 'string',
  225. 'length' => 255,
  226. 'null' => false,
  227. ),
  228. 'some_date' => array(
  229. 'type' => 'date',
  230. 'length' => '',
  231. 'null' => false,
  232. ),
  233. 'some_time' => array(
  234. 'type' => 'time',
  235. 'length' => '',
  236. 'null' => false,
  237. ),
  238. 'created' => array(
  239. 'type' => 'datetime',
  240. 'length' => '',
  241. 'null' => false,
  242. )
  243. ));
  244. $this->Task->interactive = false;
  245. $result = $this->Task->doValidation($Model);
  246. $expected = array(
  247. 'name' => array(
  248. 'notempty' => 'notempty'
  249. ),
  250. 'email' => array(
  251. 'email' => 'email',
  252. ),
  253. 'some_date' => array(
  254. 'date' => 'date'
  255. ),
  256. 'some_time' => array(
  257. 'time' => 'time'
  258. ),
  259. );
  260. $this->assertEqual($result, $expected);
  261. }
  262. /**
  263. * test that finding primary key works
  264. *
  265. * @return void
  266. * @access public
  267. */
  268. public function testFindPrimaryKey() {
  269. $fields = array(
  270. 'one' => array(),
  271. 'two' => array(),
  272. 'key' => array('key' => 'primary')
  273. );
  274. $this->Task->expectAt(0, 'in', array('*', null, 'key'));
  275. $this->Task->setReturnValue('in', 'my_field');
  276. $result = $this->Task->findPrimaryKey($fields);
  277. $expected = 'my_field';
  278. $this->assertEqual($result, $expected);
  279. }
  280. /**
  281. * test finding Display field
  282. *
  283. * @return void
  284. * @access public
  285. */
  286. public function testFindDisplayField() {
  287. $fields = array('id' => array(), 'tagname' => array(), 'body' => array(),
  288. 'created' => array(), 'modified' => array());
  289. $this->Task->setReturnValue('in', 'n');
  290. $this->Task->setReturnValueAt(0, 'in', 'n');
  291. $result = $this->Task->findDisplayField($fields);
  292. $this->assertFalse($result);
  293. $this->Task->setReturnValueAt(1, 'in', 'y');
  294. $this->Task->setReturnValueAt(2, 'in', 2);
  295. $result = $this->Task->findDisplayField($fields);
  296. $this->assertEqual($result, 'tagname');
  297. }
  298. /**
  299. * test that belongsTo generation works.
  300. *
  301. * @return void
  302. * @access public
  303. */
  304. public function testBelongsToGeneration() {
  305. $model = new Model(array('ds' => 'test_suite', 'name' => 'Comment'));
  306. $result = $this->Task->findBelongsTo($model, array());
  307. $expected = array(
  308. 'belongsTo' => array(
  309. array(
  310. 'alias' => 'Article',
  311. 'className' => 'Article',
  312. 'foreignKey' => 'article_id',
  313. ),
  314. array(
  315. 'alias' => 'User',
  316. 'className' => 'User',
  317. 'foreignKey' => 'user_id',
  318. ),
  319. )
  320. );
  321. $this->assertEqual($result, $expected);
  322. $model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
  323. $result = $this->Task->findBelongsTo($model, array());
  324. $expected = array(
  325. 'belongsTo' => array(
  326. array(
  327. 'alias' => 'ParentCategoryThread',
  328. 'className' => 'CategoryThread',
  329. 'foreignKey' => 'parent_id',
  330. ),
  331. )
  332. );
  333. $this->assertEqual($result, $expected);
  334. }
  335. /**
  336. * test that hasOne and/or hasMany relations are generated properly.
  337. *
  338. * @return void
  339. * @access public
  340. */
  341. public function testHasManyHasOneGeneration() {
  342. $model = new Model(array('ds' => 'test_suite', 'name' => 'Article'));
  343. $this->Task->connection = 'test_suite';
  344. $this->Task->listAll();
  345. $result = $this->Task->findHasOneAndMany($model, array());
  346. $expected = array(
  347. 'hasMany' => array(
  348. array(
  349. 'alias' => 'Comment',
  350. 'className' => 'Comment',
  351. 'foreignKey' => 'article_id',
  352. ),
  353. ),
  354. 'hasOne' => array(
  355. array(
  356. 'alias' => 'Comment',
  357. 'className' => 'Comment',
  358. 'foreignKey' => 'article_id',
  359. ),
  360. ),
  361. );
  362. $this->assertEqual($result, $expected);
  363. $model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
  364. $result = $this->Task->findHasOneAndMany($model, array());
  365. $expected = array(
  366. 'hasOne' => array(
  367. array(
  368. 'alias' => 'ChildCategoryThread',
  369. 'className' => 'CategoryThread',
  370. 'foreignKey' => 'parent_id',
  371. ),
  372. ),
  373. 'hasMany' => array(
  374. array(
  375. 'alias' => 'ChildCategoryThread',
  376. 'className' => 'CategoryThread',
  377. 'foreignKey' => 'parent_id',
  378. ),
  379. )
  380. );
  381. $this->assertEqual($result, $expected);
  382. }
  383. /**
  384. * Test that HABTM generation works
  385. *
  386. * @return void
  387. * @access public
  388. */
  389. public function testHasAndBelongsToManyGeneration() {
  390. $model = new Model(array('ds' => 'test_suite', 'name' => 'Article'));
  391. $this->Task->connection = 'test_suite';
  392. $this->Task->listAll();
  393. $result = $this->Task->findHasAndBelongsToMany($model, array());
  394. $expected = array(
  395. 'hasAndBelongsToMany' => array(
  396. array(
  397. 'alias' => 'Tag',
  398. 'className' => 'Tag',
  399. 'foreignKey' => 'article_id',
  400. 'joinTable' => 'articles_tags',
  401. 'associationForeignKey' => 'tag_id',
  402. ),
  403. ),
  404. );
  405. $this->assertEqual($result, $expected);
  406. }
  407. /**
  408. * test non interactive doAssociations
  409. *
  410. * @return void
  411. * @access public
  412. */
  413. public function testDoAssociationsNonInteractive() {
  414. $this->Task->connection = 'test_suite';
  415. $this->Task->interactive = false;
  416. $model = new Model(array('ds' => 'test_suite', 'name' => 'Article'));
  417. $result = $this->Task->doAssociations($model);
  418. $expected = array(
  419. 'hasMany' => array(
  420. array(
  421. 'alias' => 'Comment',
  422. 'className' => 'Comment',
  423. 'foreignKey' => 'article_id',
  424. ),
  425. ),
  426. 'hasAndBelongsToMany' => array(
  427. array(
  428. 'alias' => 'Tag',
  429. 'className' => 'Tag',
  430. 'foreignKey' => 'article_id',
  431. 'joinTable' => 'articles_tags',
  432. 'associationForeignKey' => 'tag_id',
  433. ),
  434. ),
  435. );
  436. }
  437. /**
  438. * Ensure that the fixutre object is correctly called.
  439. *
  440. * @return void
  441. * @access public
  442. */
  443. public function testBakeFixture() {
  444. $this->Task->Fixture->expectAt(0, 'bake', array('Article', 'articles'));
  445. $this->Task->bakeFixture('Article', 'articles');
  446. $this->assertEqual($this->Task->plugin, $this->Task->Fixture->plugin);
  447. $this->assertEqual($this->Task->connection, $this->Task->Fixture->connection);
  448. }
  449. /**
  450. * Ensure that the test object is correctly called.
  451. *
  452. * @return void
  453. * @access public
  454. */
  455. public function testBakeTest() {
  456. $this->Task->Test->expectAt(0, 'bake', array('Model', 'Article'));
  457. $this->Task->bakeTest('Article');
  458. $this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
  459. $this->assertEqual($this->Task->connection, $this->Task->Test->connection);
  460. }
  461. /**
  462. * test confirming of associations, and that when an association is hasMany
  463. * a question for the hasOne is also not asked.
  464. *
  465. * @return void
  466. * @access public
  467. */
  468. public function testConfirmAssociations() {
  469. $associations = array(
  470. 'hasOne' => array(
  471. array(
  472. 'alias' => 'ChildCategoryThread',
  473. 'className' => 'CategoryThread',
  474. 'foreignKey' => 'parent_id',
  475. ),
  476. ),
  477. 'hasMany' => array(
  478. array(
  479. 'alias' => 'ChildCategoryThread',
  480. 'className' => 'CategoryThread',
  481. 'foreignKey' => 'parent_id',
  482. ),
  483. ),
  484. 'belongsTo' => array(
  485. array(
  486. 'alias' => 'User',
  487. 'className' => 'User',
  488. 'foreignKey' => 'user_id',
  489. ),
  490. )
  491. );
  492. $model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
  493. $this->Task->setReturnValueAt(0, 'in', 'y');
  494. $result = $this->Task->confirmAssociations($model, $associations);
  495. $this->assertTrue(empty($result['hasOne']));
  496. $this->Task->setReturnValue('in', 'n');
  497. $result = $this->Task->confirmAssociations($model, $associations);
  498. $this->assertTrue(empty($result['hasMany']));
  499. $this->assertTrue(empty($result['hasOne']));
  500. }
  501. /**
  502. * test that inOptions generates questions and only accepts a valid answer
  503. *
  504. * @return void
  505. * @access public
  506. */
  507. public function testInOptions() {
  508. $options = array('one', 'two', 'three');
  509. $this->Task->expectAt(0, 'out', array('1. one'));
  510. $this->Task->expectAt(1, 'out', array('2. two'));
  511. $this->Task->expectAt(2, 'out', array('3. three'));
  512. $this->Task->setReturnValueAt(0, 'in', 10);
  513. $this->Task->expectAt(3, 'out', array('1. one'));
  514. $this->Task->expectAt(4, 'out', array('2. two'));
  515. $this->Task->expectAt(5, 'out', array('3. three'));
  516. $this->Task->setReturnValueAt(1, 'in', 2);
  517. $result = $this->Task->inOptions($options, 'Pick a number');
  518. $this->assertEqual($result, 1);
  519. }
  520. /**
  521. * test baking validation
  522. *
  523. * @return void
  524. * @access public
  525. */
  526. public function testBakeValidation() {
  527. $validate = array(
  528. 'name' => array(
  529. 'notempty' => 'notempty'
  530. ),
  531. 'email' => array(
  532. 'email' => 'email',
  533. ),
  534. 'some_date' => array(
  535. 'date' => 'date'
  536. ),
  537. 'some_time' => array(
  538. 'time' => 'time'
  539. )
  540. );
  541. $result = $this->Task->bake('Article', compact('validate'));
  542. $this->assertPattern('/class Article extends AppModel \{/', $result);
  543. $this->assertPattern('/\$name \= \'Article\'/', $result);
  544. $this->assertPattern('/\$validate \= array\(/', $result);
  545. $pattern = '/' . preg_quote("'notempty' => array('rule' => array('notempty')),", '/') . '/';
  546. $this->assertPattern($pattern, $result);
  547. }
  548. /**
  549. * test baking relations
  550. *
  551. * @return void
  552. * @access public
  553. */
  554. public function testBakeRelations() {
  555. $associations = array(
  556. 'belongsTo' => array(
  557. array(
  558. 'alias' => 'SomethingElse',
  559. 'className' => 'SomethingElse',
  560. 'foreignKey' => 'something_else_id',
  561. ),
  562. array(
  563. 'alias' => 'User',
  564. 'className' => 'User',
  565. 'foreignKey' => 'user_id',
  566. ),
  567. ),
  568. 'hasOne' => array(
  569. array(
  570. 'alias' => 'OtherModel',
  571. 'className' => 'OtherModel',
  572. 'foreignKey' => 'other_model_id',
  573. ),
  574. ),
  575. 'hasMany' => array(
  576. array(
  577. 'alias' => 'Comment',
  578. 'className' => 'Comment',
  579. 'foreignKey' => 'parent_id',
  580. ),
  581. ),
  582. 'hasAndBelongsToMany' => array(
  583. array(
  584. 'alias' => 'Tag',
  585. 'className' => 'Tag',
  586. 'foreignKey' => 'article_id',
  587. 'joinTable' => 'articles_tags',
  588. 'associationForeignKey' => 'tag_id',
  589. ),
  590. )
  591. );
  592. $result = $this->Task->bake('Article', compact('associations'));
  593. $this->assertPattern('/\$hasAndBelongsToMany \= array\(/', $result);
  594. $this->assertPattern('/\$hasMany \= array\(/', $result);
  595. $this->assertPattern('/\$belongsTo \= array\(/', $result);
  596. $this->assertPattern('/\$hasOne \= array\(/', $result);
  597. $this->assertPattern('/Tag/', $result);
  598. $this->assertPattern('/OtherModel/', $result);
  599. $this->assertPattern('/SomethingElse/', $result);
  600. $this->assertPattern('/Comment/', $result);
  601. }
  602. /**
  603. * test bake() with a -plugin param
  604. *
  605. * @return void
  606. * @access public
  607. */
  608. public function testBakeWithPlugin() {
  609. $this->Task->plugin = 'ControllerTest';
  610. $path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
  611. $this->Task->expectAt(0, 'createFile', array($path, '*'));
  612. $this->Task->bake('Article', array(), array());
  613. $this->Task->plugin = 'controllerTest';
  614. $path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
  615. $this->Task->expectAt(1, 'createFile', array(
  616. $path, new PatternExpectation('/Article extends ControllerTestAppModel/')));
  617. $this->Task->bake('Article', array(), array());
  618. }
  619. /**
  620. * test that execute passes runs bake depending with named model.
  621. *
  622. * @return void
  623. * @access public
  624. */
  625. public function testExecuteWithNamedModel() {
  626. $this->Task->connection = 'test_suite';
  627. $this->Task->path = '/my/path/';
  628. $this->Task->args = array('article');
  629. $filename = '/my/path/article.php';
  630. $this->Task->setReturnValue('_checkUnitTest', 1);
  631. $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
  632. $this->Task->execute();
  633. }
  634. /**
  635. * test that execute runs all() when args[0] = all
  636. *
  637. * @return void
  638. * @access public
  639. */
  640. public function testExecuteIntoAll() {
  641. $this->Task->connection = 'test_suite';
  642. $this->Task->path = '/my/path/';
  643. $this->Task->args = array('all');
  644. $this->Task->setReturnValue('_checkUnitTest', true);
  645. $this->Task->Fixture->expectCallCount('bake', 5);
  646. $this->Task->Test->expectCallCount('bake', 5);
  647. $filename = '/my/path/article.php';
  648. $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
  649. $filename = '/my/path/articles_tag.php';
  650. $this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticlesTag/')));
  651. $filename = '/my/path/category_thread.php';
  652. $this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class CategoryThread/')));
  653. $filename = '/my/path/comment.php';
  654. $this->Task->expectAt(3, 'createFile', array($filename, new PatternExpectation('/class Comment/')));
  655. $filename = '/my/path/tag.php';
  656. $this->Task->expectAt(4, 'createFile', array($filename, new PatternExpectation('/class Tag/')));
  657. $this->Task->execute();
  658. }
  659. /**
  660. * test the interactive side of bake.
  661. *
  662. * @return void
  663. * @access public
  664. */
  665. public function testExecuteIntoInteractive() {
  666. $this->Task->connection = 'test_suite';
  667. $this->Task->path = '/my/path/';
  668. $this->Task->interactive = true;
  669. $this->Task->setReturnValueAt(0, 'in', '1'); //choose article
  670. $this->Task->setReturnValueAt(1, 'in', 'n'); //no validation
  671. $this->Task->setReturnValueAt(2, 'in', 'y'); //yes to associations
  672. $this->Task->setReturnValueAt(3, 'in', 'y'); //yes to comment relation
  673. $this->Task->setReturnValueAt(4, 'in', 'y'); //yes to user relation
  674. $this->Task->setReturnValueAt(5, 'in', 'y'); //yes to tag relation
  675. $this->Task->setReturnValueAt(6, 'in', 'n'); //no to additional assocs
  676. $this->Task->setReturnValueAt(7, 'in', 'y'); //yes to looksGood?
  677. $this->Task->setReturnValue('_checkUnitTest', true);
  678. $this->Task->Test->expectOnce('bake');
  679. $this->Task->Fixture->expectOnce('bake');
  680. $filename = '/my/path/article.php';
  681. $this->Task->expectOnce('createFile');
  682. $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
  683. $this->Task->execute();
  684. }
  685. /**
  686. * test using bake interactively with a table that does not exist.
  687. *
  688. * @return void
  689. * @access public
  690. */
  691. public function testExecuteWithNonExistantTableName() {
  692. $this->Task->connection = 'test_suite';
  693. $this->Task->path = '/my/path/';
  694. $this->Task->expectOnce('_stop');
  695. $this->Task->expectOnce('err');
  696. $this->Task->setReturnValueAt(0, 'in', 'Foobar');
  697. $this->Task->setReturnValueAt(1, 'in', 'y');
  698. $this->Task->execute();
  699. }
  700. }
  701. ?>