2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Test for Schema database management
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2008-10-30 17:30:26 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5550
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
App::import('Core', 'Schema');
|
|
|
|
/**
|
|
|
|
* Test for Schema database management
|
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class MyAppSchema extends CakeSchema {
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'MyApp';
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* connection property
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'test_suite'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $connection = 'test_suite';
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
);
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
);
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function setup($version) {
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function teardown($version) {
|
|
|
|
}
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestAppSchema class
|
2008-06-27 05:14:52 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage 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 {
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'MyApp';
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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)),
|
|
|
|
);
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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)),
|
|
|
|
);
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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'),
|
2008-12-17 03:32:45 +00:00
|
|
|
'indexes' => array('posts_tag' => array('column' => array('tag_id', 'post_id'), 'unique' => 1))
|
2008-05-30 11:40:08 +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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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),
|
2008-10-01 15:27:29 +00:00
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true))
|
2008-05-30 11:40:08 +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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $datatypes = 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
|
|
|
'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2'),
|
2008-10-01 15:27:29 +00:00
|
|
|
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true))
|
2008-05-30 11:40:08 +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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function setup($version) {
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function teardown($version) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* SchmeaPost class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class SchemaPost extends CakeTestModel {
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'SchemaPost';
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $useTable = 'posts';
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $hasMany = array('SchemaComment');
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $hasAndBelongsToMany = array('SchemaTag');
|
|
|
|
}
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* SchemaComment class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class SchemaComment extends CakeTestModel {
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'SchemaComment';
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $useTable = 'comments';
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $belongsTo = array('SchemaPost');
|
|
|
|
}
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* SchemaTag class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class SchemaTag extends CakeTestModel {
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'SchemaTag';
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $useTable = 'tags';
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $hasAndBelongsToMany = array('SchemaPost');
|
|
|
|
}
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* SchemaDatatype class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class SchemaDatatype extends CakeTestModel {
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'SchemaDatatype';
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $useTable = 'datatypes';
|
|
|
|
}
|
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
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.model
|
2008-08-03 17:41:05 +00:00
|
|
|
*/
|
|
|
|
class Testdescribe extends CakeTestModel {
|
|
|
|
/**
|
|
|
|
* name property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
2008-08-03 17:41:05 +00:00
|
|
|
* @var string 'Testdescribe'
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $name = 'Testdescribe';
|
|
|
|
}
|
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
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class CakeSchemaTest extends CakeTestCase {
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $fixtures = array('core.post', 'core.tag', 'core.posts_tag', 'core.comment', 'core.datatype');
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-12-17 03:32:45 +00:00
|
|
|
function startTest() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Schema = new TestAppSchema();
|
|
|
|
}
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function tearDown() {
|
|
|
|
unset($this->Schema);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSchemaName() {
|
|
|
|
$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');
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSchemaRead() {
|
2008-12-17 03:32:45 +00:00
|
|
|
|
2008-10-01 15:27:29 +00:00
|
|
|
$read = $this->Schema->read(array(
|
|
|
|
'connection' => 'test_suite',
|
|
|
|
'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
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($read['tables'], $this->Schema->tables);
|
2008-10-01 15:27:29 +00:00
|
|
|
$this->assertIdentical(
|
|
|
|
$read['tables']['datatypes']['float_field'],
|
|
|
|
$this->Schema->tables['datatypes']['float_field']
|
|
|
|
);
|
|
|
|
|
2008-09-17 01:47:19 +00:00
|
|
|
$db =& ConnectionManager::getDataSource('test_suite');
|
|
|
|
$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']));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSchemaComparison() {
|
|
|
|
$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),
|
|
|
|
'title' => array('type' => 'string', 'null' => false, 'length' => 100)
|
|
|
|
),
|
|
|
|
'drop' => array('article_id' => array('type' => 'integer', 'null' => false)),
|
|
|
|
'change' => array(
|
|
|
|
'comment' => array('type' => 'text', 'null' => false, 'default' => null)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'posts' => array(
|
|
|
|
'add' => array('summary' => array('type' => 'text', 'null' => 1)),
|
|
|
|
'change' => array(
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
|
|
|
|
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
|
|
|
|
'published' => array(
|
|
|
|
'type' => 'string', 'null' => true, 'default' => 'Y', 'length' => '1'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($expected, $compare);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSchemaLoading() {
|
2008-08-04 16:53:39 +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);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSchemaCreateTable() {
|
|
|
|
$db =& ConnectionManager::getDataSource('test_suite');
|
2008-08-07 15:36:26 +00:00
|
|
|
$db->cacheSources = false;
|
2009-03-19 21:10:13 +00:00
|
|
|
|
2008-12-17 03:36:27 +00:00
|
|
|
$Schema =& new CakeSchema(array(
|
|
|
|
'connection' => 'test_suite',
|
|
|
|
'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
|
|
|
}
|
|
|
|
}
|
2008-08-07 15:36:26 +00:00
|
|
|
?>
|