2006-04-14 00:37:28 +04:00
|
|
|
<?php
|
2006-12-28 00:20:26 +03:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.phpdoctrine.com>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Doctrine_Table_TestCase
|
|
|
|
*
|
|
|
|
* @package Doctrine
|
|
|
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @category Object Relational Mapping
|
|
|
|
* @link www.phpdoctrine.com
|
|
|
|
* @since 1.0
|
|
|
|
* @version $Revision$
|
|
|
|
*/
|
2007-06-25 23:25:23 +04:00
|
|
|
class Doctrine_Table_TestCase extends Doctrine_UnitTestCase
|
2007-06-25 23:07:14 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
public function prepareTables()
|
|
|
|
{
|
|
|
|
$this->tables[] = 'FieldNameTest';
|
2007-07-06 03:25:36 +04:00
|
|
|
parent::prepareTables();
|
2006-09-03 23:20:02 +04:00
|
|
|
}
|
2006-09-17 19:44:10 +04:00
|
|
|
|
2007-06-25 23:07:14 +04:00
|
|
|
public function testFieldConversion()
|
|
|
|
{
|
2006-09-03 23:20:02 +04:00
|
|
|
$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-17 19:44:10 +04:00
|
|
|
|
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);
|
2007-06-25 23:07:14 +04:00
|
|
|
|
2006-09-03 23:20:02 +04:00
|
|
|
$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
|
|
|
}
|
2006-09-17 19:44:10 +04:00
|
|
|
|
2007-06-25 23:07:14 +04:00
|
|
|
public function testGetForeignKey()
|
|
|
|
{
|
2006-08-31 13:04:14 +04:00
|
|
|
$fk = $this->objTable->getRelation("Group");
|
2006-09-29 01:21:33 +04:00
|
|
|
$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");
|
|
|
|
|
2006-08-31 13:04:14 +04:00
|
|
|
$fk = $this->objTable->getRelation("Email");
|
2006-09-29 01:21:33 +04:00
|
|
|
$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
|
|
|
|
|
|
|
|
2007-07-06 03:25:36 +04:00
|
|
|
$fk = $this->objTable->getRelation('Phonenumber');
|
2006-09-29 01:21:33 +04:00
|
|
|
$this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey);
|
2006-04-14 00:37:28 +04:00
|
|
|
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
|
2007-07-06 03:25:36 +04:00
|
|
|
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY);
|
2006-04-23 12:12:01 +04:00
|
|
|
$this->assertTrue($fk->getLocal() == $this->objTable->getIdentifier());
|
2007-07-06 03:25:36 +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
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
public function testGetComponentName()
|
|
|
|
{
|
2007-07-06 03:25:36 +04:00
|
|
|
$this->assertTrue($this->objTable->getComponentName() == 'User');
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testGetTableName()
|
|
|
|
{
|
2007-07-06 03:25:36 +04:00
|
|
|
$this->assertTrue($this->objTable->tableName == 'entity');
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testGetConnection()
|
|
|
|
{
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->assertTrue($this->objTable->getConnection() instanceof Doctrine_Connection);
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testGetData()
|
|
|
|
{
|
2006-04-14 00:37:28 +04:00
|
|
|
$this->assertTrue($this->objTable->getData() == array());
|
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testSetSequenceName()
|
|
|
|
{
|
2007-07-06 03:25:36 +04:00
|
|
|
$this->objTable->sequenceName = 'test-seq';
|
|
|
|
$this->assertEqual($this->objTable->sequenceName, 'test-seq');
|
2007-02-12 01:55:19 +03:00
|
|
|
$this->objTable->sequenceName = null;
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testCreate()
|
|
|
|
{
|
2006-04-14 00:37:28 +04:00
|
|
|
$record = $this->objTable->create();
|
|
|
|
$this->assertTrue($record instanceof Doctrine_Record);
|
2007-01-21 21:31:51 +03:00
|
|
|
$this->assertTrue($record->state() == Doctrine_Record::STATE_TCLEAN);
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testFind()
|
|
|
|
{
|
2006-04-14 00:37:28 +04:00
|
|
|
$record = $this->objTable->find(4);
|
|
|
|
$this->assertTrue($record instanceof Doctrine_Record);
|
|
|
|
|
2006-10-15 21:15:16 +04:00
|
|
|
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-10-15 21:15:16 +04:00
|
|
|
}
|
|
|
|
|
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);
|
2006-10-15 21:15:16 +04:00
|
|
|
} catch(Exception $e) {
|
2006-10-15 21:24:35 +04:00
|
|
|
$this->assertTrue(false);
|
2006-10-15 21:15:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$record = $this->objTable->find(null);
|
2006-10-15 21:24:35 +04:00
|
|
|
$this->assertTrue($record === false);
|
2006-10-15 21:15:16 +04:00
|
|
|
} catch(Exception $e) {
|
2006-10-15 21:24:35 +04:00
|
|
|
$this->assertTrue(false);
|
2006-10-15 21:15:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testFindAll()
|
|
|
|
{
|
2006-04-14 00:37:28 +04:00
|
|
|
$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
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testFindByDql()
|
|
|
|
{
|
2006-09-03 23:20:02 +04:00
|
|
|
$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
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testGetProxy()
|
|
|
|
{
|
2006-04-14 00:37:28 +04:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testGetColumns()
|
|
|
|
{
|
2006-04-14 00:37:28 +04:00
|
|
|
$columns = $this->objTable->getColumns();
|
|
|
|
$this->assertTrue(is_array($columns));
|
|
|
|
|
|
|
|
}
|
2007-06-25 23:07:14 +04:00
|
|
|
|
|
|
|
public function testApplyInheritance()
|
|
|
|
{
|
2006-04-15 21:42:24 +04:00
|
|
|
$this->assertEqual($this->objTable->applyInheritance("id = 3"), "id = 3 AND type = ?");
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
2006-09-17 19:44:10 +04:00
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
|
|
|
?>
|