parent
e06f0be65d
commit
0835a57ce1
@ -512,9 +512,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
if($state == null) {
|
||||
return $this->_state;
|
||||
}
|
||||
$err = false;
|
||||
if(is_integer($state)) {
|
||||
|
||||
if($state >= 1 && $state <= 6)
|
||||
$this->_state = $state;
|
||||
else
|
||||
$err = true;
|
||||
|
||||
} elseif(is_string($state)) {
|
||||
$upper = strtoupper($state);
|
||||
switch($upper) {
|
||||
@ -526,10 +531,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
case 'DELETED':
|
||||
$this->_state = constant('Doctrine_Record::STATE_' . $upper);
|
||||
break;
|
||||
default:
|
||||
$err = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new Doctrine_Record_State_Exception('Unknown record state ' . $state);
|
||||
if($err)
|
||||
throw new Doctrine_Record_State_Exception('Unknown record state ' . $state);
|
||||
}
|
||||
/**
|
||||
* refresh
|
||||
|
@ -177,7 +177,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
$names = array_reverse($names);
|
||||
|
||||
// create database table
|
||||
if(method_exists($record,"setTableDefinition")) {
|
||||
if(method_exists($record, 'setTableDefinition')) {
|
||||
$record->setTableDefinition();
|
||||
|
||||
$this->columnCount = count($this->columns);
|
||||
@ -185,7 +185,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
if(isset($this->columns)) {
|
||||
|
||||
// get the declaring class of setTableDefinition method
|
||||
$method = new ReflectionMethod($this->options['name'],"setTableDefinition");
|
||||
$method = new ReflectionMethod($this->options['name'], 'setTableDefinition');
|
||||
$class = $method->getDeclaringClass();
|
||||
|
||||
if( ! isset($this->options['tableName']))
|
||||
@ -193,9 +193,17 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
|
||||
switch(count($this->primaryKeys)):
|
||||
case 0:
|
||||
$this->columns = array_merge(array("id" => array("integer", 20, array("autoincrement" => true, "primary" => true))), $this->columns);
|
||||
$this->primaryKeys[] = "id";
|
||||
$this->identifier = "id";
|
||||
$this->columns = array_merge(array('id' =>
|
||||
array('integer',
|
||||
20,
|
||||
array('autoincrement' => true,
|
||||
'primary' => true
|
||||
)
|
||||
)
|
||||
), $this->columns);
|
||||
|
||||
$this->primaryKeys[] = 'id';
|
||||
$this->identifier = 'id';
|
||||
$this->identifierType = Doctrine_Identifier::AUTO_INCREMENT;
|
||||
$this->columnCount++;
|
||||
break;
|
||||
@ -964,9 +972,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
*/
|
||||
final public function enumValue($field, $index) {
|
||||
if ($index instanceof Doctrine_Null)
|
||||
{
|
||||
return $index;
|
||||
}
|
||||
return $index;
|
||||
|
||||
return isset($this->options['enumMap'][$field][$index]) ? $this->options['enumMap'][$field][$index] : $index;
|
||||
}
|
||||
/**
|
||||
|
@ -343,10 +343,16 @@ $menu = array("Getting started" =>
|
||||
"Transactions" => array(
|
||||
"Introduction",
|
||||
"Unit of work",
|
||||
"Nesting",
|
||||
"Savepoints",
|
||||
"Locking strategies" =>
|
||||
array("Pessimistic locking",
|
||||
"Optimistic locking"),
|
||||
"Nesting"
|
||||
|
||||
"Lock modes",
|
||||
"Isolation levels",
|
||||
"Deadlocks",
|
||||
|
||||
),
|
||||
/**
|
||||
"Developer components" => array(
|
||||
@ -466,12 +472,12 @@ $menu = array("Getting started" =>
|
||||
if( ! file_exists("docs/$title - $k - $v2.php")) {
|
||||
$missing[0]++;
|
||||
$str .= " [ <font color='red'>doc</font> ] ";
|
||||
touch("docs/$title - $k - $v2.php");
|
||||
//touch("docs/$title - $k - $v2.php");
|
||||
}
|
||||
if( ! file_exists("codes/$title - $k - $v2.php")) {
|
||||
$missing[1]++;
|
||||
$str .= " [ <font color='red'>code</font> ] ";
|
||||
touch("codes/$title - $k - $v2.php");
|
||||
//touch("codes/$title - $k - $v2.php");
|
||||
|
||||
}
|
||||
|
||||
@ -486,12 +492,12 @@ $menu = array("Getting started" =>
|
||||
if( ! file_exists("docs/$title - $t.php")) {
|
||||
$missing[0]++;
|
||||
$str .= " [ <font color='red'>doc</font> ] ";
|
||||
touch("docs/$title - $t.php");
|
||||
//touch("docs/$title - $t.php");
|
||||
}
|
||||
if( ! file_exists("codes/$title - $t.php")) {
|
||||
$missing[1]++;
|
||||
$str .= " [ <font color='red'>code</font> ] ";
|
||||
touch("codes/$title - $t.php");
|
||||
//touch("codes/$title - $t.php");
|
||||
}
|
||||
print "<dt>".$e." <a href=\"".$_SERVER['PHP_SELF']."?index=$i#$e\">".$t."</a>$str</dt>\n";
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ class Doctrine_Import_TestCase extends Doctrine_UnitTestCase {
|
||||
unlink('tmp' . DIRECTORY_SEPARATOR . 'ImportTest.php');
|
||||
}
|
||||
public function testForeignKeySupport() {
|
||||
/**
|
||||
$this->dbh->query('CREATE TABLE album (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
title VARCHAR(100),
|
||||
@ -109,7 +110,7 @@ class Doctrine_Import_TestCase extends Doctrine_UnitTestCase {
|
||||
$sql = "PRAGMA table_info(track)";
|
||||
$sql = "PRAGMA foreign_key_list(track)";
|
||||
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
80
tests/RecordStateTestCase.php
Normal file
80
tests/RecordStateTestCase.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
class Doctrine_Record_State_TestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareTables() { }
|
||||
public function prepareData() { }
|
||||
|
||||
public function testAssignUnknownState() {
|
||||
$user = new User();
|
||||
try {
|
||||
$user->state(123123);
|
||||
$this->fail();
|
||||
} catch(Doctrine_Record_State_Exception $e) {
|
||||
$this->pass();
|
||||
}
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_TCLEAN);
|
||||
try {
|
||||
$user->state('some unknown state');
|
||||
$this->fail();
|
||||
} catch(Doctrine_Record_State_Exception $e) {
|
||||
$this->pass();
|
||||
}
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_TCLEAN);
|
||||
}
|
||||
|
||||
public function testAssignDirtyState() {
|
||||
$user = new User();
|
||||
|
||||
$user->state(Doctrine_Record::STATE_DIRTY);
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_DIRTY);
|
||||
|
||||
$user->state('dirty');
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_DIRTY);
|
||||
}
|
||||
public function testAssignCleanState() {
|
||||
$user = new User();
|
||||
|
||||
$user->state(Doctrine_Record::STATE_CLEAN);
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
|
||||
|
||||
$user->state('clean');
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
|
||||
}
|
||||
public function testAssignTransientCleanState() {
|
||||
$user = new User();
|
||||
|
||||
$user->state(Doctrine_Record::STATE_TCLEAN);
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_TCLEAN);
|
||||
|
||||
$user->state('tclean');
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_TCLEAN);
|
||||
}
|
||||
public function testAssignTransientDirtyState() {
|
||||
$user = new User();
|
||||
|
||||
$user->state(Doctrine_Record::STATE_TDIRTY);
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_TDIRTY);
|
||||
|
||||
$user->state('tdirty');
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_TDIRTY);
|
||||
}
|
||||
public function testAssignProxyState() {
|
||||
$user = new User();
|
||||
|
||||
$user->state(Doctrine_Record::STATE_PROXY);
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_PROXY);
|
||||
|
||||
$user->state('proxy');
|
||||
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_PROXY);
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
require_once("UnitTestCase.php");
|
||||
|
||||
class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
|
||||
class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
public function prepareTables() {
|
||||
$this->tables[] = "enumTest";
|
||||
|
@ -3,11 +3,12 @@
|
||||
class RelationTest extends Doctrine_Record {
|
||||
public function setTableDefinition() {
|
||||
$this->hasColumn('name', 'string', 200);
|
||||
$this->hasColumn("child_id", "integer");
|
||||
$this->hasColumn('child_id', 'integer');
|
||||
}
|
||||
public function setUp() {
|
||||
$this->ownsMany('OwnsOneToManyWithAlias as AliasO2M', 'AliasO2M.component_id');
|
||||
$this->hasMany('HasManyToManyWithAlias as AliasM2M', 'JoinTable.c1_id');
|
||||
$this->hasMany('M2M as AliasM2M', 'JoinTable.c1_id');
|
||||
// $this->hasMany('M2M as AliasM2M2', 'JoinTable.c1_id');
|
||||
}
|
||||
}
|
||||
class RelationTestChild extends RelationTest {
|
||||
@ -41,7 +42,7 @@ class OwnsOneToManyWithAlias extends Doctrine_Record {
|
||||
|
||||
}
|
||||
}
|
||||
class HasManyToManyWithAlias extends Doctrine_Record {
|
||||
class M2M extends Doctrine_Record {
|
||||
public function setTableDefinition() {
|
||||
$this->hasColumn('name', 'string', 200);
|
||||
}
|
||||
@ -52,7 +53,7 @@ class HasManyToManyWithAlias extends Doctrine_Record {
|
||||
class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareData() { }
|
||||
public function prepareTables() {
|
||||
$this->tables = array('HasManyToManyWithAlias', 'RelationTest', 'JoinTable');
|
||||
$this->tables = array('M2M', 'RelationTest', 'JoinTable');
|
||||
|
||||
parent::prepareTables();
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ require_once("BatchIteratorTestCase.php");
|
||||
require_once("CacheFileTestCase.php");
|
||||
|
||||
require_once("RecordTestCase.php");
|
||||
require_once("RecordStateTestCase.php");
|
||||
require_once("RecordFilterTestCase.php");
|
||||
|
||||
require_once("AccessTestCase.php");
|
||||
@ -57,14 +58,16 @@ print "<pre>";
|
||||
$test = new GroupTest("Doctrine Framework Unit Tests");
|
||||
|
||||
|
||||
$test->addTestCase(new Doctrine_Relation_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Record_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Record_State_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Import_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_SchemaTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Relation_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_ValidatorTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Query_MultiJoin_TestCase());
|
||||
|
Loading…
Reference in New Issue
Block a user