mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
be63f26e78
commit
5def68bf30
3 changed files with 33 additions and 8 deletions
|
@ -873,6 +873,14 @@ class Model extends Overloadable {
|
|||
*/
|
||||
function getColumnType($column) {
|
||||
$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'])) {
|
||||
return $cols[$column]['type'];
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ require_once dirname(__FILE__) . DS . 'models.php';
|
|||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class ModelTest extends CakeTestCase {
|
||||
|
||||
var $autoFixtures = false;
|
||||
|
||||
var $fixtures = array(
|
||||
|
@ -77,6 +78,19 @@ class ModelTest extends CakeTestCase {
|
|||
$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() {
|
||||
$this->loadFixtures('DeviceType', 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', 'Document', 'Device', 'DocumentDirectory');
|
||||
$DeviceType =& new DeviceType();
|
||||
|
@ -3848,7 +3862,10 @@ class ModelTest extends CakeTestCase {
|
|||
$this->assertTrue(is_object($TestModel->Behaviors->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);
|
||||
|
||||
$expected['enabled'] = false;
|
||||
|
|
|
@ -61,13 +61,13 @@ class TestAlias extends Model {
|
|||
var $name = 'TestAlias';
|
||||
var $alias = 'TestAlias';
|
||||
var $_schema = array(
|
||||
'id'=> array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key'=>'primary'),
|
||||
'name'=> array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
||||
'email'=> array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
||||
'notes'=> array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''),
|
||||
'created'=> array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'updated'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||
);
|
||||
'id'=> array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key'=>'primary'),
|
||||
'name'=> array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
||||
'email'=> array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
||||
'notes'=> array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''),
|
||||
'created'=> array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'updated'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue