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