Updating Model test to reflect TreeBehavior changes, adding association support to Model::getColumnType()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7005 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-05-22 12:56:41 +00:00
parent be63f26e78
commit 5def68bf30
3 changed files with 33 additions and 8 deletions

View file

@ -873,6 +873,14 @@ class Model extends Overloadable {
*/ */
function getColumnType($column) { function getColumnType($column) {
$cols = $this->schema(); $cols = $this->schema();
$model = null;
if (strpos($column, '.')) {
list($model, $column) = explode('.', $column);
}
if ($model != $this->alias && isset($this->{$model})) {
return $this->{$model}->getColumnType($column);
}
if (isset($cols[$column]) && isset($cols[$column]['type'])) { if (isset($cols[$column]) && isset($cols[$column]['type'])) {
return $cols[$column]['type']; return $cols[$column]['type'];
} }

View file

@ -37,6 +37,7 @@ require_once dirname(__FILE__) . DS . 'models.php';
* @subpackage cake.tests.cases.libs.model * @subpackage cake.tests.cases.libs.model
*/ */
class ModelTest extends CakeTestCase { class ModelTest extends CakeTestCase {
var $autoFixtures = false; var $autoFixtures = false;
var $fixtures = array( var $fixtures = array(
@ -77,6 +78,19 @@ class ModelTest extends CakeTestCase {
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
function testColumnTypeFetching() {
$model =& new Test();
$this->assertEqual($model->getColumnType('id'), 'integer');
$this->assertEqual($model->getColumnType('notes'), 'text');
$this->assertEqual($model->getColumnType('updated'), 'datetime');
$this->assertEqual($model->getColumnType('unknown'), 'string');
$model =& new Article();
$this->assertEqual($model->getColumnType('User.created'), 'datetime');
$this->assertEqual($model->getColumnType('Tag.id'), 'integer');
$this->assertEqual($model->getColumnType('Article.id'), 'integer');
}
function testMultipleBelongsToWithSameClass() { function testMultipleBelongsToWithSameClass() {
$this->loadFixtures('DeviceType', 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', 'Document', 'Device', 'DocumentDirectory'); $this->loadFixtures('DeviceType', 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', 'Document', 'Device', 'DocumentDirectory');
$DeviceType =& new DeviceType(); $DeviceType =& new DeviceType();
@ -3848,7 +3862,10 @@ class ModelTest extends CakeTestCase {
$this->assertTrue(is_object($TestModel->Behaviors->Tree)); $this->assertTrue(is_object($TestModel->Behaviors->Tree));
$this->assertEqual($TestModel->Behaviors->attached(), array('Tree')); $this->assertEqual($TestModel->Behaviors->attached(), array('Tree'));
$expected = array('parent' => 'parent_id', 'left' => 'left_field', 'right' => 'right_field', 'scope' => '1 = 1', 'type' => 'nested', '__parentChange' => false); $expected = array(
'parent' => 'parent_id', 'left' => 'left_field', 'right' => 'right_field', 'scope' => '1 = 1',
'type' => 'nested', '__parentChange' => false, 'recursive' => -1
);
$this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected); $this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected);
$expected['enabled'] = false; $expected['enabled'] = false;

View file

@ -61,13 +61,13 @@ class TestAlias extends Model {
var $name = 'TestAlias'; var $name = 'TestAlias';
var $alias = 'TestAlias'; var $alias = 'TestAlias';
var $_schema = array( var $_schema = array(
'id'=> array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key'=>'primary'), 'id'=> array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key'=>'primary'),
'name'=> array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'name'=> array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'email'=> array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), 'email'=> array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'notes'=> array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''), 'notes'=> array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''),
'created'=> array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'created'=> array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) 'updated'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
); );
} }
/** /**