2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Test for Schema database management
|
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5550
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
|
|
|
|
App::uses('CakeSchema', 'Model');
|
2011-01-09 04:15:07 +00:00
|
|
|
App::uses('CakeTestFixture', 'TestSuite/Fixture');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Test for Schema database management
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class MyAppSchema extends CakeSchema {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* connection property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-09-20 02:58:30 +00:00
|
|
|
public $connection = 'test';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* comments property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $comments = array(
|
2008-08-04 16:53:39 +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)),
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* posts property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $posts = array(
|
2008-08-04 16:53:39 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'author_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)),
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-08-02 03:22:46 +00:00
|
|
|
/**
|
|
|
|
* _foo property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $_foo = array('bar');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getVar method
|
|
|
|
*
|
|
|
|
* @param string $var Name of var
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getVar($var) {
|
|
|
|
if (!isset($this->$var)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $this->$var;
|
|
|
|
}
|
2012-03-19 01:20:17 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestAppSchema class
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestAppSchema extends CakeSchema {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'MyApp';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* comments property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $comments = array(
|
2013-06-09 15:39:48 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
2008-10-01 15:27:29 +00:00
|
|
|
'article_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'user_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'comment' => array('type' => 'text', 'null' => true, '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)),
|
2009-10-03 16:41:14 +00:00
|
|
|
'tableParameters' => array(),
|
2008-10-01 15:27:29 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* posts property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $posts = array(
|
2008-10-01 15:27:29 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'title' => array('type' => 'string', 'null' => false),
|
|
|
|
'body' => array('type' => 'text', 'null' => true, '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)),
|
2009-10-03 16:41:14 +00:00
|
|
|
'tableParameters' => array(),
|
2008-10-01 15:27:29 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* posts_tags property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $posts_tags = array(
|
2008-12-17 03:32:45 +00:00
|
|
|
'post_id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
|
2008-10-01 15:27:29 +00:00
|
|
|
'tag_id' => array('type' => 'string', 'null' => false, 'key' => 'primary'),
|
2009-10-03 16:41:14 +00:00
|
|
|
'indexes' => array('posts_tag' => array('column' => array('tag_id', 'post_id'), 'unique' => 1)),
|
|
|
|
'tableParameters' => array()
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* tags property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $tags = array(
|
2008-08-04 16:53:39 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'tag' => array('type' => 'string', 'null' => false),
|
2008-08-04 16:53:39 +00:00
|
|
|
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
|
|
|
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
2009-10-03 16:41:14 +00:00
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
|
|
|
'tableParameters' => array()
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* datatypes property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $datatypes = array(
|
2008-08-04 16:53:39 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
2009-10-03 20:08:54 +00:00
|
|
|
'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => ''),
|
2013-09-28 06:29:39 +00:00
|
|
|
'decimal_field' => array('type' => 'decimal', 'length' => '6,3', 'default' => '0.000'),
|
2012-08-30 13:26:17 +00:00
|
|
|
'huge_int' => array('type' => 'biginteger'),
|
2011-02-05 20:24:46 +00:00
|
|
|
'bool' => array('type' => 'boolean', 'null' => false, 'default' => false),
|
2009-10-03 16:41:14 +00:00
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
|
|
|
'tableParameters' => array()
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setup method
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
|
|
|
* @param mixed $version
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setup($version) {
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* teardown method
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
|
|
|
* @param mixed $version
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function teardown($version) {
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-03-19 01:20:17 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* SchemaPost class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class SchemaPost extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'posts';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasMany property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasMany = array('SchemaComment');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasAndBelongsToMany property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasAndBelongsToMany = array('SchemaTag');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* SchemaComment class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class SchemaComment extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'comments';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* belongsTo property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array('SchemaPost');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* SchemaTag class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class SchemaTag extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'tags';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* hasAndBelongsToMany property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasAndBelongsToMany = array('SchemaPost');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* SchemaDatatype class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class SchemaDatatype extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'datatypes';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-03 17:41:05 +00:00
|
|
|
/**
|
|
|
|
* Testdescribe class
|
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* This class is defined purely to inherit the cacheSources variable otherwise
|
2012-02-23 23:29:53 +00:00
|
|
|
* testSchemaCreateTable will fail if listSources has already been called and
|
2009-03-19 21:10:13 +00:00
|
|
|
* its source cache populated - I.e. if the test is run within a group
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @uses CakeTestModel
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-08-03 17:41:05 +00:00
|
|
|
*/
|
|
|
|
class Testdescribe extends CakeTestModel {
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-02-15 17:46:18 +00:00
|
|
|
/**
|
|
|
|
* SchemaCrossDatabase class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2010-02-15 17:46:18 +00:00
|
|
|
*/
|
|
|
|
class SchemaCrossDatabase extends CakeTestModel {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* useTable property
|
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2010-02-15 17:46:18 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'cross_database';
|
2010-02-15 17:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* useDbConfig property
|
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2010-02-15 17:46:18 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useDbConfig = 'test2';
|
2010-02-15 17:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SchemaCrossDatabaseFixture class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2010-02-15 17:46:18 +00:00
|
|
|
*/
|
|
|
|
class SchemaCrossDatabaseFixture extends CakeTestFixture {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2010-02-15 17:46:18 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'CrossDatabase';
|
2010-02-15 17:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* table property
|
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2010-02-15 17:46:18 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $table = 'cross_database';
|
2010-02-15 17:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* fields property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fields = array(
|
2010-02-15 17:46:18 +00:00
|
|
|
'id' => array('type' => 'integer', 'key' => 'primary'),
|
|
|
|
'name' => 'string'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* records property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $records = array(
|
2010-02-15 17:46:18 +00:00
|
|
|
array('id' => 1, 'name' => 'First'),
|
|
|
|
array('id' => 2, 'name' => 'Second'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-03-04 05:51:20 +00:00
|
|
|
/**
|
|
|
|
* NonConventionalPrimaryKeyFixture class
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.Model
|
|
|
|
*/
|
|
|
|
class NonConventionalPrimaryKeyFixture extends CakeTestFixture {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $name = 'NonConventional';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* table property
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $table = 'non_conventional';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fields property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $fields = array(
|
|
|
|
'version_id' => array('type' => 'integer', 'key' => 'primary'),
|
|
|
|
'id' => array('type' => 'integer'),
|
|
|
|
'name' => 'string'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-04-25 07:22:57 +00:00
|
|
|
/**
|
|
|
|
* SchemaPrefixAuthUser class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2010-04-25 07:22:57 +00:00
|
|
|
*/
|
|
|
|
class SchemaPrefixAuthUser extends CakeTestModel {
|
2012-03-19 01:20:17 +00:00
|
|
|
|
2010-04-25 07:22:57 +00:00
|
|
|
/**
|
|
|
|
* table prefix
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-06-26 16:29:20 +00:00
|
|
|
public $tablePrefix = 'auth_';
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-04-25 07:22:57 +00:00
|
|
|
/**
|
|
|
|
* useTable
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-06-26 16:29:20 +00:00
|
|
|
public $useTable = 'users';
|
2010-04-25 07:22:57 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* CakeSchemaTest
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class CakeSchemaTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* fixtures property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'core.post', 'core.tag', 'core.posts_tag', 'core.test_plugin_comment',
|
2010-02-28 18:31:23 +00:00
|
|
|
'core.datatype', 'core.auth_user', 'core.author',
|
2011-05-31 15:40:29 +00:00
|
|
|
'core.test_plugin_article', 'core.user', 'core.comment',
|
|
|
|
'core.prefix_test'
|
2009-10-03 20:08:54 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::setUp();
|
2010-10-17 19:55:04 +00:00
|
|
|
ConnectionManager::getDataSource('test')->cacheSources = false;
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Schema = new TestAppSchema();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::tearDown();
|
2012-03-19 01:20:17 +00:00
|
|
|
if (file_exists(TMP . 'tests' . DS . 'schema.php')) {
|
|
|
|
unlink(TMP . 'tests' . DS . 'schema.php');
|
2011-05-28 21:08:22 +00:00
|
|
|
}
|
2009-03-19 21:10:13 +00:00
|
|
|
unset($this->Schema);
|
2011-05-10 04:40:15 +00:00
|
|
|
CakePlugin::unload();
|
2009-03-19 21:10:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testSchemaName method
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaName() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$Schema = new CakeSchema();
|
2014-08-11 15:40:57 +00:00
|
|
|
$this->assertEquals('App', $Schema->name);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testSchemaRead method
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaRead() {
|
2008-10-01 15:27:29 +00:00
|
|
|
$read = $this->Schema->read(array(
|
2010-09-20 02:58:30 +00:00
|
|
|
'connection' => 'test',
|
2008-10-01 15:27:29 +00:00
|
|
|
'name' => 'TestApp',
|
|
|
|
'models' => array('SchemaPost', 'SchemaComment', 'SchemaTag', 'SchemaDatatype')
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($read['tables']['missing']);
|
2008-10-01 15:27:29 +00:00
|
|
|
|
2009-10-03 16:41:14 +00:00
|
|
|
$expected = array('comments', 'datatypes', 'posts', 'posts_tags', 'tags');
|
2010-09-19 17:30:36 +00:00
|
|
|
foreach ($expected as $table) {
|
|
|
|
$this->assertTrue(isset($read['tables'][$table]), 'Missing table ' . $table);
|
|
|
|
}
|
|
|
|
foreach ($this->Schema->tables as $table => $fields) {
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(array_keys($fields), array_keys($read['tables'][$table]));
|
2009-10-03 16:41:14 +00:00
|
|
|
}
|
|
|
|
|
2011-09-03 21:51:48 +00:00
|
|
|
if (isset($read['tables']['datatypes']['float_field']['length'])) {
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(
|
2011-09-03 21:51:48 +00:00
|
|
|
$read['tables']['datatypes']['float_field']['length'],
|
|
|
|
$this->Schema->tables['datatypes']['float_field']['length']
|
|
|
|
);
|
|
|
|
}
|
2010-12-02 04:49:43 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(
|
2010-12-02 04:49:43 +00:00
|
|
|
$read['tables']['datatypes']['float_field']['type'],
|
|
|
|
$this->Schema->tables['datatypes']['float_field']['type']
|
|
|
|
);
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(
|
2010-12-02 04:49:43 +00:00
|
|
|
$read['tables']['datatypes']['float_field']['null'],
|
|
|
|
$this->Schema->tables['datatypes']['float_field']['null']
|
2008-10-01 15:27:29 +00:00
|
|
|
);
|
|
|
|
|
2010-10-17 19:55:04 +00:00
|
|
|
$db = ConnectionManager::getDataSource('test');
|
2008-09-17 01:47:19 +00:00
|
|
|
$config = $db->config;
|
|
|
|
$config['prefix'] = 'schema_test_prefix_';
|
|
|
|
ConnectionManager::create('schema_prefix', $config);
|
|
|
|
$read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false));
|
|
|
|
$this->assertTrue(empty($read['tables']));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-11-13 05:43:40 +00:00
|
|
|
$read = $this->Schema->read(array(
|
2010-09-20 02:58:30 +00:00
|
|
|
'connection' => 'test',
|
2009-11-13 05:43:40 +00:00
|
|
|
'name' => 'TestApp',
|
2011-02-24 06:01:03 +00:00
|
|
|
'models' => array('SchemaComment', 'SchemaTag', 'SchemaPost')
|
2009-11-13 05:43:40 +00:00
|
|
|
));
|
2011-02-24 06:01:03 +00:00
|
|
|
$this->assertFalse(isset($read['tables']['missing']['posts_tags']), 'Join table marked as missing');
|
|
|
|
}
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2011-07-15 19:48:38 +00:00
|
|
|
/**
|
2012-03-19 01:20:17 +00:00
|
|
|
* testSchemaReadWithAppModel method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-07-15 19:48:38 +00:00
|
|
|
public function testSchemaReadWithAppModel() {
|
|
|
|
$connections = ConnectionManager::enumConnectionObjects();
|
2011-10-28 05:01:17 +00:00
|
|
|
ConnectionManager::drop('default');
|
2011-07-15 19:48:38 +00:00
|
|
|
ConnectionManager::create('default', $connections['test']);
|
|
|
|
try {
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Schema->read(array(
|
2012-03-19 01:20:17 +00:00
|
|
|
'connection' => 'default',
|
|
|
|
'name' => 'TestApp',
|
|
|
|
'models' => array('AppModel')
|
2011-07-15 19:48:38 +00:00
|
|
|
));
|
|
|
|
} catch(MissingTableException $mte) {
|
2011-09-29 03:27:50 +00:00
|
|
|
ConnectionManager::drop('default');
|
2011-07-15 19:48:38 +00:00
|
|
|
$this->fail($mte->getMessage());
|
|
|
|
}
|
2011-09-29 03:27:50 +00:00
|
|
|
ConnectionManager::drop('default');
|
2011-07-15 19:48:38 +00:00
|
|
|
}
|
2010-06-04 03:20:37 +00:00
|
|
|
|
2011-02-24 06:01:03 +00:00
|
|
|
/**
|
|
|
|
* testSchemaReadWithOddTablePrefix method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaReadWithOddTablePrefix() {
|
2011-02-24 06:01:03 +00:00
|
|
|
$config = ConnectionManager::getDataSource('test')->config;
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set.');
|
|
|
|
|
2011-02-24 06:01:03 +00:00
|
|
|
$SchemaPost = ClassRegistry::init('SchemaPost');
|
|
|
|
$SchemaPost->tablePrefix = 'po';
|
|
|
|
$SchemaPost->useTable = 'sts';
|
2010-06-04 03:20:37 +00:00
|
|
|
$read = $this->Schema->read(array(
|
2010-09-20 02:58:30 +00:00
|
|
|
'connection' => 'test',
|
2010-06-04 03:20:37 +00:00
|
|
|
'name' => 'TestApp',
|
2011-02-24 06:01:03 +00:00
|
|
|
'models' => array('SchemaPost')
|
2010-06-04 03:20:37 +00:00
|
|
|
));
|
2011-02-24 06:01:03 +00:00
|
|
|
|
|
|
|
$this->assertFalse(isset($read['tables']['missing']['posts']), 'Posts table was not read from tablePrefix');
|
2009-11-13 05:43:40 +00:00
|
|
|
}
|
2010-02-15 17:46:18 +00:00
|
|
|
|
2010-04-25 07:22:57 +00:00
|
|
|
/**
|
|
|
|
* test read() with tablePrefix properties.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaReadWithTablePrefix() {
|
2011-02-24 06:01:03 +00:00
|
|
|
$config = ConnectionManager::getDataSource('test')->config;
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set.');
|
2011-02-24 06:01:03 +00:00
|
|
|
|
2010-10-17 19:55:04 +00:00
|
|
|
$Schema = new CakeSchema();
|
2010-04-25 07:22:57 +00:00
|
|
|
$read = $Schema->read(array(
|
2010-09-20 02:58:30 +00:00
|
|
|
'connection' => 'test',
|
2010-04-25 07:22:57 +00:00
|
|
|
'name' => 'TestApp',
|
|
|
|
'models' => array('SchemaPrefixAuthUser')
|
|
|
|
));
|
|
|
|
unset($read['tables']['missing']);
|
|
|
|
$this->assertTrue(isset($read['tables']['auth_users']), 'auth_users key missing %s');
|
|
|
|
}
|
|
|
|
|
2010-10-21 03:17:04 +00:00
|
|
|
/**
|
|
|
|
* test reading schema with config prefix.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaReadWithConfigPrefix() {
|
2011-09-04 01:37:40 +00:00
|
|
|
$this->skipIf($this->db instanceof Sqlite, 'Cannot open 2 connections to Sqlite');
|
2012-03-12 14:12:44 +00:00
|
|
|
|
2011-01-09 04:15:07 +00:00
|
|
|
$db = ConnectionManager::getDataSource('test');
|
2010-10-21 03:17:04 +00:00
|
|
|
$config = $db->config;
|
2011-12-04 20:10:01 +00:00
|
|
|
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set.');
|
2012-03-12 14:12:44 +00:00
|
|
|
|
2010-10-21 03:17:04 +00:00
|
|
|
$config['prefix'] = 'schema_test_prefix_';
|
|
|
|
ConnectionManager::create('schema_prefix', $config);
|
|
|
|
$read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false));
|
|
|
|
$this->assertTrue(empty($read['tables']));
|
2011-05-31 15:40:29 +00:00
|
|
|
|
|
|
|
$config['prefix'] = 'prefix_';
|
|
|
|
ConnectionManager::create('schema_prefix2', $config);
|
|
|
|
$read = $this->Schema->read(array(
|
|
|
|
'connection' => 'schema_prefix2',
|
|
|
|
'name' => 'TestApp',
|
|
|
|
'models' => false));
|
|
|
|
$this->assertTrue(isset($read['tables']['prefix_tests']));
|
2010-10-21 03:17:04 +00:00
|
|
|
}
|
|
|
|
|
2009-08-28 05:06:21 +00:00
|
|
|
/**
|
|
|
|
* test reading schema from plugins.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaReadWithPlugins() {
|
2009-08-28 05:06:21 +00:00
|
|
|
App::objects('model', null, false);
|
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2009-08-28 05:06:21 +00:00
|
|
|
));
|
2011-05-10 04:40:15 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
2010-02-28 18:31:23 +00:00
|
|
|
|
2010-10-17 19:55:04 +00:00
|
|
|
$Schema = new CakeSchema();
|
2009-08-28 05:06:21 +00:00
|
|
|
$Schema->plugin = 'TestPlugin';
|
|
|
|
$read = $Schema->read(array(
|
2010-09-20 02:58:30 +00:00
|
|
|
'connection' => 'test',
|
2009-08-28 05:06:21 +00:00
|
|
|
'name' => 'TestApp',
|
|
|
|
'models' => true
|
|
|
|
));
|
2009-10-03 20:08:54 +00:00
|
|
|
unset($read['tables']['missing']);
|
|
|
|
$this->assertTrue(isset($read['tables']['auth_users']));
|
2010-02-15 17:46:18 +00:00
|
|
|
$this->assertTrue(isset($read['tables']['authors']));
|
2010-02-28 18:31:23 +00:00
|
|
|
$this->assertTrue(isset($read['tables']['test_plugin_comments']));
|
2010-02-15 17:46:18 +00:00
|
|
|
$this->assertTrue(isset($read['tables']['posts']));
|
2010-09-19 17:30:36 +00:00
|
|
|
$this->assertTrue(count($read['tables']) >= 4);
|
2010-04-25 07:22:57 +00:00
|
|
|
|
2009-08-28 05:06:21 +00:00
|
|
|
App::build();
|
|
|
|
}
|
2009-10-03 16:44:49 +00:00
|
|
|
|
2010-02-15 17:46:18 +00:00
|
|
|
/**
|
|
|
|
* test reading schema with tables from another database.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaReadWithCrossDatabase() {
|
2011-11-17 05:33:46 +00:00
|
|
|
$config = ConnectionManager::enumConnectionObjects();
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(
|
2011-11-17 05:33:46 +00:00
|
|
|
!isset($config['test']) || !isset($config['test2']),
|
2012-03-19 01:20:17 +00:00
|
|
|
'Primary and secondary test databases not configured, ' .
|
|
|
|
'skipping cross-database join tests. ' .
|
|
|
|
'To run these tests, you must define $test and $test2 in your database configuration.'
|
2010-02-15 17:46:18 +00:00
|
|
|
);
|
|
|
|
|
2012-03-19 01:20:17 +00:00
|
|
|
$db = ConnectionManager::getDataSource('test2');
|
2010-02-15 17:46:18 +00:00
|
|
|
$fixture = new SchemaCrossDatabaseFixture();
|
2012-03-19 01:20:17 +00:00
|
|
|
$fixture->create($db);
|
|
|
|
$fixture->insert($db);
|
2010-02-15 17:46:18 +00:00
|
|
|
|
|
|
|
$read = $this->Schema->read(array(
|
2010-09-20 02:58:30 +00:00
|
|
|
'connection' => 'test',
|
2010-02-15 17:46:18 +00:00
|
|
|
'name' => 'TestApp',
|
|
|
|
'models' => array('SchemaCrossDatabase', 'SchemaPost')
|
|
|
|
));
|
|
|
|
$this->assertTrue(isset($read['tables']['posts']));
|
2010-10-01 03:22:57 +00:00
|
|
|
$this->assertFalse(isset($read['tables']['cross_database']), 'Cross database should not appear');
|
|
|
|
$this->assertFalse(isset($read['tables']['missing']['cross_database']), 'Cross database should not appear');
|
2010-02-15 17:46:18 +00:00
|
|
|
|
|
|
|
$read = $this->Schema->read(array(
|
|
|
|
'connection' => 'test2',
|
|
|
|
'name' => 'TestApp',
|
|
|
|
'models' => array('SchemaCrossDatabase', 'SchemaPost')
|
|
|
|
));
|
2010-10-01 03:22:57 +00:00
|
|
|
$this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear');
|
|
|
|
$this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear');
|
2010-02-15 17:46:18 +00:00
|
|
|
$this->assertTrue(isset($read['tables']['cross_database']));
|
|
|
|
|
2012-03-19 01:20:17 +00:00
|
|
|
$fixture->drop($db);
|
2010-02-15 17:46:18 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 05:51:20 +00:00
|
|
|
/**
|
|
|
|
* testSchemaRead method when a primary key is on a non-conventional column
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSchemaReadWithNonConventionalPrimaryKey() {
|
2017-03-06 20:58:03 +00:00
|
|
|
$this->skipIf($this->db instanceof Postgres, 'Cannot test on Postgres');
|
2017-03-04 05:51:20 +00:00
|
|
|
$db = ConnectionManager::getDataSource('test');
|
|
|
|
$fixture = new NonConventionalPrimaryKeyFixture();
|
|
|
|
$fixture->create($db);
|
|
|
|
|
|
|
|
$read = $this->Schema->read(array(
|
|
|
|
'connection' => 'test',
|
|
|
|
'name' => 'TestApp',
|
|
|
|
'models' => false
|
|
|
|
));
|
|
|
|
$fixture->drop($db);
|
|
|
|
|
2017-03-06 20:58:03 +00:00
|
|
|
$hasTable = isset($read['tables']['non_conventional']);
|
|
|
|
$this->assertTrue($hasTable, 'non_conventional table should appear');
|
2017-03-10 04:11:17 +00:00
|
|
|
$versionIdHasKey = isset($read['tables']['non_conventional']['version_id']['key']);
|
2017-03-06 20:58:03 +00:00
|
|
|
$this->assertTrue($versionIdHasKey, 'version_id key should be set');
|
2017-03-10 04:11:17 +00:00
|
|
|
$versionIdKeyIsPrimary = $read['tables']['non_conventional']['version_id']['key'] === 'primary';
|
2017-03-06 20:58:03 +00:00
|
|
|
$this->assertTrue($versionIdKeyIsPrimary, 'version_id key should be primary');
|
2017-03-10 04:11:17 +00:00
|
|
|
$idHasNoKey = !isset($read['tables']['non_conventional']['id']['key']);
|
2017-03-06 20:58:03 +00:00
|
|
|
$this->assertTrue($idHasNoKey, 'id key should not be set');
|
2017-03-04 05:51:20 +00:00
|
|
|
}
|
|
|
|
|
2009-10-03 16:41:14 +00:00
|
|
|
/**
|
|
|
|
* test that tables are generated correctly
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGenerateTable() {
|
2010-09-21 02:35:33 +00:00
|
|
|
$posts = array(
|
2009-10-03 16:41:14 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'title' => array('type' => 'string', 'null' => false),
|
|
|
|
'body' => array('type' => 'text', 'null' => true, '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)),
|
|
|
|
);
|
2010-09-21 02:35:33 +00:00
|
|
|
$result = $this->Schema->generateTable('posts', $posts);
|
2011-11-21 04:00:58 +00:00
|
|
|
$this->assertRegExp('/public \$posts/', $result);
|
2012-09-20 03:21:26 +00:00
|
|
|
|
|
|
|
$posts = array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'title' => array('type' => 'string', 'null' => false),
|
|
|
|
'body' => array('type' => 'text', 'null' => true, '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),
|
|
|
|
'MyFtIndex' => array('column' => array('title', 'body'), 'type' => 'fulltext')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$result = $this->Schema->generateTable('fields', $posts);
|
|
|
|
$this->assertRegExp('/public \$fields/', $result);
|
2013-09-25 18:58:29 +00:00
|
|
|
$this->assertRegExp('/\'type\' \=\> \'fulltext\'/', $result);
|
2009-10-03 16:41:14 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2016-10-02 16:23:05 +00:00
|
|
|
/**
|
|
|
|
* test that tables with unsupported name are not getting through
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGenerateInvalidTable() {
|
|
|
|
$invalidTableName = 'invalid name !@#$%^&*()';
|
|
|
|
$expectedException = "Invalid table name '{$invalidTableName}'";
|
|
|
|
try{
|
|
|
|
$this->Schema->generateTable($invalidTableName, array());
|
|
|
|
$this->fail("Expected exception \"{$expectedException}\" not thrown");
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->assertEquals($expectedException, $e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testSchemaWrite method
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaWrite() {
|
2012-03-19 01:20:17 +00:00
|
|
|
$write = $this->Schema->write(array(
|
|
|
|
'name' => 'MyOtherApp',
|
|
|
|
'tables' => $this->Schema->tables,
|
|
|
|
'path' => TMP . 'tests'
|
|
|
|
));
|
|
|
|
$file = file_get_contents(TMP . 'tests' . DS . 'schema.php');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($write, $file);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-19 01:20:17 +00:00
|
|
|
require_once TMP . 'tests' . DS . 'schema.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
$OtherSchema = new MyOtherAppSchema();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Schema->tables, $OtherSchema->tables);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testSchemaComparison method
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaComparison() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$New = new MyAppSchema();
|
|
|
|
$compare = $New->compare($this->Schema);
|
|
|
|
$expected = array(
|
2008-10-01 15:27:29 +00:00
|
|
|
'comments' => array(
|
|
|
|
'add' => array(
|
2011-09-16 13:28:28 +00:00
|
|
|
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'after' => 'id'),
|
|
|
|
'title' => array('type' => 'string', 'null' => false, 'length' => 100, 'after' => 'user_id'),
|
2008-10-01 15:27:29 +00:00
|
|
|
),
|
2009-10-03 20:08:54 +00:00
|
|
|
'drop' => array(
|
|
|
|
'article_id' => array('type' => 'integer', 'null' => false),
|
2009-10-05 00:53:49 +00:00
|
|
|
'tableParameters' => array(),
|
2009-10-03 20:08:54 +00:00
|
|
|
),
|
2008-10-01 15:27:29 +00:00
|
|
|
'change' => array(
|
2009-10-05 00:53:49 +00:00
|
|
|
'comment' => array('type' => 'text', 'null' => false, 'default' => null),
|
2008-10-01 15:27:29 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'posts' => array(
|
2009-10-05 00:53:49 +00:00
|
|
|
'add' => array(
|
2011-09-16 13:28:28 +00:00
|
|
|
'summary' => array('type' => 'text', 'null' => true, 'after' => 'body'),
|
2009-10-05 00:53:49 +00:00
|
|
|
),
|
|
|
|
'drop' => array(
|
|
|
|
'tableParameters' => array(),
|
|
|
|
),
|
2008-10-01 15:27:29 +00:00
|
|
|
'change' => array(
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
|
|
|
|
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
|
2010-06-07 04:35:40 +00:00
|
|
|
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1)
|
2008-10-01 15:27:29 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $compare);
|
2010-08-02 03:22:46 +00:00
|
|
|
$this->assertNull($New->getVar('comments'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('bar'), $New->getVar('_foo'));
|
2010-05-29 15:06:36 +00:00
|
|
|
|
|
|
|
$tables = array(
|
|
|
|
'missing' => array(
|
|
|
|
'categories' => array(
|
2012-03-19 01:20:17 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'),
|
|
|
|
'created' => array('type' => 'datetime', 'null' => false, 'default' => null),
|
|
|
|
'modified' => array('type' => 'datetime', 'null' => false, 'default' => null),
|
|
|
|
'name' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 100),
|
2010-05-29 15:06:36 +00:00
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
|
|
|
|
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ratings' => array(
|
2012-03-19 01:20:17 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'),
|
|
|
|
'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => null),
|
|
|
|
'model' => array('type' => 'varchar', 'null' => false, 'default' => null),
|
|
|
|
'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => null),
|
|
|
|
'created' => array('type' => 'datetime', 'null' => false, 'default' => null),
|
|
|
|
'modified' => array('type' => 'datetime', 'null' => false, 'default' => null),
|
2010-05-29 15:06:36 +00:00
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
|
|
|
|
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$compare = $New->compare($this->Schema, $tables);
|
|
|
|
$expected = array(
|
|
|
|
'ratings' => array(
|
2013-04-03 15:37:09 +00:00
|
|
|
'create' => array(
|
2012-03-19 01:20:17 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'),
|
2013-04-03 15:37:09 +00:00
|
|
|
'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => null),
|
|
|
|
'model' => array('type' => 'varchar', 'null' => false, 'default' => null),
|
|
|
|
'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => null),
|
|
|
|
'created' => array('type' => 'datetime', 'null' => false, 'default' => null),
|
|
|
|
'modified' => array('type' => 'datetime', 'null' => false, 'default' => null),
|
2010-05-29 15:06:36 +00:00
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
|
|
|
|
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $compare);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-10-28 03:03:31 +00:00
|
|
|
/**
|
|
|
|
* test comparing '' and null and making sure they are different.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCompareEmptyStringAndNull() {
|
2010-11-13 04:05:44 +00:00
|
|
|
$One = new CakeSchema(array(
|
2010-10-28 03:03:31 +00:00
|
|
|
'posts' => array(
|
2012-03-19 01:20:17 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'),
|
2010-10-28 03:03:31 +00:00
|
|
|
'name' => array('type' => 'string', 'null' => false, 'default' => '')
|
|
|
|
)
|
|
|
|
));
|
2010-11-13 04:05:44 +00:00
|
|
|
$Two = new CakeSchema(array(
|
2010-10-28 03:03:31 +00:00
|
|
|
'posts' => array(
|
2012-03-19 01:20:17 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'),
|
2010-10-28 03:03:31 +00:00
|
|
|
'name' => array('type' => 'string', 'null' => false, 'default' => null)
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$compare = $One->compare($Two);
|
|
|
|
$expected = array(
|
|
|
|
'posts' => array(
|
|
|
|
'change' => array(
|
|
|
|
'name' => array('type' => 'string', 'null' => false, 'default' => null)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $compare);
|
2010-10-28 03:03:31 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 00:53:49 +00:00
|
|
|
/**
|
|
|
|
* Test comparing tableParameters and indexes.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTableParametersAndIndexComparison() {
|
2009-10-05 00:53:49 +00:00
|
|
|
$old = array(
|
|
|
|
'posts' => array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'title' => array('type' => 'string', 'null' => false),
|
|
|
|
'indexes' => array(
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => true)
|
|
|
|
),
|
|
|
|
'tableParameters' => array(
|
|
|
|
'charset' => 'latin1',
|
|
|
|
'collate' => 'latin1_general_ci'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'comments' => array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
|
|
|
|
'comment' => array('type' => 'text'),
|
|
|
|
'indexes' => array(
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => true),
|
|
|
|
'post_id' => array('column' => 'post_id'),
|
|
|
|
),
|
|
|
|
'tableParameters' => array(
|
|
|
|
'engine' => 'InnoDB',
|
|
|
|
'charset' => 'latin1',
|
|
|
|
'collate' => 'latin1_general_ci'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$new = array(
|
|
|
|
'posts' => array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'title' => array('type' => 'string', 'null' => false),
|
|
|
|
'indexes' => array(
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => true),
|
|
|
|
'author_id' => array('column' => 'author_id'),
|
|
|
|
),
|
|
|
|
'tableParameters' => array(
|
|
|
|
'charset' => 'utf8',
|
|
|
|
'collate' => 'utf8_general_ci',
|
|
|
|
'engine' => 'MyISAM'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'comments' => array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
|
|
|
|
'comment' => array('type' => 'text'),
|
|
|
|
'indexes' => array(
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => true),
|
|
|
|
),
|
|
|
|
'tableParameters' => array(
|
|
|
|
'charset' => 'utf8',
|
|
|
|
'collate' => 'utf8_general_ci'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$compare = $this->Schema->compare($old, $new);
|
|
|
|
$expected = array(
|
|
|
|
'posts' => array(
|
|
|
|
'add' => array(
|
|
|
|
'indexes' => array('author_id' => array('column' => 'author_id')),
|
|
|
|
),
|
|
|
|
'change' => array(
|
|
|
|
'tableParameters' => array(
|
2010-02-15 17:46:18 +00:00
|
|
|
'charset' => 'utf8',
|
2009-10-05 00:53:49 +00:00
|
|
|
'collate' => 'utf8_general_ci',
|
|
|
|
'engine' => 'MyISAM'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'comments' => array(
|
|
|
|
'drop' => array(
|
|
|
|
'indexes' => array('post_id' => array('column' => 'post_id')),
|
|
|
|
),
|
|
|
|
'change' => array(
|
|
|
|
'tableParameters' => array(
|
2010-02-15 17:46:18 +00:00
|
|
|
'charset' => 'utf8',
|
2009-10-05 00:53:49 +00:00
|
|
|
'collate' => 'utf8_general_ci',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2011-11-13 01:43:55 +00:00
|
|
|
$this->assertEquals($expected, $compare);
|
2009-10-05 00:53:49 +00:00
|
|
|
}
|
|
|
|
|
2012-03-12 14:12:44 +00:00
|
|
|
/**
|
|
|
|
* Test comparing with field changed from VARCHAR to DATETIME
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCompareVarcharToDatetime() {
|
|
|
|
$old = array(
|
|
|
|
'posts' => array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'title' => array('type' => 'string', 'null' => true, 'length' => 45),
|
|
|
|
'indexes' => array(
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => true)
|
|
|
|
),
|
|
|
|
'tableParameters' => array(
|
|
|
|
'charset' => 'latin1',
|
|
|
|
'collate' => 'latin1_general_ci'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$new = array(
|
|
|
|
'posts' => array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'title' => array('type' => 'datetime', 'null' => false),
|
|
|
|
'indexes' => array(
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => true)
|
|
|
|
),
|
|
|
|
'tableParameters' => array(
|
|
|
|
'charset' => 'latin1',
|
|
|
|
'collate' => 'latin1_general_ci'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$compare = $this->Schema->compare($old, $new);
|
|
|
|
$expected = array(
|
|
|
|
'posts' => array(
|
|
|
|
'change' => array(
|
|
|
|
'title' => array(
|
|
|
|
'type' => 'datetime',
|
|
|
|
'null' => false,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $compare, 'Invalid SQL, datetime does not have length');
|
|
|
|
}
|
|
|
|
|
2016-07-26 20:39:09 +00:00
|
|
|
/**
|
|
|
|
* Test comparing with field length/limit changed from some non-default value to the default
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCompareLimitToDefault() {
|
|
|
|
$old = array(
|
|
|
|
'posts' => array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 1, 'key' => 'primary'),
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => false, 'limit' => 5),
|
|
|
|
'title' => array('type' => 'string', 'null' => true, 'length' => 45),
|
|
|
|
'indexes' => array(
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => true)
|
|
|
|
),
|
|
|
|
'tableParameters' => array(
|
|
|
|
'charset' => 'latin1',
|
|
|
|
'collate' => 'latin1_general_ci'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$new = array(
|
|
|
|
'posts' => array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => false),
|
|
|
|
'title' => array('type' => 'varchar', 'null' => true),
|
|
|
|
'indexes' => array(
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => true)
|
|
|
|
),
|
|
|
|
'tableParameters' => array(
|
|
|
|
'charset' => 'latin1',
|
|
|
|
'collate' => 'latin1_general_ci'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$compare = $this->Schema->compare($old, $new);
|
|
|
|
$expected = array(
|
|
|
|
'posts' => array(
|
|
|
|
'change' => array(
|
|
|
|
'id' => array(
|
|
|
|
'type' => 'integer',
|
|
|
|
'null' => false,
|
|
|
|
'key' => 'primary'
|
|
|
|
),
|
|
|
|
'author_id' => array(
|
|
|
|
'type' => 'integer',
|
|
|
|
'null' => false,
|
|
|
|
),
|
|
|
|
'title' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'null' => true,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $compare, 'Invalid SQL, field length change not detected');
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testSchemaLoading method
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaLoading() {
|
2010-10-17 19:55:04 +00:00
|
|
|
$Other = $this->Schema->load(array('name' => 'MyOtherApp', 'path' => TMP . 'tests'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('MyOtherApp', $Other->name);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($Other->tables, $this->Schema->tables);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-04 17:32:33 +00:00
|
|
|
/**
|
|
|
|
* test loading schema files inside of plugins.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaLoadingFromPlugin() {
|
2009-10-04 17:32:33 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2009-10-04 17:32:33 +00:00
|
|
|
));
|
2011-05-10 04:40:15 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
2010-10-17 19:55:04 +00:00
|
|
|
$Other = $this->Schema->load(array('name' => 'TestPluginApp', 'plugin' => 'TestPlugin'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('TestPluginApp', $Other->name);
|
|
|
|
$this->assertEquals(array('test_plugin_acos'), array_keys($Other->tables));
|
2009-10-04 17:32:33 +00:00
|
|
|
|
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testSchemaCreateTable method
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaCreateTable() {
|
2010-10-17 19:55:04 +00:00
|
|
|
$db = ConnectionManager::getDataSource('test');
|
2008-08-07 15:36:26 +00:00
|
|
|
$db->cacheSources = false;
|
2009-03-19 21:10:13 +00:00
|
|
|
|
2010-10-17 19:55:04 +00:00
|
|
|
$Schema = new CakeSchema(array(
|
2010-09-20 02:58:30 +00:00
|
|
|
'connection' => 'test',
|
2008-12-17 03:36:27 +00:00
|
|
|
'testdescribes' => array(
|
|
|
|
'id' => array('type' => 'integer', 'key' => 'primary'),
|
|
|
|
'int_null' => array('type' => 'integer', 'null' => true),
|
|
|
|
'int_not_null' => array('type' => 'integer', 'null' => false),
|
|
|
|
),
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$sql = $db->createSchema($Schema);
|
2009-03-19 21:10:13 +00:00
|
|
|
|
2008-12-17 03:36:27 +00:00
|
|
|
$col = $Schema->tables['testdescribes']['int_null'];
|
|
|
|
$col['name'] = 'int_null';
|
|
|
|
$column = $this->db->buildColumn($col);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/' . preg_quote($column, '/') . '/', $sql);
|
2009-03-19 21:10:13 +00:00
|
|
|
|
2008-12-17 03:36:27 +00:00
|
|
|
$col = $Schema->tables['testdescribes']['int_not_null'];
|
|
|
|
$col['name'] = 'int_not_null';
|
|
|
|
$column = $this->db->buildColumn($col);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/' . preg_quote($column, '/') . '/', $sql);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|