diff --git a/tests/CacheTestCase.php b/tests/CacheTestCase.php index 82bdeeb3a..389a56e1d 100644 --- a/tests/CacheTestCase.php +++ b/tests/CacheTestCase.php @@ -53,7 +53,7 @@ class Doctrine_Cache_TestCase extends Doctrine_UnitTestCase $resultSet = array(array('name' => 'John'), array('name' => 'Arnold')); - $this->cache->getDriver()->save(md5($query), $resultSet); + $this->cache->getDriver()->save(md5(serialize($query)), $resultSet); $count = $this->dbh->getAdapter()->count(); diff --git a/tests/Export/MysqlTestCase.php b/tests/Export/MysqlTestCase.php index b7fd06a97..3e79532de 100644 --- a/tests/Export/MysqlTestCase.php +++ b/tests/Export/MysqlTestCase.php @@ -253,6 +253,28 @@ class Doctrine_Export_Mysql_TestCase extends Doctrine_UnitTestCase $this->assertEqual($this->adapter->pop(), 'CREATE TABLE sometable (id INT UNSIGNED AUTO_INCREMENT, content VARCHAR(4), FULLTEXT INDEX myindex (content DESC), PRIMARY KEY(id)) ENGINE = MYISAM'); } + public function testExportSupportsIndexes() + { + $r = new MysqlIndexTestRecord; + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mysql_index_test_record (id BIGINT AUTO_INCREMENT, name TEXT, code INT, content TEXT, FULLTEXT INDEX content_idx (content), UNIQUE INDEX namecode_idx (name, code), PRIMARY KEY(id)) ENGINE = MYISAM'); + } +} +class MysqlIndexTestRecord extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('name', 'string', null); + $this->hasColumn('code', 'integer', 4); + $this->hasColumn('content', 'string', 4000); + + $this->index('content', array('fields' => 'content', 'type' => 'fulltext')); + $this->index('namecode', array('fields' => array('name', 'code'), + 'type' => 'unique')); + + $this->option('type', 'MYISAM'); + + } } class MysqlTestRecord extends Doctrine_Record { diff --git a/tests/ExportTestCase.php b/tests/ExportTestCase.php index e64260748..c70d485de 100644 --- a/tests/ExportTestCase.php +++ b/tests/ExportTestCase.php @@ -30,8 +30,10 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Export_TestCase extends Doctrine_UnitTestCase { - public function testCreateTableThrowsExceptionWithoutValidTableName() { +class Doctrine_Export_TestCase extends Doctrine_UnitTestCase +{ + public function testCreateTableThrowsExceptionWithoutValidTableName() + { try { $this->export->createTable(0, array(), array()); @@ -40,7 +42,8 @@ class Doctrine_Export_TestCase extends Doctrine_UnitTestCase { $this->pass(); } } - public function testCreateTableThrowsExceptionWithEmptyFieldsArray() { + public function testCreateTableThrowsExceptionWithEmptyFieldsArray() + { try { $this->export->createTable('sometable', array(), array()); @@ -49,29 +52,34 @@ class Doctrine_Export_TestCase extends Doctrine_UnitTestCase { $this->pass(); } } - public function testDropConstraintExecutesSql() { + public function testDropConstraintExecutesSql() + { $this->export->dropConstraint('sometable', 'relevancy'); $this->assertEqual($this->adapter->pop(), 'ALTER TABLE sometable DROP CONSTRAINT relevancy_idx'); } - public function testCreateIndexExecutesSql() { + public function testCreateIndexExecutesSql() + { $this->export->createIndex('sometable', 'relevancy', array('fields' => array('title' => array(), 'content' => array()))); $this->assertEqual($this->adapter->pop(), 'CREATE INDEX relevancy_idx ON sometable (title, content)'); } - public function testDropIndexExecutesSql() { + public function testDropIndexExecutesSql() + { $this->export->dropIndex('sometable', 'relevancy'); $this->assertEqual($this->adapter->pop(), 'DROP INDEX relevancy_idx'); } - public function testDropTableExecutesSql() { + public function testDropTableExecutesSql() + { $this->export->dropTable('sometable'); $this->assertEqual($this->adapter->pop(), 'DROP TABLE sometable'); } - public function testRecordIsExportedProperly() { - + public function testRecordIsExportedProperly() + { + } } ?> diff --git a/tests/Query/JoinTestCase.php b/tests/Query/JoinTestCase.php index 8e8d555db..4ff321317 100644 --- a/tests/Query/JoinTestCase.php +++ b/tests/Query/JoinTestCase.php @@ -30,41 +30,42 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase +class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase { - public function prepareTables() - { - } - public function prepareData() - { + public function prepareTables() + { } - public function testInitData() + public function prepareData() + { + } + + public function testInitData() { $c = new Record_Country(); - + $c->name = 'Some country'; $c->City[0]->name = 'City 1'; $c->City[1]->name = 'City 2'; $c->City[2]->name = 'City 3'; - + $c->City[0]->District->name = 'District 1'; $c->City[2]->District->name = 'District 2'; - + $c->save(); - + $this->connection->clear(); } - public function testRecordHydrationWorksWithDeeplyNestedStructures() + public function testRecordHydrationWorksWithDeeplyNestedStructures() { $q = new Doctrine_Query(); - + $q->select('c.*, c2.*, d.*') ->from('Record_Country c')->leftJoin('c.City c2')->leftJoin('c2.District d') ->where('c.id = ?', array(1)); - + $this->assertEqual($q->getQuery(), "SELECT r.id AS r__id, r.name AS r__name, r2.id AS r2__id, r2.name AS r2__name, r2.country_id AS r2__country_id, r2.district_id AS r2__district_id, r3.id AS r3__id, r3.name AS r3__name FROM record__country r LEFT JOIN record__city r2 ON r.id = r2.country_id LEFT JOIN record__district r3 ON r2.district_id = r3.id WHERE r.id = ?"); - + $countries = $q->execute(); $c = $countries[0]; $this->assertEqual($c->City[0]->name, 'City 1'); @@ -74,7 +75,7 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase $this->assertEqual($c->City[0]->District->name, 'District 1'); $this->assertEqual($c->City[2]->District->name, 'District 2'); } - public function testManyToManyJoinUsesProperTableAliases() + public function testManyToManyJoinUsesProperTableAliases() { $q = new Doctrine_Query(); @@ -82,4 +83,23 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e INNER JOIN groupuser g ON e.id = g.user_id INNER JOIN entity e2 ON e2.id = g.group_id WHERE (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))'); } + + public function testSelfReferentialAssociationJoinsAreSupported() + { + $q = new Doctrine_Query(); + + $q->select('e.name')->from('Entity e INNER JOIN e.Entity e2'); + + $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e INNER JOIN entity_reference e3 ON e.id = e3.entity1 OR e.id = e3.entity2 INNER JOIN entity e2 ON e2.id = e3.entity2 OR e2.id = e3.entity1'); + } + /** + public function testSelfReferentialNestJoin() + { + $nest = new NestTest(); + $rel = $nest->getTable()->getRelation('Parents'); + + $this->assertEqual($rel->getLocal(), 'parent_id'); + $this->assertTrue($rel instanceof Doctrine_Association); + } + */ } diff --git a/tests/TableTestCase.php b/tests/TableTestCase.php index 03f3e73c6..3de220118 100644 --- a/tests/TableTestCase.php +++ b/tests/TableTestCase.php @@ -119,7 +119,7 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase { $this->assertTrue($this->objTable->getComponentName() == "User"); } public function testGetTableName() { - $this->assertTrue($this->objTable->getTableName() == "entity"); + $this->assertTrue($this->objTable->tableName == "entity"); } public function testGetConnection() { $this->assertTrue($this->objTable->getConnection() instanceof Doctrine_Connection); @@ -128,9 +128,9 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase { $this->assertTrue($this->objTable->getData() == array()); } public function testSetSequenceName() { - $this->objTable->setSequenceName("test-seq"); - $this->assertEqual($this->objTable->getSequenceName(),"test-seq"); - $this->objTable->setSequenceName(null); + $this->objTable->sequenceName = "test-seq"; + $this->assertEqual($this->objTable->sequenceName, "test-seq"); + $this->objTable->sequenceName = null; } public function testCreate() { $record = $this->objTable->create(); diff --git a/tests/classes.php b/tests/classes.php index c8c23185b..cbea453fe 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -584,5 +584,22 @@ class PackageVersionNotes extends Doctrine_Record { $this->hasOne('PackageVersion', 'PackageVersionNotes.package_version_id'); } } - +class NestTest extends Doctrine_Record +{ + public function setTableDefinition() { + $this->hasColumn('name', 'string'); + } + public function setUp() + { + $this->hasMany('NestTest as Parents', 'NestReference.parent_id'); + $this->hasMany('NestTest as Children', 'NestReference.child_id'); + } +} +class NestReference extends Doctrine_Record +{ + public function setTableDefinition() { + $this->hasColumn('parent_id', 'integer', 4, 'primary'); + $this->hasColumn('child_id', 'integer', 4, 'primary'); + } +} ?>