ModelTaskTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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. class ModelTaskTest extends TestCase {
  28. /**
  29. * fixtures
  30. *
  31. * @var array
  32. */
  33. public $fixtures = array(
  34. 'core.bake_article', 'core.bake_comment', 'core.bake_articles_bake_tag',
  35. 'core.bake_tag', 'core.category_thread', 'core.number_tree'
  36. );
  37. /**
  38. * setUp method
  39. *
  40. * @return void
  41. */
  42. public function setUp() {
  43. parent::setUp();
  44. $out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
  45. $in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);
  46. $this->Task = $this->getMock('Cake\Console\Command\Task\ModelTask',
  47. array('in', 'err', 'createFile', '_stop', '_checkUnitTest'),
  48. array($out, $out, $in)
  49. );
  50. $this->Task->connection = 'test';
  51. $this->_setupOtherMocks();
  52. }
  53. /**
  54. * Setup a mock that has out mocked. Normally this is not used as it makes $this->at() really tricky.
  55. *
  56. * @return void
  57. */
  58. protected function _useMockedOut() {
  59. $out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
  60. $in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);
  61. $this->Task = $this->getMock('Cake\Console\Command\Task\ModelTask',
  62. array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
  63. array($out, $out, $in)
  64. );
  65. $this->_setupOtherMocks();
  66. }
  67. /**
  68. * sets up the rest of the dependencies for Model Task
  69. *
  70. * @return void
  71. */
  72. protected function _setupOtherMocks() {
  73. $out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
  74. $in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);
  75. $this->Task->Fixture = $this->getMock('Cake\Console\Command\Task\FixtureTask', [], [$out, $out, $in]);
  76. $this->Task->Test = $this->getMock('Cake\Console\Command\Task\FixtureTask', [], [$out, $out, $in]);
  77. $this->Task->Template = new TemplateTask($out, $out, $in);
  78. $this->Task->name = 'Model';
  79. }
  80. /**
  81. * tearDown method
  82. *
  83. * @return void
  84. */
  85. public function tearDown() {
  86. parent::tearDown();
  87. unset($this->Task);
  88. }
  89. /**
  90. * Test that listAll uses the connection property
  91. *
  92. * @return void
  93. */
  94. public function testListAllConnection() {
  95. $this->_useMockedOut();
  96. $this->Task->connection = 'test';
  97. $result = $this->Task->listAll();
  98. $this->assertContains('bake_articles', $result);
  99. $this->assertContains('bake_articles_bake_tags', $result);
  100. $this->assertContains('bake_tags', $result);
  101. $this->assertContains('bake_comments', $result);
  102. $this->assertContains('category_threads', $result);
  103. }
  104. /**
  105. * Test getName() method.
  106. *
  107. * @return void
  108. */
  109. public function testGetTable() {
  110. $result = $this->Task->getTable('BakeArticle');
  111. $this->assertEquals('bake_articles', $result);
  112. $result = $this->Task->getTable('BakeArticles');
  113. $this->assertEquals('bake_articles', $result);
  114. $this->Task->params['table'] = 'bake_articles';
  115. $result = $this->Task->getTable('Article');
  116. $this->assertEquals('bake_articles', $result);
  117. }
  118. /**
  119. * Test getting the a table class.
  120. *
  121. * @return void
  122. */
  123. public function testGetTableObject() {
  124. $result = $this->Task->getTableObject('Article', 'bake_articles');
  125. $this->assertInstanceOf('Cake\ORM\Table', $result);
  126. $this->assertEquals('bake_articles', $result->table());
  127. $this->assertEquals('Article', $result->alias());
  128. }
  129. /**
  130. * Test getAssociations with off flag.
  131. *
  132. * @return void
  133. */
  134. public function testGetAssociationsNoFlag() {
  135. $this->Task->params['no-associations'] = true;
  136. $articles = TableRegistry::get('BakeArticle');
  137. $this->assertEquals([], $this->Task->getAssociations($articles));
  138. }
  139. /**
  140. * Test getAssociations
  141. *
  142. * @return void
  143. */
  144. public function testGetAssociations() {
  145. $articles = TableRegistry::get('BakeArticles');
  146. $result = $this->Task->getAssociations($articles);
  147. $expected = [
  148. 'belongsTo' => [
  149. [
  150. 'alias' => 'BakeUsers',
  151. 'className' => 'BakeUsers',
  152. 'foreignKey' => 'bake_user_id',
  153. ],
  154. ],
  155. 'hasMany' => [
  156. [
  157. 'alias' => 'BakeComments',
  158. 'className' => 'BakeComments',
  159. 'foreignKey' => 'bake_article_id',
  160. ],
  161. ],
  162. 'belongsToMany' => [
  163. [
  164. 'alias' => 'BakeTags',
  165. 'className' => 'BakeTags',
  166. 'foreignKey' => 'bake_article_id',
  167. 'joinTable' => 'bake_articles_bake_tags',
  168. 'targetForeignKey' => 'bake_tag_id',
  169. ],
  170. ],
  171. ];
  172. $this->assertEquals($expected, $result);
  173. }
  174. /**
  175. * test that belongsTo generation works.
  176. *
  177. * @return void
  178. */
  179. public function testBelongsToGeneration() {
  180. $model = TableRegistry::get('BakeComments');
  181. $result = $this->Task->findBelongsTo($model, []);
  182. $expected = [
  183. 'belongsTo' => [
  184. [
  185. 'alias' => 'BakeArticles',
  186. 'className' => 'BakeArticles',
  187. 'foreignKey' => 'bake_article_id',
  188. ],
  189. [
  190. 'alias' => 'BakeUsers',
  191. 'className' => 'BakeUsers',
  192. 'foreignKey' => 'bake_user_id',
  193. ],
  194. ]
  195. ];
  196. $this->assertEquals($expected, $result);
  197. $model = TableRegistry::get('CategoryThreads');
  198. $result = $this->Task->findBelongsTo($model, array());
  199. $expected = [
  200. 'belongsTo' => [
  201. [
  202. 'alias' => 'ParentCategoryThreads',
  203. 'className' => 'CategoryThreads',
  204. 'foreignKey' => 'parent_id',
  205. ],
  206. ]
  207. ];
  208. $this->assertEquals($expected, $result);
  209. }
  210. /**
  211. * test that hasOne and/or hasMany relations are generated properly.
  212. *
  213. * @return void
  214. */
  215. public function testHasManyGeneration() {
  216. $this->Task->connection = 'test';
  217. $model = TableRegistry::get('BakeArticles');
  218. $result = $this->Task->findHasMany($model, []);
  219. $expected = [
  220. 'hasMany' => [
  221. [
  222. 'alias' => 'BakeComments',
  223. 'className' => 'BakeComments',
  224. 'foreignKey' => 'bake_article_id',
  225. ],
  226. ],
  227. ];
  228. $this->assertEquals($expected, $result);
  229. $model = TableRegistry::get('CategoryThreads');
  230. $result = $this->Task->findHasMany($model, []);
  231. $expected = [
  232. 'hasMany' => [
  233. [
  234. 'alias' => 'ChildCategoryThreads',
  235. 'className' => 'CategoryThreads',
  236. 'foreignKey' => 'parent_id',
  237. ],
  238. ]
  239. ];
  240. $this->assertEquals($expected, $result);
  241. }
  242. /**
  243. * Test that HABTM generation works
  244. *
  245. * @return void
  246. */
  247. public function testHasAndBelongsToManyGeneration() {
  248. $this->Task->connection = 'test';
  249. $model = TableRegistry::get('BakeArticles');
  250. $result = $this->Task->findBelongsToMany($model, []);
  251. $expected = [
  252. 'belongsToMany' => [
  253. [
  254. 'alias' => 'BakeTags',
  255. 'className' => 'BakeTags',
  256. 'foreignKey' => 'bake_article_id',
  257. 'joinTable' => 'bake_articles_bake_tags',
  258. 'targetForeignKey' => 'bake_tag_id',
  259. ],
  260. ],
  261. ];
  262. $this->assertEquals($expected, $result);
  263. }
  264. /**
  265. * Test getting accessible fields.
  266. *
  267. * @return void
  268. */
  269. public function testFields() {
  270. $model = TableRegistry::get('BakeArticles');
  271. $result = $this->Task->getFields($model);
  272. $expected = [
  273. 'id',
  274. 'bake_user_id',
  275. 'title',
  276. 'body',
  277. 'published',
  278. ];
  279. $this->assertEquals($expected, $result);
  280. }
  281. /**
  282. * Test getting field with the no- option
  283. *
  284. * @return void
  285. */
  286. public function testFieldsDisabled() {
  287. $model = TableRegistry::get('BakeArticles');
  288. $this->Task->params['no-fields'] = true;
  289. $result = $this->Task->getFields($model);
  290. $this->assertEquals([], $result);
  291. }
  292. /**
  293. * Test getting field with a whitelist
  294. *
  295. * @return void
  296. */
  297. public function testFieldsWhiteList() {
  298. $model = TableRegistry::get('BakeArticles');
  299. $this->Task->params['fields'] = 'id, title , , body , created';
  300. $result = $this->Task->getFields($model);
  301. $expected = [
  302. 'id',
  303. 'title',
  304. 'body',
  305. 'created',
  306. ];
  307. $this->assertEquals($expected, $result);
  308. }
  309. /**
  310. * test getting validation rules with the no-validation rule.
  311. *
  312. * @return void
  313. */
  314. public function testGetValidationDisabled() {
  315. $model = TableRegistry::get('BakeArticles');
  316. $this->Task->params['no-validation'] = true;
  317. $result = $this->Task->getValidation($model);
  318. $this->assertEquals([], $result);
  319. }
  320. /**
  321. * test getting validation rules.
  322. *
  323. * @return void
  324. */
  325. public function testGetValidation() {
  326. $model = TableRegistry::get('BakeArticles');
  327. $result = $this->Task->getValidation($model);
  328. $expected = [
  329. 'id' => ['rule' => 'numeric', 'allowEmpty' => true],
  330. 'bake_user_id' => ['rule' => 'numeric', 'allowEmpty' => true],
  331. 'title' => ['rule' => 'notEmpty', 'allowEmpty' => false],
  332. 'body' => ['rule' => 'notEmpty', 'allowEmpty' => false],
  333. 'published' => ['rule' => 'boolean', 'allowEmpty' => false],
  334. ];
  335. $this->assertEquals($expected, $result);
  336. }
  337. /**
  338. * test non interactive doActsAs
  339. *
  340. * @return void
  341. */
  342. public function testGetBehaviors() {
  343. $model = TableRegistry::get('NumberTrees');
  344. $result = $this->Task->getBehaviors($model);
  345. $this->assertEquals(['Tree'], $result);
  346. $model = TableRegistry::get('BakeArticles');
  347. $result = $this->Task->getBehaviors($model);
  348. $this->assertEquals(['Timestamp'], $result);
  349. }
  350. /**
  351. * Ensure that the fixture object is correctly called.
  352. *
  353. * @return void
  354. */
  355. public function testBakeFixture() {
  356. $this->Task->plugin = 'TestPlugin';
  357. $this->Task->Fixture->expects($this->at(0))
  358. ->method('bake')
  359. ->with('BakeArticle', 'bake_articles');
  360. $this->Task->bakeFixture('BakeArticle', 'bake_articles');
  361. $this->assertEquals($this->Task->plugin, $this->Task->Fixture->plugin);
  362. $this->assertEquals($this->Task->connection, $this->Task->Fixture->connection);
  363. $this->assertEquals($this->Task->interactive, $this->Task->Fixture->interactive);
  364. }
  365. /**
  366. * Ensure that the fixture baking can be disabled
  367. *
  368. * @return void
  369. */
  370. public function testBakeFixtureDisabled() {
  371. $this->Task->params['no-fixture'] = true;
  372. $this->Task->plugin = 'TestPlugin';
  373. $this->Task->Fixture->expects($this->never())
  374. ->method('bake');
  375. $this->Task->bakeFixture('BakeArticle', 'bake_articles');
  376. }
  377. /**
  378. * Ensure that the test object is correctly called.
  379. *
  380. * @return void
  381. */
  382. public function testBakeTest() {
  383. $this->Task->plugin = 'TestPlugin';
  384. $this->Task->Test->expects($this->at(0))
  385. ->method('bake')
  386. ->with('Model', 'BakeArticle');
  387. $this->Task->bakeTest('BakeArticle');
  388. $this->assertEquals($this->Task->plugin, $this->Task->Test->plugin);
  389. $this->assertEquals($this->Task->connection, $this->Task->Test->connection);
  390. $this->assertEquals($this->Task->interactive, $this->Task->Test->interactive);
  391. }
  392. /**
  393. * Ensure that test baking can be disabled.
  394. *
  395. * @return void
  396. */
  397. public function testBakeTestDisabled() {
  398. $this->Task->params['no-test'] = true;
  399. $this->Task->plugin = 'TestPlugin';
  400. $this->Task->Test->expects($this->never())
  401. ->method('bake');
  402. $this->Task->bakeTest('BakeArticle');
  403. }
  404. /**
  405. * test baking validation
  406. *
  407. * @return void
  408. */
  409. public function testBakeTableValidation() {
  410. $validation = array(
  411. 'name' => array(
  412. 'allowEmpty' => false,
  413. 'rule' => 'notEmpty'
  414. ),
  415. 'email' => array(
  416. 'allowEmpty' => true,
  417. 'rule' => 'email',
  418. ),
  419. );
  420. $model = TableRegistry::get('BakeArticles');
  421. $result = $this->Task->bakeTable($model, compact('validation'));
  422. $this->assertContains('namespace App\Model\Table;', $result);
  423. $this->assertContains('use Cake\ORM\Table;', $result);
  424. $this->assertContains('use Cake\Validation\Validator;', $result);
  425. $this->assertContains('class BakeArticlesTable extends Table {', $result);
  426. $this->assertContains('public function validationDefault(Validator $validator) {', $result);
  427. $this->assertContains("->add('name', 'valid', ['rule' => 'notEmpty'])", $result);
  428. $this->assertContains("->add('email', 'valid', ['rule' => 'email'])", $result);
  429. $this->assertContains("->allowEmpty('email')", $result);
  430. }
  431. /**
  432. * test baking
  433. *
  434. * @return void
  435. */
  436. public function testBakeTableConfig() {
  437. $config = [
  438. 'table' => 'articles',
  439. 'primaryKey' => ['id'],
  440. 'displayField' => 'title',
  441. 'behaviors' => ['Timestamp'],
  442. ];
  443. $model = TableRegistry::get('BakeArticles');
  444. $result = $this->Task->bakeTable($model, $config);
  445. $this->assertContains('public function initialize(array $config) {', $result);
  446. $this->assertContains("this->primaryKey(['id']);\n", $result);
  447. $this->assertContains("this->displayField('title');\n", $result);
  448. $this->assertContains("this->addBehavior('Timestamp');\n", $result);
  449. $this->assertContains("this->table('articles');\n", $result);
  450. $this->assertNotContains('use Cake\Validation\Validator;', $result);
  451. }
  452. /**
  453. * test baking relations
  454. *
  455. * @return void
  456. */
  457. public function testBakeTableRelations() {
  458. $associations = [
  459. 'belongsTo' => [
  460. [
  461. 'alias' => 'SomethingElse',
  462. 'className' => 'SomethingElse',
  463. 'foreignKey' => 'something_else_id',
  464. ],
  465. [
  466. 'alias' => 'BakeUser',
  467. 'className' => 'BakeUser',
  468. 'foreignKey' => 'bake_user_id',
  469. ],
  470. ],
  471. 'hasMany' => [
  472. [
  473. 'alias' => 'BakeComment',
  474. 'className' => 'BakeComment',
  475. 'foreignKey' => 'parent_id',
  476. ],
  477. ],
  478. 'belongsToMany' => [
  479. [
  480. 'alias' => 'BakeTag',
  481. 'className' => 'BakeTag',
  482. 'foreignKey' => 'bake_article_id',
  483. 'joinTable' => 'bake_articles_bake_tags',
  484. 'targetForeignKey' => 'bake_tag_id',
  485. ],
  486. ]
  487. ];
  488. $model = TableRegistry::get('BakeArticles');
  489. $result = $this->Task->bakeTable($model, compact('associations'));
  490. $this->assertContains("this->hasMany('BakeComment', [", $result);
  491. $this->assertContains("this->belongsTo('SomethingElse', [", $result);
  492. $this->assertContains("this->belongsTo('BakeUser', [", $result);
  493. $this->assertContains("this->belongsToMany('BakeTag', [", $result);
  494. $this->assertContains("'joinTable' => 'bake_articles_bake_tags',", $result);
  495. }
  496. /**
  497. * test baking an entity class
  498. *
  499. * @return void
  500. */
  501. public function testBakeEntity() {
  502. $config = [
  503. 'fields' => []
  504. ];
  505. $model = TableRegistry::get('BakeArticles');
  506. $result = $this->Task->bakeEntity($model, $config);
  507. $this->assertContains('namespace App\Model\Entity;', $result);
  508. $this->assertContains('use Cake\ORM\Entity;', $result);
  509. $this->assertContains('class BakeArticle extends Entity {', $result);
  510. $this->assertNotContains('$_accessible', $result);
  511. }
  512. /**
  513. * test baking an entity class
  514. *
  515. * @return void
  516. */
  517. public function testBakeEntityFields() {
  518. $config = [
  519. 'fields' => ['title', 'body', 'published']
  520. ];
  521. $model = TableRegistry::get('BakeArticles');
  522. $result = $this->Task->bakeEntity($model, $config);
  523. $this->assertContains("protected \$_accessible = ['title', 'body', 'published']", $result);
  524. }
  525. /**
  526. * test bake() with a -plugin param
  527. *
  528. * @return void
  529. */
  530. public function testBakeTableWithPlugin() {
  531. $this->Task->plugin = 'ControllerTest';
  532. // fake plugin path
  533. Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/'));
  534. $path = APP . 'Plugin/ControllerTest/Model/Table/BakeArticlesTable.php';
  535. $this->Task->expects($this->once())->method('createFile')
  536. ->with($path, $this->logicalAnd(
  537. $this->stringContains('namespace ControllerTest\\Model\\Table;'),
  538. $this->stringContains('use Cake\\ORM\\Table;'),
  539. $this->stringContains('class BakeArticlesTable extends Table {')
  540. ));
  541. $model = TableRegistry::get('BakeArticles');
  542. $this->Task->bakeTable($model);
  543. }
  544. /**
  545. * test bake() with a -plugin param
  546. *
  547. * @return void
  548. */
  549. public function testBakeEntityWithPlugin() {
  550. $this->Task->plugin = 'ControllerTest';
  551. // fake plugin path
  552. Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/'));
  553. $path = APP . 'Plugin/ControllerTest/Model/Entity/BakeArticle.php';
  554. $this->Task->expects($this->once())->method('createFile')
  555. ->with($path, $this->logicalAnd(
  556. $this->stringContains('namespace ControllerTest\\Model\\Entity;'),
  557. $this->stringContains('use Cake\\ORM\\Entity;'),
  558. $this->stringContains('class BakeArticle extends Entity {')
  559. ));
  560. $model = TableRegistry::get('BakeArticles');
  561. $this->Task->bakeEntity($model);
  562. }
  563. /**
  564. * test that execute passes runs bake depending with named model.
  565. *
  566. * @return void
  567. */
  568. public function testExecuteWithNamedModel() {
  569. $this->Task->connection = 'test';
  570. $this->Task->path = '/my/path/';
  571. $this->Task->args = ['BakeArticles'];
  572. $tableFile = '/my/path/Table/BakeArticlesTable.php';
  573. $this->Task->expects($this->at(0))
  574. ->method('createFile')
  575. ->with($tableFile, $this->stringContains('class BakeArticlesTable extends Table'));
  576. $entityFile = '/my/path/Entity/BakeArticle.php';
  577. $this->Task->expects($this->at(1))
  578. ->method('createFile')
  579. ->with($entityFile, $this->stringContains('class BakeArticle extends Entity'));
  580. $this->Task->execute();
  581. }
  582. /**
  583. * data provider for testExecuteWithNamedModelVariations
  584. *
  585. * @return void
  586. */
  587. public static function nameVariations() {
  588. return array(
  589. array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
  590. );
  591. }
  592. /**
  593. * test that execute passes with different inflections of the same name.
  594. *
  595. * @dataProvider nameVariations
  596. * @return void
  597. */
  598. public function testExecuteWithNamedModelVariations($name) {
  599. $this->Task->connection = 'test';
  600. $this->Task->path = '/my/path/';
  601. $this->Task->args = array($name);
  602. $filename = '/my/path/Table/BakeArticlesTable.php';
  603. $this->Task->expects($this->at(0))
  604. ->method('createFile')
  605. ->with($filename, $this->stringContains('class BakeArticlesTable extends Table {'));
  606. $this->Task->execute();
  607. }
  608. /**
  609. * test that execute runs all() when args[0] = all
  610. *
  611. * @return void
  612. */
  613. public function testExecuteIntoAll() {
  614. $count = count($this->Task->listAll());
  615. if ($count != count($this->fixtures)) {
  616. $this->markTestSkipped('Additional tables detected.');
  617. }
  618. $this->Task->connection = 'test';
  619. $this->Task->path = '/my/path/';
  620. $this->Task->args = ['all'];
  621. $this->Task->Fixture->expects($this->exactly(6))
  622. ->method('bake');
  623. $this->Task->Test->expects($this->exactly(6))
  624. ->method('bake');
  625. $filename = '/my/path/Table/BakeArticlesTable.php';
  626. $this->Task->expects($this->at(0))
  627. ->method('createFile')
  628. ->with($filename, $this->stringContains('class BakeArticlesTable extends'));
  629. $filename = '/my/path/Entity/BakeArticle.php';
  630. $this->Task->expects($this->at(1))
  631. ->method('createFile')
  632. ->with($filename, $this->stringContains('class BakeArticle extends'));
  633. $filename = '/my/path/Table/BakeArticlesBakeTagsTable.php';
  634. $this->Task->expects($this->at(2))
  635. ->method('createFile')
  636. ->with($filename, $this->stringContains('class BakeArticlesBakeTagsTable extends'));
  637. $filename = '/my/path/Entity/BakeArticlesBakeTag.php';
  638. $this->Task->expects($this->at(3))
  639. ->method('createFile')
  640. ->with($filename, $this->stringContains('class BakeArticlesBakeTag extends'));
  641. $filename = '/my/path/Table/BakeCommentsTable.php';
  642. $this->Task->expects($this->at(4))
  643. ->method('createFile')
  644. ->with($filename, $this->stringContains('class BakeCommentsTable extends'));
  645. $filename = '/my/path/Entity/BakeComment.php';
  646. $this->Task->expects($this->at(5))
  647. ->method('createFile')
  648. ->with($filename, $this->stringContains('class BakeComment extends'));
  649. $filename = '/my/path/Table/BakeTagsTable.php';
  650. $this->Task->expects($this->at(6))
  651. ->method('createFile')
  652. ->with($filename, $this->stringContains('class BakeTagsTable extends'));
  653. $filename = '/my/path/Entity/BakeTag.php';
  654. $this->Task->expects($this->at(7))
  655. ->method('createFile')
  656. ->with($filename, $this->stringContains('class BakeTag extends'));
  657. $filename = '/my/path/Table/CategoryThreadsTable.php';
  658. $this->Task->expects($this->at(8))
  659. ->method('createFile')
  660. ->with($filename, $this->stringContains('class CategoryThreadsTable extends'));
  661. $filename = '/my/path/Entity/CategoryThread.php';
  662. $this->Task->expects($this->at(9))
  663. ->method('createFile')
  664. ->with($filename, $this->stringContains('class CategoryThread extends'));
  665. $this->Task->execute();
  666. }
  667. /**
  668. * test that skipTables changes how all() works.
  669. *
  670. * @return void
  671. */
  672. public function testSkipTablesAndAll() {
  673. $count = count($this->Task->listAll('test'));
  674. if ($count != count($this->fixtures)) {
  675. $this->markTestSkipped('Additional tables detected.');
  676. }
  677. $this->Task->connection = 'test';
  678. $this->Task->path = '/my/path/';
  679. $this->Task->args = ['all'];
  680. $this->Task->skipTables = ['bake_tags'];
  681. $this->Task->Fixture->expects($this->exactly(5))
  682. ->method('bake');
  683. $this->Task->Test->expects($this->exactly(5))
  684. ->method('bake');
  685. $filename = '/my/path/Entity/BakeArticle.php';
  686. $this->Task->expects($this->at(1))
  687. ->method('createFile')
  688. ->with($filename);
  689. $filename = '/my/path/Entity/BakeArticlesBakeTag.php';
  690. $this->Task->expects($this->at(3))
  691. ->method('createFile')
  692. ->with($filename);
  693. $filename = '/my/path/Entity/BakeComment.php';
  694. $this->Task->expects($this->at(5))
  695. ->method('createFile')
  696. ->with($filename);
  697. $filename = '/my/path/Entity/CategoryThread.php';
  698. $this->Task->expects($this->at(7))
  699. ->method('createFile')
  700. ->with($filename);
  701. $filename = '/my/path/Entity/NumberTree.php';
  702. $this->Task->expects($this->at(9))
  703. ->method('createFile')
  704. ->with($filename);
  705. $this->Task->execute();
  706. }
  707. }