1
0
mirror of synced 2024-12-15 15:46:02 +03:00
doctrine2/tests/TableTestCase.php

173 lines
6.3 KiB
PHP
Raw Normal View History

2006-04-14 00:37:28 +04:00
<?php
require_once("UnitTestCase.php");
2006-04-14 00:37:28 +04:00
class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
2006-09-03 23:20:02 +04:00
public function prepareTables() {
$this->tables[] = "FieldNameTest";
parent::prepareTables();
}
2006-09-03 23:20:02 +04:00
public function testFieldConversion() {
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
$t = new FieldNameTest();
$t->someColumn = 'abc';
$t->someEnum = 'php';
$t->someInt = 1;
$t->someArray = array();
$obj = new StdClass();
$t->someObject = $obj;
$this->assertEqual($t->someColumn, 'abc');
$this->assertEqual($t->someEnum, 'php');
$this->assertEqual($t->someInt, 1);
$this->assertEqual($t->someArray, array());
$this->assertEqual($t->someObject, $obj);
$t->save();
$this->assertEqual($t->someColumn, 'abc');
$this->assertEqual($t->someEnum, 'php');
$this->assertEqual($t->someInt, 1);
$this->assertEqual($t->someArray, array());
$this->assertEqual($t->someObject, $obj);
2006-09-03 23:20:02 +04:00
$t->refresh();
$this->assertEqual($t->someColumn, 'abc');
$this->assertEqual($t->someEnum, 'php');
$this->assertEqual($t->someInt, 1);
$this->assertEqual($t->someArray, array());
$this->assertEqual($t->someObject, $obj);
$this->connection->clear();
$t = $this->connection->getTable('FieldNameTest')->find(1);
$this->assertEqual($t->someColumn, 'abc');
$this->assertEqual($t->someEnum, 'php');
$this->assertEqual($t->someInt, 1);
$this->assertEqual($t->someArray, array());
$this->assertEqual($t->someObject, $obj);
2006-09-13 01:36:36 +04:00
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
2006-09-03 23:20:02 +04:00
}
public function testBind() {
2006-08-22 03:20:33 +04:00
$table = $this->connection->getTable("User");
}
2006-05-17 21:58:40 +04:00
2006-04-23 12:12:01 +04:00
public function testGetIdentifier() {
2006-08-22 03:20:33 +04:00
$table = $this->connection->getTable("User");
2006-04-23 12:12:01 +04:00
}
2006-04-14 00:37:28 +04:00
public function testGetForeignKey() {
$fk = $this->objTable->getRelation("Group");
$this->assertTrue($fk instanceof Doctrine_Relation_Association);
2006-04-14 00:37:28 +04:00
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
2006-04-23 12:12:01 +04:00
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY_AGGREGATE);
2006-04-14 00:37:28 +04:00
$this->assertTrue($fk->getLocal() == "user_id");
$this->assertTrue($fk->getForeign() == "group_id");
$fk = $this->objTable->getRelation("Email");
$this->assertTrue($fk instanceof Doctrine_Relation_LocalKey);
2006-04-14 00:37:28 +04:00
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
2006-04-23 12:12:01 +04:00
$this->assertTrue($fk->getType() == Doctrine_Relation::ONE_COMPOSITE);
2006-04-14 00:37:28 +04:00
$this->assertTrue($fk->getLocal() == "email_id");
2006-04-23 12:12:01 +04:00
$this->assertTrue($fk->getForeign() == $fk->getTable()->getIdentifier());
2006-04-14 00:37:28 +04:00
$fk = $this->objTable->getRelation("Phonenumber");
$this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey);
2006-04-14 00:37:28 +04:00
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
2006-04-23 12:12:01 +04:00
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY_COMPOSITE);
$this->assertTrue($fk->getLocal() == $this->objTable->getIdentifier());
2006-04-14 00:37:28 +04:00
$this->assertTrue($fk->getForeign() == "entity_id");
2006-09-24 23:54:55 +04:00
2006-05-17 21:58:40 +04:00
2006-04-14 00:37:28 +04:00
}
public function testGetComponentName() {
$this->assertTrue($this->objTable->getComponentName() == "User");
}
public function testGetTableName() {
$this->assertTrue($this->objTable->getTableName() == "entity");
}
2006-08-22 03:20:33 +04:00
public function testGetConnection() {
$this->assertTrue($this->objTable->getConnection() instanceof Doctrine_Connection);
2006-04-14 00:37:28 +04:00
}
public function testGetData() {
$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);
}
public function testCreate() {
$record = $this->objTable->create();
$this->assertTrue($record instanceof Doctrine_Record);
$this->assertTrue($record->getState() == Doctrine_Record::STATE_TCLEAN);
}
public function testFind() {
$record = $this->objTable->find(4);
$this->assertTrue($record instanceof Doctrine_Record);
try {
$record = $this->objTable->find('4');
$this->assertTrue($record instanceof Doctrine_Record);
} catch(Exception $e) {
2006-10-15 21:24:35 +04:00
$this->assertTrue(false);
}
2006-04-14 00:37:28 +04:00
try {
$record = $this->objTable->find(123);
2006-10-15 21:24:35 +04:00
$this->assertTrue($record === false);
} catch(Exception $e) {
2006-10-15 21:24:35 +04:00
$this->assertTrue(false);
}
try {
$record = $this->objTable->find(null);
2006-10-15 21:24:35 +04:00
$this->assertTrue($record === false);
} catch(Exception $e) {
2006-10-15 21:24:35 +04:00
$this->assertTrue(false);
}
try {
$record = $this->objTable->find(false);
2006-10-15 21:24:35 +04:00
$this->assertTrue($record === false);
2006-04-14 00:37:28 +04:00
} catch(Exception $e) {
2006-10-15 21:24:35 +04:00
$this->assertTrue(false);
2006-04-14 00:37:28 +04:00
}
}
public function testFindAll() {
$users = $this->objTable->findAll();
$this->assertEqual($users->count(), 8);
2006-04-17 01:23:38 +04:00
$this->assertTrue($users instanceof Doctrine_Collection);
2006-04-14 00:37:28 +04:00
}
2006-09-03 23:20:02 +04:00
public function testFindByDql() {
$users = $this->objTable->findByDql("name LIKE '%Arnold%'");
2006-04-14 00:37:28 +04:00
$this->assertEqual($users->count(), 1);
2006-04-17 01:23:38 +04:00
$this->assertTrue($users instanceof Doctrine_Collection);
2006-04-14 00:37:28 +04:00
}
public function testGetProxy() {
$user = $this->objTable->getProxy(4);
$this->assertTrue($user instanceof Doctrine_Record);
try {
$record = $this->objTable->find(123);
} catch(Exception $e) {
$this->assertTrue($e instanceOf Doctrine_Find_Exception);
}
}
public function testGetColumns() {
$columns = $this->objTable->getColumns();
$this->assertTrue(is_array($columns));
}
public function testApplyInheritance() {
$this->assertEqual($this->objTable->applyInheritance("id = 3"), "id = 3 AND type = ?");
2006-04-14 00:37:28 +04:00
}
2006-04-14 00:37:28 +04:00
}
?>