From a108327d2022109fd710c15dfcbed3384aac5d84 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 19 Jun 2007 19:02:28 +0000 Subject: [PATCH] --- tests/Export/RecordTestCase.php | 12 ++++++++++ tests/Export/_files2/model.php | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/Export/_files2/model.php diff --git a/tests/Export/RecordTestCase.php b/tests/Export/RecordTestCase.php index 0f8ebf093..d92a7c53e 100644 --- a/tests/Export/RecordTestCase.php +++ b/tests/Export/RecordTestCase.php @@ -86,6 +86,17 @@ class Doctrine_Export_Record_TestCase extends Doctrine_UnitTestCase $this->assertEqual($sql[0], 'CREATE TABLE mysql_group (id BIGINT AUTO_INCREMENT, name TEXT, PRIMARY KEY(id)) ENGINE = INNODB'); } + public function testExportModelFromDirectory() + { + Doctrine::export(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files2'); + + $this->assertEqual($this->adapter->pop(), 'COMMIT'); + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category (id BIGINT AUTO_INCREMENT, created DATETIME, parent BIGINT, position MEDIUMINT, active BIGINT, INDEX index_parent_idx (parent), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB'); + $this->assertEqual($this->adapter->pop(), 'ALTER TABLE cms__category ADD CONSTRAINT FOREIGN KEY (category_id) REFERENCES cms__category_languages(id) ON DELETE CASCADE'); + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category_languages (id BIGINT AUTO_INCREMENT, name TEXT, category_id BIGINT, language_id BIGINT, INDEX index_category_idx (category_id), INDEX index_language_idx (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB'); + $this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION'); + + } } class ForeignKeyTest extends Doctrine_Record { @@ -172,3 +183,4 @@ class MysqlTestRecord extends Doctrine_Record $this->option('type', 'INNODB'); } } + diff --git a/tests/Export/_files2/model.php b/tests/Export/_files2/model.php new file mode 100644 index 000000000..57f8bd131 --- /dev/null +++ b/tests/Export/_files2/model.php @@ -0,0 +1,41 @@ +setAttribute(Doctrine::ATTR_COLL_KEY, 'language_id'); + $this->hasOne('Cms_Category as category', array('local' => 'category_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); + } + + public function setTableDefinition() + { + $this->hasColumn('name', 'string',256); + $this->hasColumn('category_id', 'integer',11); + $this->hasColumn('language_id', 'integer',11); + $this->option('collate', 'utf8_unicode_ci'); + $this->option('charset', 'utf8'); + $this->option('type', 'INNODB'); + $this->index('index_category', array('fields' => 'category_id')); + $this->index('index_language', array('fields' => 'language_id')); + } +} +class Cms_Category extends Doctrine_Record +{ + + public function setUp() + { + $this->ownsMany('Cms_CategoryLanguages as langs', array('local' => 'id', 'foreign' => 'category_id')); + } + + public function setTableDefinition() + { + $this->hasColumn('created', 'timestamp'); + $this->hasColumn('parent', 'integer', 11); + $this->hasColumn('position', 'integer', 3); + $this->hasColumn('active', 'integer', 11); + $this->option('collate', 'utf8_unicode_ci'); + $this->option('charset', 'utf8'); + $this->option('type', 'INNODB'); + $this->index('index_parent', array('fields' => 'parent')); + } +}