From b0568e7ace3fe11ae74f3e3283d72434a905cd46 Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 26 Apr 2008 14:39:34 +0000 Subject: [PATCH] Adding schema introspection tests to Model git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6726 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/model.test.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 3cd8ea950..7914a0706 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -3649,6 +3649,27 @@ class ModelTest extends CakeTestCase { $this->assertEqual($this->Comment->displayField, 'id'); } + function testSchema() { + $this->Post = new Post(); + + $result = $this->Post->schema(); + $columns = array('id', 'author_id', 'title', 'body', 'published', 'created', 'updated'); + $this->assertEqual(array_keys($result), $columns); + + $types = array('integer', 'integer', 'string', 'text', 'string', 'datetime', 'datetime'); + $this->assertEqual(Set::extract(array_values($result), '{n}.type'), $types); + + $this->expectError('(Model::loadInfo) Deprecated - See Model::schema()'); + $result = $this->Post->loadInfo(); + $this->assertEqual($result->extract("{n}.name"), $columns); + $this->assertEqual($result->extract('{n}.type'), $types); + + $result = $this->Post->schema('body'); + $this->assertEqual($result['type'], 'text'); + $this->assertNull($this->Post->schema('foo')); + + $this->assertEqual($this->Post->getColumnTypes(), array_combine($columns, $types)); + } function testOldQuery() { $this->loadFixtures('Article');