SchemaShellTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <?php
  2. /**
  3. * SchemaShellTest Test file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * For full copyright and license information, please see the LICENSE.txt
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://cakephp.org CakePHP Project
  16. * @package Cake.Test.Case.Console.Command
  17. * @since CakePHP v 1.3
  18. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  19. */
  20. App::uses('ShellDispatcher', 'Console');
  21. App::uses('ConsoleOutput', 'Console');
  22. App::uses('ConsoleInput', 'Console');
  23. App::uses('Shell', 'Console');
  24. App::uses('CakeSchema', 'Model');
  25. App::uses('SchemaShell', 'Console/Command');
  26. /**
  27. * Test for Schema database management
  28. *
  29. * @package Cake.Test.Case.Console.Command
  30. */
  31. class SchemaShellTestSchema extends CakeSchema {
  32. /**
  33. * connection property
  34. *
  35. * @var string
  36. */
  37. public $connection = 'test';
  38. /**
  39. * comments property
  40. *
  41. * @var array
  42. */
  43. public $comments = array(
  44. 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
  45. 'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
  46. 'user_id' => array('type' => 'integer', 'null' => false),
  47. 'title' => array('type' => 'string', 'null' => false, 'length' => 100),
  48. 'comment' => array('type' => 'text', 'null' => false, 'default' => null),
  49. 'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
  50. 'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
  51. 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
  52. 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
  53. );
  54. /**
  55. * posts property
  56. *
  57. * @var array
  58. */
  59. public $articles = array(
  60. 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
  61. 'user_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
  62. 'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
  63. 'body' => array('type' => 'text', 'null' => true, 'default' => null),
  64. 'summary' => array('type' => 'text', 'null' => true),
  65. 'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1),
  66. 'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
  67. 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
  68. 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
  69. );
  70. public $newone = array(
  71. 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
  72. 'testit' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
  73. 'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
  74. 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
  75. 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
  76. );
  77. }
  78. /**
  79. * SchemaShellTest class
  80. *
  81. * @package Cake.Test.Case.Console.Command
  82. */
  83. class SchemaShellTest extends CakeTestCase {
  84. /**
  85. * Fixtures
  86. *
  87. * @var array
  88. */
  89. public $fixtures = array(
  90. 'core.article', 'core.user', 'core.post', 'core.auth_user', 'core.author',
  91. 'core.comment', 'core.test_plugin_comment', 'core.aco', 'core.aro', 'core.aros_aco',
  92. );
  93. /**
  94. * setUp method
  95. *
  96. * @return void
  97. */
  98. public function setUp() {
  99. parent::setUp();
  100. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  101. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  102. $this->Shell = $this->getMock(
  103. 'SchemaShell',
  104. array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop'),
  105. array($out, $out, $in)
  106. );
  107. }
  108. /**
  109. * tearDown method
  110. *
  111. * @return void
  112. */
  113. public function tearDown() {
  114. parent::tearDown();
  115. if (!empty($this->file) && $this->file instanceof File) {
  116. $this->file->delete();
  117. unset($this->file);
  118. }
  119. }
  120. /**
  121. * test startup method
  122. *
  123. * @return void
  124. */
  125. public function testStartup() {
  126. $this->Shell->startup();
  127. $this->assertTrue(isset($this->Shell->Schema));
  128. $this->assertInstanceOf('CakeSchema', $this->Shell->Schema);
  129. $this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $this->Shell->Schema->name);
  130. $this->assertEquals('schema.php', $this->Shell->Schema->file);
  131. $this->Shell->Schema = null;
  132. $this->Shell->params = array(
  133. 'name' => 'TestSchema'
  134. );
  135. $this->Shell->startup();
  136. $this->assertEquals('TestSchema', $this->Shell->Schema->name);
  137. $this->assertEquals('test_schema.php', $this->Shell->Schema->file);
  138. $this->assertEquals('default', $this->Shell->Schema->connection);
  139. $this->assertEquals(APP . 'Config' . DS . 'Schema', $this->Shell->Schema->path);
  140. $this->Shell->Schema = null;
  141. $this->Shell->params = array(
  142. 'file' => 'other_file.php',
  143. 'connection' => 'test',
  144. 'path' => '/test/path'
  145. );
  146. $this->Shell->startup();
  147. $this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $this->Shell->Schema->name);
  148. $this->assertEquals('other_file.php', $this->Shell->Schema->file);
  149. $this->assertEquals('test', $this->Shell->Schema->connection);
  150. $this->assertEquals('/test/path', $this->Shell->Schema->path);
  151. }
  152. /**
  153. * Test View - and that it dumps the schema file to stdout
  154. *
  155. * @return void
  156. */
  157. public function testView() {
  158. $this->Shell->startup();
  159. $this->Shell->Schema->path = APP . 'Config' . DS . 'Schema';
  160. $this->Shell->params['file'] = 'i18n.php';
  161. $this->Shell->expects($this->once())->method('_stop');
  162. $this->Shell->expects($this->once())->method('out');
  163. $this->Shell->view();
  164. }
  165. /**
  166. * test that view() can find plugin schema files.
  167. *
  168. * @return void
  169. */
  170. public function testViewWithPlugins() {
  171. App::build(array(
  172. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  173. ));
  174. CakePlugin::load('TestPlugin');
  175. $this->Shell->args = array('TestPlugin.schema');
  176. $this->Shell->startup();
  177. $this->Shell->expects($this->exactly(2))->method('_stop');
  178. $this->Shell->expects($this->atLeastOnce())->method('out');
  179. $this->Shell->view();
  180. $this->Shell->args = array();
  181. $this->Shell->params = array('plugin' => 'TestPlugin');
  182. $this->Shell->startup();
  183. $this->Shell->view();
  184. App::build();
  185. CakePlugin::unload();
  186. }
  187. /**
  188. * test dump() with sql file generation
  189. *
  190. * @return void
  191. */
  192. public function testDumpWithFileWriting() {
  193. $this->Shell->params = array(
  194. 'name' => 'i18n',
  195. 'connection' => 'test',
  196. 'write' => TMP . 'tests' . DS . 'i18n.sql'
  197. );
  198. $this->Shell->expects($this->once())->method('_stop');
  199. $this->Shell->startup();
  200. $this->Shell->dump();
  201. $this->file = new File(TMP . 'tests' . DS . 'i18n.sql');
  202. $contents = $this->file->read();
  203. $this->assertRegExp('/DROP TABLE/', $contents);
  204. $this->assertRegExp('/CREATE TABLE.*?i18n/', $contents);
  205. $this->assertRegExp('/id/', $contents);
  206. $this->assertRegExp('/model/', $contents);
  207. $this->assertRegExp('/field/', $contents);
  208. $this->assertRegExp('/locale/', $contents);
  209. $this->assertRegExp('/foreign_key/', $contents);
  210. $this->assertRegExp('/content/', $contents);
  211. }
  212. /**
  213. * test that dump() can find and work with plugin schema files.
  214. *
  215. * @return void
  216. */
  217. public function testDumpFileWritingWithPlugins() {
  218. App::build(array(
  219. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  220. ));
  221. CakePlugin::load('TestPlugin');
  222. $this->Shell->args = array('TestPlugin.TestPluginApp');
  223. $this->Shell->params = array(
  224. 'connection' => 'test',
  225. 'write' => TMP . 'tests' . DS . 'dump_test.sql'
  226. );
  227. $this->Shell->startup();
  228. $this->Shell->expects($this->once())->method('_stop');
  229. $this->Shell->dump();
  230. $this->file = new File(TMP . 'tests' . DS . 'dump_test.sql');
  231. $contents = $this->file->read();
  232. $this->assertRegExp('/CREATE TABLE.*?test_plugin_acos/', $contents);
  233. $this->assertRegExp('/id/', $contents);
  234. $this->assertRegExp('/model/', $contents);
  235. $this->file->delete();
  236. App::build();
  237. CakePlugin::unload();
  238. }
  239. /**
  240. * test generate with snapshot generation
  241. *
  242. * @return void
  243. */
  244. public function testGenerateSnapshot() {
  245. $this->Shell->path = TMP;
  246. $this->Shell->params['file'] = 'schema.php';
  247. $this->Shell->params['force'] = false;
  248. $this->Shell->args = array('snapshot');
  249. $this->Shell->Schema = $this->getMock('CakeSchema');
  250. $this->Shell->Schema->expects($this->at(0))->method('read')->will($this->returnValue(array('schema data')));
  251. $this->Shell->Schema->expects($this->at(0))->method('write')->will($this->returnValue(true));
  252. $this->Shell->Schema->expects($this->at(1))->method('read');
  253. $this->Shell->Schema->expects($this->at(1))->method('write')->with(array('schema data', 'file' => 'schema_0.php'));
  254. $this->Shell->generate();
  255. }
  256. /**
  257. * test generate without a snapshot.
  258. *
  259. * @return void
  260. */
  261. public function testGenerateNoOverwrite() {
  262. touch(TMP . 'schema.php');
  263. $this->Shell->params['file'] = 'schema.php';
  264. $this->Shell->params['force'] = false;
  265. $this->Shell->args = array();
  266. $this->Shell->expects($this->once())->method('in')->will($this->returnValue('q'));
  267. $this->Shell->Schema = $this->getMock('CakeSchema');
  268. $this->Shell->Schema->path = TMP;
  269. $this->Shell->Schema->expects($this->never())->method('read');
  270. $this->Shell->generate();
  271. unlink(TMP . 'schema.php');
  272. }
  273. /**
  274. * test generate with overwriting of the schema files.
  275. *
  276. * @return void
  277. */
  278. public function testGenerateOverwrite() {
  279. touch(TMP . 'schema.php');
  280. $this->Shell->params['file'] = 'schema.php';
  281. $this->Shell->params['force'] = false;
  282. $this->Shell->args = array();
  283. $this->Shell->expects($this->once())->method('in')->will($this->returnValue('o'));
  284. $this->Shell->expects($this->at(2))->method('out')
  285. ->with(new PHPUnit_Framework_Constraint_PCREMatch('/Schema file:\s[a-z\.]+\sgenerated/'));
  286. $this->Shell->Schema = $this->getMock('CakeSchema');
  287. $this->Shell->Schema->path = TMP;
  288. $this->Shell->Schema->expects($this->once())->method('read')->will($this->returnValue(array('schema data')));
  289. $this->Shell->Schema->expects($this->once())->method('write')->will($this->returnValue(true));
  290. $this->Shell->Schema->expects($this->once())->method('read');
  291. $this->Shell->Schema->expects($this->once())->method('write')
  292. ->with(array('schema data', 'file' => 'schema.php'));
  293. $this->Shell->generate();
  294. unlink(TMP . 'schema.php');
  295. }
  296. /**
  297. * test that generate() can read plugin dirs and generate schema files for the models
  298. * in a plugin.
  299. *
  300. * @return void
  301. */
  302. public function testGenerateWithPlugins() {
  303. App::build(array(
  304. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  305. ), App::RESET);
  306. CakePlugin::load('TestPlugin');
  307. $this->db->cacheSources = false;
  308. $this->Shell->params = array(
  309. 'plugin' => 'TestPlugin',
  310. 'connection' => 'test',
  311. 'force' => false
  312. );
  313. $this->Shell->startup();
  314. $this->Shell->Schema->path = TMP . 'tests' . DS;
  315. $this->Shell->generate();
  316. $this->file = new File(TMP . 'tests' . DS . 'schema.php');
  317. $contents = $this->file->read();
  318. $this->assertRegExp('/class TestPluginSchema/', $contents);
  319. $this->assertRegExp('/public \$posts/', $contents);
  320. $this->assertRegExp('/public \$auth_users/', $contents);
  321. $this->assertRegExp('/public \$authors/', $contents);
  322. $this->assertRegExp('/public \$test_plugin_comments/', $contents);
  323. $this->assertNotRegExp('/public \$users/', $contents);
  324. $this->assertNotRegExp('/public \$articles/', $contents);
  325. CakePlugin::unload();
  326. }
  327. /**
  328. * test generate with specific models
  329. *
  330. * @return void
  331. */
  332. public function testGenerateModels() {
  333. App::build(array(
  334. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  335. ), App::RESET);
  336. CakePlugin::load('TestPlugin');
  337. $this->db->cacheSources = false;
  338. $this->Shell->params = array(
  339. 'plugin' => 'TestPlugin',
  340. 'connection' => 'test',
  341. 'models' => 'TestPluginComment',
  342. 'force' => false,
  343. 'overwrite' => true
  344. );
  345. $this->Shell->startup();
  346. $this->Shell->Schema->path = TMP . 'tests' . DS;
  347. $this->Shell->generate();
  348. $this->file = new File(TMP . 'tests' . DS . 'schema.php');
  349. $contents = $this->file->read();
  350. $this->assertRegExp('/class TestPluginSchema/', $contents);
  351. $this->assertRegExp('/public \$test_plugin_comments/', $contents);
  352. $this->assertNotRegExp('/public \$authors/', $contents);
  353. $this->assertNotRegExp('/public \$auth_users/', $contents);
  354. $this->assertNotRegExp('/public \$posts/', $contents);
  355. CakePlugin::unload();
  356. }
  357. /**
  358. * test generate with excluded tables
  359. *
  360. * @return void
  361. */
  362. public function testGenerateExclude() {
  363. Configure::write('Acl.database', 'test');
  364. $this->db->cacheSources = false;
  365. $this->Shell->params = array(
  366. 'connection' => 'test',
  367. 'force' => false,
  368. 'models' => 'Aro, Aco, Permission',
  369. 'overwrite' => true,
  370. 'exclude' => 'acos, aros',
  371. );
  372. $this->Shell->startup();
  373. $this->Shell->Schema->path = TMP . 'tests' . DS;
  374. $this->Shell->generate();
  375. $this->file = new File(TMP . 'tests' . DS . 'schema.php');
  376. $contents = $this->file->read();
  377. $this->assertNotContains('public $acos = array(', $contents);
  378. $this->assertNotContains('public $aros = array(', $contents);
  379. $this->assertContains('public $aros_acos = array(', $contents);
  380. }
  381. /**
  382. * Test schema run create with no table args.
  383. *
  384. * @return void
  385. */
  386. public function testCreateNoArgs() {
  387. $this->Shell->params = array(
  388. 'connection' => 'test'
  389. );
  390. $this->Shell->args = array('i18n');
  391. $this->Shell->startup();
  392. $this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
  393. $this->Shell->create();
  394. $db = ConnectionManager::getDataSource('test');
  395. $db->cacheSources = false;
  396. $sources = $db->listSources();
  397. $this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources));
  398. $schema = new i18nSchema();
  399. $db->execute($db->dropSchema($schema));
  400. }
  401. /**
  402. * Test schema run create with no table args.
  403. *
  404. * @return void
  405. */
  406. public function testCreateWithTableArgs() {
  407. $db = ConnectionManager::getDataSource('test');
  408. $sources = $db->listSources();
  409. if (in_array('i18n', $sources)) {
  410. $this->markTestSkipped('i18n table already exists, cannot try to create it again.');
  411. }
  412. $this->Shell->params = array(
  413. 'connection' => 'test',
  414. 'name' => 'I18n',
  415. 'path' => APP . 'Config' . DS . 'Schema'
  416. );
  417. $this->Shell->args = array('I18n', 'i18n');
  418. $this->Shell->startup();
  419. $this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
  420. $this->Shell->create();
  421. $db = ConnectionManager::getDataSource('test');
  422. $db->cacheSources = false;
  423. $sources = $db->listSources();
  424. $this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources), 'i18n should be present.');
  425. $schema = new I18nSchema();
  426. $db->execute($db->dropSchema($schema, 'i18n'));
  427. }
  428. /**
  429. * test run update with a table arg.
  430. *
  431. * @return void
  432. */
  433. public function testUpdateWithTable() {
  434. $this->Shell = $this->getMock(
  435. 'SchemaShell',
  436. array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
  437. array(&$this->Dispatcher)
  438. );
  439. $this->Shell->params = array(
  440. 'connection' => 'test',
  441. 'force' => true
  442. );
  443. $this->Shell->args = array('SchemaShellTest', 'articles');
  444. $this->Shell->startup();
  445. $this->Shell->expects($this->any())
  446. ->method('in')
  447. ->will($this->returnValue('y'));
  448. $this->Shell->expects($this->once())
  449. ->method('_run')
  450. ->with($this->arrayHasKey('articles'), 'update', $this->isInstanceOf('CakeSchema'));
  451. $this->Shell->update();
  452. }
  453. /**
  454. * test run update with a table arg. and checks that a CREATE statement is issued
  455. * table creation
  456. * @return void
  457. */
  458. public function testUpdateWithTableCreate() {
  459. $this->Shell = $this->getMock(
  460. 'SchemaShell',
  461. array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'),
  462. array(&$this->Dispatcher)
  463. );
  464. $this->Shell->params = array(
  465. 'connection' => 'test',
  466. 'force' => true
  467. );
  468. $this->Shell->args = array('SchemaShellTest', 'newone');
  469. $this->Shell->startup();
  470. $this->Shell->expects($this->any())
  471. ->method('in')
  472. ->will($this->returnValue('y'));
  473. $r = $this->Shell->expects($this->once())
  474. ->method('_run')
  475. ->with($this->arrayHasKey('newone'), 'update', $this->isInstanceOf('CakeSchema'));
  476. $this->Shell->update();
  477. }
  478. /**
  479. * test that the plugin param creates the correct path in the schema object.
  480. *
  481. * @return void
  482. */
  483. public function testPluginParam() {
  484. App::build(array(
  485. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  486. ));
  487. CakePlugin::load('TestPlugin');
  488. $this->Shell->params = array(
  489. 'plugin' => 'TestPlugin',
  490. 'connection' => 'test'
  491. );
  492. $this->Shell->startup();
  493. $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Config' . DS . 'Schema';
  494. $this->assertEquals($expected, $this->Shell->Schema->path);
  495. CakePlugin::unload();
  496. }
  497. /**
  498. * test that underscored names also result in CamelCased class names
  499. *
  500. * @return void
  501. */
  502. public function testName() {
  503. App::build(array(
  504. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  505. ));
  506. CakePlugin::load('TestPlugin');
  507. $this->Shell->params = array(
  508. 'plugin' => 'TestPlugin',
  509. 'connection' => 'test',
  510. 'name' => 'custom_name',
  511. 'force' => false,
  512. 'overwrite' => true,
  513. );
  514. $this->Shell->startup();
  515. if (file_exists($this->Shell->Schema->path . DS . 'custom_name.php')) {
  516. unlink($this->Shell->Schema->path . DS . 'custom_name.php');
  517. }
  518. $this->Shell->generate();
  519. $contents = file_get_contents($this->Shell->Schema->path . DS . 'custom_name.php');
  520. $this->assertRegExp('/class CustomNameSchema/', $contents);
  521. unlink($this->Shell->Schema->path . DS . 'custom_name.php');
  522. CakePlugin::unload();
  523. }
  524. /**
  525. * test that passing name and file creates the passed filename with the
  526. * passed classname
  527. *
  528. * @return void
  529. */
  530. public function testNameAndFile() {
  531. App::build(array(
  532. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  533. ));
  534. CakePlugin::load('TestPlugin');
  535. $this->Shell->params = array(
  536. 'plugin' => 'TestPlugin',
  537. 'connection' => 'test',
  538. 'name' => 'custom_name',
  539. 'file' => 'other_name',
  540. 'force' => false,
  541. 'overwrite' => true,
  542. );
  543. $this->Shell->startup();
  544. $file = $this->Shell->Schema->path . DS . 'other_name.php';
  545. if (file_exists($file)) {
  546. unlink($file);
  547. }
  548. $this->Shell->generate();
  549. $this->assertFileExists($file);
  550. $contents = file_get_contents($file);
  551. $this->assertRegExp('/class CustomNameSchema/', $contents);
  552. if (file_exists($file)) {
  553. unlink($file);
  554. }
  555. CakePlugin::unload();
  556. }
  557. /**
  558. * test that using Plugin.name with write.
  559. *
  560. * @return void
  561. */
  562. public function testPluginDotSyntaxWithCreate() {
  563. App::build(array(
  564. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  565. ));
  566. CakePlugin::load('TestPlugin');
  567. $this->Shell->params = array(
  568. 'connection' => 'test'
  569. );
  570. $this->Shell->args = array('TestPlugin.TestPluginApp');
  571. $this->Shell->startup();
  572. $this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
  573. $this->Shell->create();
  574. $db = ConnectionManager::getDataSource('test');
  575. $sources = $db->listSources();
  576. $this->assertTrue(in_array($db->config['prefix'] . 'test_plugin_acos', $sources));
  577. $schema = new TestPluginAppSchema();
  578. $db->execute($db->dropSchema($schema, 'test_plugin_acos'));
  579. CakePlugin::unload();
  580. }
  581. }