2009-08-07 22:10:39 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* SchemaShellTest Test file
|
|
|
|
*
|
2010-10-03 12:31:21 -04:00
|
|
|
* PHP 5
|
2009-08-07 22:10:39 -04:00
|
|
|
*
|
2009-11-06 17:46:59 +11:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2010-01-13 23:47:14 -05:00
|
|
|
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
2009-08-07 22:10:39 -04:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-13 23:47:14 -05:00
|
|
|
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
2009-11-06 17:00:11 +11:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2010-12-24 13:57:20 -05:00
|
|
|
* @package cake.tests.cases.console.libs.Shells
|
2009-08-07 22:10:39 -04:00
|
|
|
* @since CakePHP v 1.3
|
2009-11-06 17:51:51 +11:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2009-08-07 22:10:39 -04:00
|
|
|
*/
|
|
|
|
|
2010-12-08 23:15:18 -04:30
|
|
|
App::uses('ShellDispatcher', 'Console');
|
2011-03-08 01:27:52 -04:30
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2010-12-08 23:15:18 -04:30
|
|
|
App::uses('Shell', 'Console');
|
|
|
|
App::uses('CakeSchema', 'Model');
|
2011-03-08 01:27:52 -04:30
|
|
|
App::uses('SchemaShell', 'Console/Command');
|
2009-08-07 22:10:39 -04:00
|
|
|
|
2009-09-06 21:05:24 -04:00
|
|
|
/**
|
|
|
|
* Test for Schema database management
|
|
|
|
*
|
2010-12-24 13:57:20 -05:00
|
|
|
* @package cake.tests.cases.libs
|
2009-09-06 21:05:24 -04:00
|
|
|
*/
|
|
|
|
class SchemaShellTestSchema extends CakeSchema {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string 'MyApp'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 17:14:00 +10:00
|
|
|
public $name = 'SchemaShellTest';
|
2009-09-06 21:05:24 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* connection property
|
|
|
|
*
|
2010-09-19 22:28:30 -04:30
|
|
|
* @var string 'test'
|
2009-09-06 21:05:24 -04:00
|
|
|
* @access public
|
|
|
|
*/
|
2010-09-19 22:28:30 -04:30
|
|
|
public $connection = 'test';
|
2009-09-06 21:05:24 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* comments property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 17:14:00 +10:00
|
|
|
public $comments = array(
|
2009-09-06 21:05:24 -04:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
|
|
|
|
'user_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'title' => array('type' => 'string', 'null' => false, 'length' => 100),
|
|
|
|
'comment' => array('type' => 'text', 'null' => false, 'default' => null),
|
|
|
|
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
|
|
|
|
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
|
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* posts property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 17:14:00 +10:00
|
|
|
public $articles = array(
|
2009-09-06 21:05:24 -04:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'user_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
|
|
|
|
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
|
|
|
|
'body' => array('type' => 'text', 'null' => true, 'default' => null),
|
|
|
|
'summary' => array('type' => 'text', 'null' => true),
|
|
|
|
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1),
|
|
|
|
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
|
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-08-07 22:10:39 -04:00
|
|
|
/**
|
|
|
|
* SchemaShellTest class
|
|
|
|
*
|
2010-12-24 13:57:20 -05:00
|
|
|
* @package cake.tests.cases.console.libs.Shells
|
2009-08-07 22:10:39 -04:00
|
|
|
*/
|
|
|
|
class SchemaShellTest extends CakeTestCase {
|
|
|
|
|
2009-11-14 23:18:31 +11:00
|
|
|
/**
|
|
|
|
* Fixtures
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2011-04-17 12:35:21 +02:00
|
|
|
public $fixtures = array('core.article', 'core.user', 'core.post', 'core.auth_user', 'core.author',
|
2010-03-14 13:06:22 -04:00
|
|
|
'core.comment', 'core.test_plugin_comment'
|
|
|
|
);
|
2009-11-14 23:18:31 +11:00
|
|
|
|
2009-08-07 22:10:39 -04:00
|
|
|
/**
|
2010-09-20 23:05:35 -04:00
|
|
|
* setup method
|
2009-08-07 22:10:39 -04:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-10-06 22:52:42 -04:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell = $this->getMock(
|
|
|
|
'SchemaShell',
|
|
|
|
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop'),
|
2010-10-24 15:11:30 -04:00
|
|
|
array($out, $out, $in)
|
2010-05-23 00:17:22 -04:00
|
|
|
);
|
2009-08-07 22:10:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* endTest method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-10-06 22:52:42 -04:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2010-09-20 23:05:35 -04:00
|
|
|
if (!empty($this->file) && $this->file instanceof File) {
|
|
|
|
$this->file->delete();
|
|
|
|
unset($this->file);
|
|
|
|
}
|
2009-08-07 22:10:39 -04:00
|
|
|
}
|
|
|
|
|
2009-08-07 22:19:40 -04:00
|
|
|
/**
|
|
|
|
* test startup method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testStartup() {
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->Shell->startup();
|
|
|
|
$this->assertTrue(isset($this->Shell->Schema));
|
|
|
|
$this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema'));
|
2009-09-07 18:33:16 -04:00
|
|
|
$this->assertEqual(strtolower($this->Shell->Schema->name), strtolower(APP_DIR));
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->assertEqual($this->Shell->Schema->file, 'schema.php');
|
|
|
|
|
2010-10-10 00:23:25 -04:00
|
|
|
$this->Shell->Schema = null;
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->Shell->params = array(
|
2009-08-07 22:19:40 -04:00
|
|
|
'name' => 'TestSchema'
|
|
|
|
);
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->Shell->startup();
|
|
|
|
$this->assertEqual($this->Shell->Schema->name, 'TestSchema');
|
|
|
|
$this->assertEqual($this->Shell->Schema->file, 'test_schema.php');
|
|
|
|
$this->assertEqual($this->Shell->Schema->connection, 'default');
|
2011-05-14 23:40:09 -04:30
|
|
|
$this->assertEqual($this->Shell->Schema->path, APP . 'Config' . DS . 'Schema');
|
2009-09-06 21:05:24 -04:00
|
|
|
|
2010-10-10 00:23:25 -04:00
|
|
|
$this->Shell->Schema = null;
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->Shell->params = array(
|
2009-08-07 22:19:40 -04:00
|
|
|
'file' => 'other_file.php',
|
2010-09-19 22:28:30 -04:30
|
|
|
'connection' => 'test',
|
2009-08-07 22:19:40 -04:00
|
|
|
'path' => '/test/path'
|
|
|
|
);
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->Shell->startup();
|
2009-09-07 18:33:16 -04:00
|
|
|
$this->assertEqual(strtolower($this->Shell->Schema->name), strtolower(APP_DIR));
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->assertEqual($this->Shell->Schema->file, 'other_file.php');
|
2010-09-19 22:28:30 -04:30
|
|
|
$this->assertEqual($this->Shell->Schema->connection, 'test');
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->assertEqual($this->Shell->Schema->path, '/test/path');
|
2009-08-07 22:19:40 -04:00
|
|
|
}
|
2009-08-07 22:28:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test View - and that it dumps the schema file to stdout
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testView() {
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->Shell->startup();
|
2011-05-16 23:17:29 +02:00
|
|
|
$this->Shell->Schema->path = APP . 'Config' . DS . 'Schema';
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->Shell->params['file'] = 'i18n.php';
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->expects($this->once())->method('_stop');
|
|
|
|
$this->Shell->expects($this->once())->method('out');
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->Shell->view();
|
2009-08-07 22:28:28 -04:00
|
|
|
}
|
|
|
|
|
2009-10-04 14:06:07 -04:00
|
|
|
/**
|
|
|
|
* test that view() can find plugin schema files.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testViewWithPlugins() {
|
2009-10-04 14:06:07 -04:00
|
|
|
App::build(array(
|
2011-04-17 12:35:21 +02:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2009-10-04 14:06:07 -04:00
|
|
|
));
|
2011-05-12 00:25:16 -04:30
|
|
|
CakePlugin::load('TestPlugin');
|
2009-10-04 14:06:07 -04:00
|
|
|
$this->Shell->args = array('TestPlugin.schema');
|
|
|
|
$this->Shell->startup();
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->expects($this->exactly(2))->method('_stop');
|
|
|
|
$this->Shell->expects($this->exactly(2))->method('out');
|
2009-10-04 14:06:07 -04:00
|
|
|
$this->Shell->view();
|
|
|
|
|
|
|
|
$this->Shell->args = array();
|
|
|
|
$this->Shell->params = array('plugin' => 'TestPlugin');
|
|
|
|
$this->Shell->startup();
|
|
|
|
$this->Shell->view();
|
|
|
|
|
|
|
|
App::build();
|
2011-05-12 00:25:16 -04:30
|
|
|
CakePlugin::unload();
|
2009-10-04 14:06:07 -04:00
|
|
|
}
|
|
|
|
|
2009-08-08 23:00:40 -04:00
|
|
|
/**
|
|
|
|
* test dump() with sql file generation
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testDumpWithFileWriting() {
|
2009-10-04 14:47:35 -04:00
|
|
|
$this->Shell->params = array(
|
|
|
|
'name' => 'i18n',
|
|
|
|
'write' => TMP . 'tests' . DS . 'i18n.sql'
|
|
|
|
);
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->expects($this->once())->method('_stop');
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->Shell->startup();
|
|
|
|
$this->Shell->dump();
|
2009-08-08 23:00:40 -04:00
|
|
|
|
2010-11-12 23:05:44 -05:00
|
|
|
$this->file = new File(TMP . 'tests' . DS . 'i18n.sql');
|
2010-09-20 23:05:35 -04:00
|
|
|
$contents = $this->file->read();
|
2009-08-08 23:00:40 -04:00
|
|
|
$this->assertPattern('/DROP TABLE/', $contents);
|
2010-12-02 00:30:21 -04:30
|
|
|
$this->assertPattern('/CREATE TABLE.*?i18n/', $contents);
|
2009-08-08 23:00:40 -04:00
|
|
|
$this->assertPattern('/id/', $contents);
|
|
|
|
$this->assertPattern('/model/', $contents);
|
|
|
|
$this->assertPattern('/field/', $contents);
|
|
|
|
$this->assertPattern('/locale/', $contents);
|
|
|
|
$this->assertPattern('/foreign_key/', $contents);
|
|
|
|
$this->assertPattern('/content/', $contents);
|
2009-10-04 14:47:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that dump() can find and work with plugin schema files.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testDumpFileWritingWithPlugins() {
|
2009-10-04 14:47:35 -04:00
|
|
|
App::build(array(
|
2011-04-17 12:35:21 +02:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2009-10-04 14:47:35 -04:00
|
|
|
));
|
2011-05-12 00:25:16 -04:30
|
|
|
CakePlugin::load('TestPlugin');
|
2009-10-04 14:47:35 -04:00
|
|
|
$this->Shell->args = array('TestPlugin.TestPluginApp');
|
|
|
|
$this->Shell->params = array(
|
2010-09-19 22:28:30 -04:30
|
|
|
'connection' => 'test',
|
2009-10-04 14:47:35 -04:00
|
|
|
'write' => TMP . 'tests' . DS . 'dump_test.sql'
|
|
|
|
);
|
|
|
|
$this->Shell->startup();
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->expects($this->once())->method('_stop');
|
2009-10-04 14:47:35 -04:00
|
|
|
$this->Shell->dump();
|
|
|
|
|
2010-11-12 23:05:44 -05:00
|
|
|
$this->file = new File(TMP . 'tests' . DS . 'dump_test.sql');
|
2010-09-20 23:05:35 -04:00
|
|
|
$contents = $this->file->read();
|
2009-10-04 14:47:35 -04:00
|
|
|
|
2010-12-02 00:19:43 -04:30
|
|
|
$this->assertPattern('/CREATE TABLE.*?test_plugin_acos/', $contents);
|
2009-10-04 14:47:35 -04:00
|
|
|
$this->assertPattern('/id/', $contents);
|
|
|
|
$this->assertPattern('/model/', $contents);
|
|
|
|
|
2010-09-20 23:05:35 -04:00
|
|
|
$this->file->delete();
|
2009-10-04 14:47:35 -04:00
|
|
|
App::build();
|
2011-05-12 00:25:16 -04:30
|
|
|
CakePlugin::unload();
|
2009-08-07 22:28:28 -04:00
|
|
|
}
|
2009-08-08 23:21:24 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test generate with snapshot generation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-23 00:17:22 -04:00
|
|
|
public function testGenerateSnapshot() {
|
2009-08-08 23:21:24 -04:00
|
|
|
$this->Shell->path = TMP;
|
|
|
|
$this->Shell->params['file'] = 'schema.php';
|
|
|
|
$this->Shell->args = array('snapshot');
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->Schema = $this->getMock('CakeSchema');
|
|
|
|
$this->Shell->Schema->expects($this->at(0))->method('read')->will($this->returnValue(array('schema data')));
|
|
|
|
$this->Shell->Schema->expects($this->at(0))->method('write')->will($this->returnValue(true));
|
2009-08-08 23:21:24 -04:00
|
|
|
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->Schema->expects($this->at(1))->method('read');
|
2010-07-07 23:14:12 -04:30
|
|
|
$this->Shell->Schema->expects($this->at(1))->method('write')->with(array('schema data', 'file' => 'schema_0.php'));
|
2009-08-08 23:21:24 -04:00
|
|
|
|
|
|
|
$this->Shell->generate();
|
|
|
|
}
|
2009-08-08 23:46:00 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test generate without a snapshot.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testGenerateNoOverwrite() {
|
2009-08-08 23:46:00 -04:00
|
|
|
touch(TMP . 'schema.php');
|
|
|
|
$this->Shell->params['file'] = 'schema.php';
|
|
|
|
$this->Shell->args = array();
|
|
|
|
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->expects($this->once())->method('in')->will($this->returnValue('q'));
|
|
|
|
$this->Shell->Schema = $this->getMock('CakeSchema');
|
2009-08-08 23:46:00 -04:00
|
|
|
$this->Shell->Schema->path = TMP;
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->Schema->expects($this->never())->method('read');
|
2009-08-08 23:46:00 -04:00
|
|
|
|
|
|
|
$result = $this->Shell->generate();
|
|
|
|
unlink(TMP . 'schema.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test generate with overwriting of the schema files.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testGenerateOverwrite() {
|
2009-08-08 23:46:00 -04:00
|
|
|
touch(TMP . 'schema.php');
|
|
|
|
$this->Shell->params['file'] = 'schema.php';
|
|
|
|
$this->Shell->args = array();
|
|
|
|
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->expects($this->once())->method('in')->will($this->returnValue('o'));
|
|
|
|
|
|
|
|
$this->Shell->expects($this->at(2))->method('out')
|
|
|
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Schema file:\s[a-z\.]+\sgenerated/'));
|
2011-04-17 12:35:21 +02:00
|
|
|
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->Schema = $this->getMock('CakeSchema');
|
2009-08-08 23:46:00 -04:00
|
|
|
$this->Shell->Schema->path = TMP;
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->Schema->expects($this->once())->method('read')->will($this->returnValue(array('schema data')));
|
|
|
|
$this->Shell->Schema->expects($this->once())->method('write')->will($this->returnValue(true));
|
2009-08-08 23:46:00 -04:00
|
|
|
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->Schema->expects($this->once())->method('read');
|
|
|
|
$this->Shell->Schema->expects($this->once())->method('write')
|
|
|
|
->with(array('schema data', 'file' => 'schema.php'));
|
2009-08-08 23:46:00 -04:00
|
|
|
|
|
|
|
$this->Shell->generate();
|
|
|
|
unlink(TMP . 'schema.php');
|
|
|
|
}
|
2009-08-10 21:54:29 -04:00
|
|
|
|
2009-10-08 22:40:17 -04:00
|
|
|
/**
|
|
|
|
* test that generate() can read plugin dirs and generate schema files for the models
|
|
|
|
* in a plugin.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testGenerateWithPlugins() {
|
2009-10-08 22:40:17 -04:00
|
|
|
App::build(array(
|
2011-04-17 12:35:21 +02:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2010-09-20 23:05:35 -04:00
|
|
|
), true);
|
2011-05-12 00:25:16 -04:30
|
|
|
CakePlugin::load('TestPlugin');
|
2010-09-20 23:05:35 -04:00
|
|
|
|
2010-12-03 14:07:46 -04:30
|
|
|
$this->db->cacheSources = false;
|
2009-10-08 22:40:17 -04:00
|
|
|
$this->Shell->params = array(
|
|
|
|
'plugin' => 'TestPlugin',
|
2010-09-19 22:28:30 -04:30
|
|
|
'connection' => 'test'
|
2009-10-08 22:40:17 -04:00
|
|
|
);
|
|
|
|
$this->Shell->startup();
|
|
|
|
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
|
|
|
|
|
|
|
$this->Shell->generate();
|
2010-09-20 23:05:35 -04:00
|
|
|
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
|
|
|
|
$contents = $this->file->read();
|
2009-10-08 22:40:17 -04:00
|
|
|
|
2010-07-23 21:46:06 -04:00
|
|
|
$this->assertPattern('/class TestPluginSchema/', $contents);
|
2009-10-08 22:40:17 -04:00
|
|
|
$this->assertPattern('/var \$posts/', $contents);
|
|
|
|
$this->assertPattern('/var \$auth_users/', $contents);
|
2010-02-28 12:38:49 -05:00
|
|
|
$this->assertPattern('/var \$authors/', $contents);
|
2010-03-14 13:06:22 -04:00
|
|
|
$this->assertPattern('/var \$test_plugin_comments/', $contents);
|
2009-10-08 22:40:17 -04:00
|
|
|
$this->assertNoPattern('/var \$users/', $contents);
|
|
|
|
$this->assertNoPattern('/var \$articles/', $contents);
|
2011-05-12 00:25:16 -04:30
|
|
|
CakePlugin::unload();
|
2009-10-08 22:40:17 -04:00
|
|
|
}
|
|
|
|
|
2009-08-10 21:54:29 -04:00
|
|
|
/**
|
|
|
|
* Test schema run create with no table args.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testCreateNoArgs() {
|
2009-08-10 21:54:29 -04:00
|
|
|
$this->Shell->params = array(
|
2010-12-02 00:19:43 -04:30
|
|
|
'connection' => 'test'
|
2009-08-10 21:54:29 -04:00
|
|
|
);
|
2009-10-04 11:16:23 -04:00
|
|
|
$this->Shell->args = array('i18n');
|
2009-08-10 21:54:29 -04:00
|
|
|
$this->Shell->startup();
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
2009-10-04 11:16:23 -04:00
|
|
|
$this->Shell->create();
|
2009-09-06 21:05:24 -04:00
|
|
|
|
2010-09-19 22:28:30 -04:30
|
|
|
$db = ConnectionManager::getDataSource('test');
|
2011-04-17 12:35:21 +02:00
|
|
|
|
2010-12-02 00:19:43 -04:30
|
|
|
$db->cacheSources = false;
|
2009-08-10 21:54:29 -04:00
|
|
|
$sources = $db->listSources();
|
2009-09-06 21:05:24 -04:00
|
|
|
$this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources));
|
2009-09-16 02:02:40 -04:00
|
|
|
|
2010-05-23 00:17:22 -04:00
|
|
|
$schema = new i18nSchema();
|
2009-09-16 02:02:40 -04:00
|
|
|
$db->execute($db->dropSchema($schema));
|
2009-08-10 21:54:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test schema run create with no table args.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testCreateWithTableArgs() {
|
2010-09-25 00:13:37 -04:00
|
|
|
$db = ConnectionManager::getDataSource('test');
|
|
|
|
$sources = $db->listSources();
|
|
|
|
if (in_array('acos', $sources)) {
|
|
|
|
$this->markTestSkipped('acos table already exists, cannot try to create it again.');
|
|
|
|
}
|
2009-08-10 21:54:29 -04:00
|
|
|
$this->Shell->params = array(
|
2010-09-19 22:28:30 -04:30
|
|
|
'connection' => 'test',
|
2009-08-10 21:54:29 -04:00
|
|
|
'name' => 'DbAcl',
|
2011-05-16 23:17:29 +02:00
|
|
|
'path' => APP . 'Config' . DS . 'Schema'
|
2009-08-10 21:54:29 -04:00
|
|
|
);
|
2009-10-04 11:16:23 -04:00
|
|
|
$this->Shell->args = array('DbAcl', 'acos');
|
2009-08-10 21:54:29 -04:00
|
|
|
$this->Shell->startup();
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
2009-10-04 11:16:23 -04:00
|
|
|
$this->Shell->create();
|
2009-08-10 21:54:29 -04:00
|
|
|
|
2010-09-25 00:13:37 -04:00
|
|
|
$db = ConnectionManager::getDataSource('test');
|
2010-12-02 00:19:43 -04:30
|
|
|
$db->cacheSources = false;
|
2009-08-10 21:54:29 -04:00
|
|
|
$sources = $db->listSources();
|
2010-09-25 00:13:37 -04:00
|
|
|
$this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources), 'acos should be present.');
|
|
|
|
$this->assertFalse(in_array($db->config['prefix'] . 'aros', $sources), 'aros should not be found.');
|
|
|
|
$this->assertFalse(in_array('aros_acos', $sources), 'aros_acos should not be found.');
|
2010-10-18 23:26:50 -04:00
|
|
|
|
|
|
|
$schema = new DbAclSchema();
|
|
|
|
$db->execute($db->dropSchema($schema, 'acos'));
|
2009-08-10 21:54:29 -04:00
|
|
|
}
|
|
|
|
|
2009-09-06 21:05:24 -04:00
|
|
|
/**
|
|
|
|
* test run update with a table arg.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testUpdateWithTable() {
|
2010-09-21 23:25:08 -04:00
|
|
|
$this->Shell = $this->getMock(
|
|
|
|
'SchemaShell',
|
|
|
|
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '__run'),
|
|
|
|
array(&$this->Dispatcher)
|
|
|
|
);
|
|
|
|
|
2009-09-06 21:05:24 -04:00
|
|
|
$this->Shell->params = array(
|
2010-09-19 22:28:30 -04:30
|
|
|
'connection' => 'test',
|
2010-10-16 00:43:03 -04:00
|
|
|
'force' => true
|
2009-09-06 21:05:24 -04:00
|
|
|
);
|
2009-10-04 11:16:23 -04:00
|
|
|
$this->Shell->args = array('SchemaShellTest', 'articles');
|
2009-09-06 21:05:24 -04:00
|
|
|
$this->Shell->startup();
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
2010-09-21 23:25:08 -04:00
|
|
|
$this->Shell->expects($this->once())->method('__run')
|
|
|
|
->with($this->arrayHasKey('articles'), 'update', $this->isInstanceOf('CakeSchema'));
|
2011-04-17 12:35:21 +02:00
|
|
|
|
2009-10-04 11:16:23 -04:00
|
|
|
$this->Shell->update();
|
2009-09-06 21:05:24 -04:00
|
|
|
}
|
|
|
|
|
2009-08-20 01:07:21 -04:00
|
|
|
/**
|
|
|
|
* test that the plugin param creates the correct path in the schema object.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testPluginParam() {
|
2009-08-20 01:07:21 -04:00
|
|
|
App::build(array(
|
2011-04-17 12:35:21 +02:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2009-08-20 01:07:21 -04:00
|
|
|
));
|
2011-05-12 00:25:16 -04:30
|
|
|
CakePlugin::load('TestPlugin');
|
2009-08-20 01:07:21 -04:00
|
|
|
$this->Shell->params = array(
|
|
|
|
'plugin' => 'TestPlugin',
|
2010-09-19 22:28:30 -04:30
|
|
|
'connection' => 'test'
|
2009-08-20 01:07:21 -04:00
|
|
|
);
|
|
|
|
$this->Shell->startup();
|
2011-04-17 12:35:21 +02:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Config' . DS . 'Schema';
|
2009-08-20 01:07:21 -04:00
|
|
|
$this->assertEqual($this->Shell->Schema->path, $expected);
|
2011-05-12 00:25:16 -04:30
|
|
|
CakePlugin::unload();
|
2009-10-04 13:32:33 -04:00
|
|
|
}
|
2009-08-20 01:07:21 -04:00
|
|
|
|
2009-10-04 13:32:33 -04:00
|
|
|
/**
|
|
|
|
* test that using Plugin.name with write.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:18:31 +11:00
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function testPluginDotSyntaxWithCreate() {
|
2009-10-04 13:32:33 -04:00
|
|
|
App::build(array(
|
2011-05-15 18:49:38 +02:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2009-10-04 13:32:33 -04:00
|
|
|
));
|
2011-05-12 00:25:16 -04:30
|
|
|
CakePlugin::load('TestPlugin');
|
2009-08-20 01:07:21 -04:00
|
|
|
$this->Shell->params = array(
|
2010-09-19 22:28:30 -04:30
|
|
|
'connection' => 'test'
|
2009-08-20 01:07:21 -04:00
|
|
|
);
|
2009-10-04 13:32:33 -04:00
|
|
|
$this->Shell->args = array('TestPlugin.TestPluginApp');
|
2009-08-20 01:07:21 -04:00
|
|
|
$this->Shell->startup();
|
2010-05-23 00:17:22 -04:00
|
|
|
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
2009-10-04 13:32:33 -04:00
|
|
|
$this->Shell->create();
|
2009-08-20 01:07:21 -04:00
|
|
|
|
2011-04-29 11:19:33 -04:30
|
|
|
$db = ConnectionManager::getDataSource('test');
|
2009-10-04 13:32:33 -04:00
|
|
|
$sources = $db->listSources();
|
2010-10-24 15:11:30 -04:00
|
|
|
$this->assertTrue(in_array($db->config['prefix'] . 'test_plugin_acos', $sources));
|
2010-10-18 23:26:50 -04:00
|
|
|
|
2010-10-23 00:54:39 -04:00
|
|
|
$schema = new TestPluginAppSchema();
|
|
|
|
$db->execute($db->dropSchema($schema, 'test_plugin_acos'));
|
2011-05-12 00:25:16 -04:30
|
|
|
CakePlugin::unload();
|
2010-09-25 01:25:42 -04:00
|
|
|
}
|
2009-08-07 22:10:39 -04:00
|
|
|
}
|