From 12d391fb42bece0cc80c2a6b3033b86e47bcde0f Mon Sep 17 00:00:00 2001 From: zYne Date: Sat, 10 Feb 2007 20:48:45 +0000 Subject: [PATCH] new tests --- tests/Export/PgsqlTestCase.php | 7 ++--- tests/Export/SqliteTestCase.php | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tests/Export/PgsqlTestCase.php b/tests/Export/PgsqlTestCase.php index 8bda821dc..77c1c7b38 100644 --- a/tests/Export/PgsqlTestCase.php +++ b/tests/Export/PgsqlTestCase.php @@ -13,10 +13,11 @@ class Doctrine_Export_Pgsql_TestCase extends Doctrine_UnitTestCase { $name = 'mytable'; $fields = array('id' => array('type' => 'integer', 'unsigned' => 1, 'autoincrement' => true)); + $options = array('primary' => array('id')); + + $this->export->createTable($name, $fields, $options); - $this->export->createTable($name, $fields); - - $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id SERIAL PRIMARY KEY)'); + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id SERIAL, PRIMARY KEY(id))'); } public function testCreateTableSupportsDefaultAttribute() { $name = 'mytable'; diff --git a/tests/Export/SqliteTestCase.php b/tests/Export/SqliteTestCase.php index 7939e8aa8..017dc65e5 100644 --- a/tests/Export/SqliteTestCase.php +++ b/tests/Export/SqliteTestCase.php @@ -46,5 +46,50 @@ class Doctrine_Export_Sqlite_TestCase extends Doctrine_UnitTestCase { $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (name CHAR(10), type INTEGER, PRIMARY KEY(name, type))'); } + public function testCreateTableSupportsIndexes() + { + $fields = array('id' => array('type' => 'integer', 'unsigned' => 1, 'autoincrement' => true, 'unique' => true), + 'name' => array('type' => 'string', 'length' => 4), + ); + + $options = array('primary' => array('id'), + 'indexes' => array('myindex' => array('fields' => array('id', 'name'))) + ); + + $this->export->createTable('sometable', $fields, $options); + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE sometable (id INTEGER UNSIGNED PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id, name))'); + } + public function testUnknownIndexSortingAttributeThrowsException() + { + $fields = array('id' => array('sorting' => 'ASC'), + 'name' => array('sorting' => 'unknown')); + + try { + $this->export->getIndexFieldDeclarationList($fields); + $this->fail(); + } catch(Doctrine_Export_Exception $e) { + $this->pass(); + } + } + public function testCreateTableSupportsIndexesWithCustomSorting() + { + $fields = array('id' => array('type' => 'integer', 'unsigned' => 1, 'autoincrement' => true, 'unique' => true), + 'name' => array('type' => 'string', 'length' => 4), + ); + + $options = array('primary' => array('id'), + 'indexes' => array('myindex' => array( + 'fields' => array( + 'id' => array('sorting' => 'ASC'), + 'name' => array('sorting' => 'DESC') + ) + )) + ); + + $this->export->createTable('sometable', $fields, $options); + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE sometable (id INTEGER UNSIGNED PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id ASC, name DESC))'); + } } ?>