2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Test for Schema database management
|
|
|
|
*
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, 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
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5550
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
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
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs
|
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
|
|
|
/**
|
|
|
|
* name property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'MyApp'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
* connection property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2010-09-20 02:58:30 +00:00
|
|
|
* @var string 'test'
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
protected $_foo = array('bar');
|
|
|
|
|
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
|
|
|
* @access public
|
|
|
|
* @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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function teardown($version) {
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-08-02 03:22:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getVar method
|
|
|
|
*
|
|
|
|
* @param string $var Name of var
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getVar($var) {
|
|
|
|
if (!isset($this->$var)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $this->$var;
|
|
|
|
}
|
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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.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
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'MyApp'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $comments = array(
|
2008-10-01 15:27:29 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0,'key' => 'primary'),
|
|
|
|
'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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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' => ''),
|
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
|
|
|
* @access public
|
|
|
|
* @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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function teardown($version) {
|
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
|
|
|
* SchmeaPost class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.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
|
|
|
/**
|
|
|
|
* name property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'SchemaPost'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'SchemaPost';
|
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
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'posts'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.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
|
|
|
/**
|
|
|
|
* name property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'SchemaComment'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'SchemaComment';
|
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
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'comments'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.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
|
|
|
/**
|
|
|
|
* name property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var string 'SchemaTag'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'SchemaTag';
|
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
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var string 'tags'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.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
|
|
|
/**
|
|
|
|
* name property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var string 'SchemaDatatype'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'SchemaDatatype';
|
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
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var string 'datatypes'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* testSchemaCreatTable will fail if listSources has already been called and
|
|
|
|
* 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
|
2008-11-08 02:58:37 +00:00
|
|
|
* @package
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.model
|
2008-08-03 17:41:05 +00:00
|
|
|
*/
|
|
|
|
class Testdescribe extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-03 17:41:05 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
2008-08-03 17:41:05 +00:00
|
|
|
* @var string 'Testdescribe'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'Testdescribe';
|
2008-08-03 17:41:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-02-15 17:46:18 +00:00
|
|
|
/**
|
|
|
|
* SchemaCrossDatabase class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.model
|
2010-02-15 17:46:18 +00:00
|
|
|
*/
|
|
|
|
class SchemaCrossDatabase extends CakeTestModel {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string 'SchemaCrossDatabase'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'SchemaCrossDatabase';
|
2010-02-15 17:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* useTable property
|
|
|
|
*
|
|
|
|
* @var string 'posts'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'cross_database';
|
2010-02-15 17:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* useDbConfig property
|
|
|
|
*
|
|
|
|
* @var string 'test2'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useDbConfig = 'test2';
|
2010-02-15 17:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SchemaCrossDatabaseFixture class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.model
|
2010-02-15 17:46:18 +00:00
|
|
|
*/
|
|
|
|
class SchemaCrossDatabaseFixture extends CakeTestFixture {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string 'CrossDatabase'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'CrossDatabase';
|
2010-02-15 17:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* table property
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $table = 'cross_database';
|
2010-02-15 17:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* fields property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-04-25 07:22:57 +00:00
|
|
|
/**
|
|
|
|
* SchemaPrefixAuthUser class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.model
|
2010-04-25 07:22:57 +00:00
|
|
|
*/
|
|
|
|
class SchemaPrefixAuthUser extends CakeTestModel {
|
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-06-26 16:29:20 +00:00
|
|
|
public $name = 'SchemaPrefixAuthUser';
|
2010-04-25 07:22:57 +00:00
|
|
|
/**
|
|
|
|
* table prefix
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-06-26 16:29:20 +00:00
|
|
|
public $tablePrefix = 'auth_';
|
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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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();
|
2011-05-28 21:08:22 +00:00
|
|
|
if (file_exists(TMP . 'tests' . DS .'schema.php')) {
|
|
|
|
unlink(TMP . 'tests' . DS .'schema.php');
|
|
|
|
}
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaName() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$Schema = new CakeSchema();
|
|
|
|
$this->assertEqual(strtolower($Schema->name), strtolower(APP_DIR));
|
|
|
|
|
|
|
|
Configure::write('App.dir', 'Some.name.with.dots');
|
|
|
|
$Schema = new CakeSchema();
|
|
|
|
$this->assertEqual($Schema->name, 'SomeNameWithDots');
|
|
|
|
|
|
|
|
Configure::write('App.dir', 'app');
|
|
|
|
}
|
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
|
|
|
* @access public
|
|
|
|
* @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) {
|
|
|
|
$this->assertEqual(array_keys($fields), array_keys($read['tables'][$table]));
|
2009-10-03 16:41:14 +00:00
|
|
|
}
|
|
|
|
|
2009-10-03 20:08:54 +00:00
|
|
|
$this->assertEqual(
|
2010-12-02 04:49:43 +00:00
|
|
|
$read['tables']['datatypes']['float_field']['length'],
|
|
|
|
$this->Schema->tables['datatypes']['float_field']['length']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEqual(
|
|
|
|
$read['tables']['datatypes']['float_field']['type'],
|
|
|
|
$this->Schema->tables['datatypes']['float_field']['type']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEqual(
|
|
|
|
$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-07-15 19:48:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testSchemaReadWithAppModel method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSchemaReadWithAppModel() {
|
|
|
|
$connections = ConnectionManager::enumConnectionObjects();
|
|
|
|
if (!empty($connections['default'])) {
|
|
|
|
$backup = $connections['default'];
|
|
|
|
ConnectionManager::drop('default');
|
|
|
|
}
|
|
|
|
ConnectionManager::create('default', $connections['test']);
|
|
|
|
try {
|
|
|
|
$read = $this->Schema->read(array(
|
|
|
|
'connection' => 'default',
|
|
|
|
'name' => 'TestApp',
|
|
|
|
'models' => array('AppModel')
|
|
|
|
));
|
|
|
|
if (!empty($backup)) {
|
|
|
|
ConnectionManager::drop('default');
|
|
|
|
ConnectionManager::create('default', $backup);
|
|
|
|
}
|
|
|
|
} catch(MissingTableException $mte) {
|
|
|
|
if (!empty($backup)) {
|
|
|
|
ConnectionManager::drop('default');
|
|
|
|
ConnectionManager::create('default', $backup);
|
|
|
|
}
|
|
|
|
$this->fail($mte->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-06-04 03:20:37 +00:00
|
|
|
|
2011-02-24 06:01:03 +00:00
|
|
|
/**
|
|
|
|
* testSchemaReadWithOddTablePrefix method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @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
|
|
|
$model = new SchemaPrefixAuthUser();
|
2010-04-25 07:22:57 +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-01-09 04:15:07 +00:00
|
|
|
$db = ConnectionManager::getDataSource('test');
|
2010-10-21 03:17:04 +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']));
|
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(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => 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() {
|
2010-02-15 17:46:18 +00:00
|
|
|
$config = new DATABASE_CONFIG();
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(
|
2010-02-15 17:46:18 +00:00
|
|
|
!isset($config->test) || !isset($config->test2),
|
2011-05-31 00:49:46 +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
|
|
|
);
|
|
|
|
|
2010-10-17 19:55:04 +00:00
|
|
|
$db2 = ConnectionManager::getDataSource('test2');
|
2010-02-15 17:46:18 +00:00
|
|
|
$fixture = new SchemaCrossDatabaseFixture();
|
|
|
|
$fixture->create($db2);
|
|
|
|
$fixture->insert($db2);
|
|
|
|
|
|
|
|
$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']));
|
|
|
|
|
|
|
|
$fixture->drop($db2);
|
|
|
|
}
|
|
|
|
|
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);
|
2009-10-03 16:41:14 +00:00
|
|
|
$this->assertPattern('/var \$posts/', $result);
|
|
|
|
}
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSchemaWrite() {
|
2008-08-04 16:53:39 +00:00
|
|
|
$write = $this->Schema->write(array('name' => 'MyOtherApp', 'tables' => $this->Schema->tables, 'path' => TMP . 'tests'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$file = file_get_contents(TMP . 'tests' . DS .'schema.php');
|
|
|
|
$this->assertEqual($write, $file);
|
|
|
|
|
|
|
|
require_once( TMP . 'tests' . DS .'schema.php');
|
|
|
|
$OtherSchema = new MyOtherAppSchema();
|
|
|
|
$this->assertEqual($this->Schema->tables, $OtherSchema->tables);
|
|
|
|
}
|
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
|
|
|
* @access public
|
|
|
|
* @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(
|
|
|
|
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
|
2009-10-05 00:53:49 +00:00
|
|
|
'title' => array('type' => 'string', 'null' => false, 'length' => 100),
|
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(
|
2010-06-07 04:35:40 +00:00
|
|
|
'summary' => array('type' => 'text', 'null' => true),
|
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
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($expected, $compare);
|
2010-08-02 03:22:46 +00:00
|
|
|
$this->assertNull($New->getVar('comments'));
|
|
|
|
$this->assertEqual($New->getVar('_foo'), array('bar'));
|
2010-05-29 15:06:36 +00:00
|
|
|
|
|
|
|
$tables = array(
|
|
|
|
'missing' => array(
|
|
|
|
'categories' => array(
|
|
|
|
'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),
|
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
|
|
|
|
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ratings' => array(
|
|
|
|
'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),
|
|
|
|
'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(
|
|
|
|
'add' => array(
|
|
|
|
'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),
|
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
|
|
|
|
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEqual($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(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
|
|
|
|
'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(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
|
|
|
|
'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)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $compare);
|
|
|
|
}
|
|
|
|
|
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',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEqual($compare, $expected);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
* @access public
|
|
|
|
* @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'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($Other->name, 'MyOtherApp');
|
|
|
|
$this->assertEqual($Other->tables, $this->Schema->tables);
|
|
|
|
}
|
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(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => 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'));
|
2009-10-04 17:32:33 +00:00
|
|
|
$this->assertEqual($Other->name, 'TestPluginApp');
|
2010-10-23 04:54:39 +00:00
|
|
|
$this->assertEqual(array_keys($Other->tables), array('test_plugin_acos'));
|
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
|
|
|
* @access public
|
|
|
|
* @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);
|
|
|
|
$this->assertPattern('/' . 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);
|
|
|
|
$this->assertPattern('/' . preg_quote($column, '/') . '/', $sql);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|