Commit 1133b26c authored by zYne's avatar zYne

--no commit message

--no commit message
parent 1a76029f
<?php
class Doctrine_Record_Lock_TestCase extends Doctrine_UnitTestCase {
public function prepareTables()
{
......
......@@ -39,8 +39,28 @@ class Doctrine_Record_State_TestCase extends Doctrine_UnitTestCase
parent::prepareTables();
}
public function prepareData() { }
public function prepareData()
{ }
public function testAssigningAutoincId()
{
$user = new User();
$this->assertEqual($user->id, null);
$user->name = 'zYne';
$user->save();
$this->assertEqual($user->id, 1);
$user->id = 2;
$this->assertEqual($user->id, 2);
$user->save();
}
/**
public function testAssignFieldsToProxies()
{
$user = new User();
......@@ -228,4 +248,5 @@ class Doctrine_Record_State_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($user2->password,UPWD2) ;
$this->assertEqual($user2->loginname,null) ;
}
*/
}
......@@ -42,6 +42,67 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
parent::prepareTables();
}
public function testOne2OneForeign()
{
$user = new User();
$user->name = "Richard Linklater";
$rel = $user->getTable()->getRelation('Account');
$this->assertTrue($rel instanceof Doctrine_Relation_ForeignKey);
$account = $user->Account;
$account->amount = 1000;
$this->assertTrue($account instanceof Account);
$this->assertEqual($account->state(), Doctrine_Record::STATE_TDIRTY);
$this->assertEqual($account->entity_id->getOid(), $user->getOid());
$this->assertEqual($account->amount, 1000);
$this->assertEqual($user->name, "Richard Linklater");
$user->save();
$this->assertEqual($account->entity_id, $user->id);
$user->refresh();
$account = $user->Account;
$this->assertTrue($account instanceof Account);
$this->assertEqual($account->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($account->entity_id, $user->id);
$this->assertEqual($account->amount, 1000);
$this->assertEqual($user->name, "Richard Linklater");
$user = new User();
$user->name = 'John Rambo';
$account = $user->Account;
$account->amount = 2000;
$this->assertEqual($account->getTable()->getColumnNames(), array('id', 'entity_id', 'amount'));
$this->connection->flush();
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
$this->assertTrue($account instanceof Account);
$this->assertEqual($account->getTable()->getColumnNames(), array('id', 'entity_id', 'amount'));
$this->assertEqual($account->entity_id, $user->id);
$this->assertEqual($account->amount, 2000);
$user = $user->getTable()->find($user->id);
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
$account = $user->Account;
$this->assertTrue($account instanceof Account);
$this->assertEqual($account->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($account->getTable()->getColumnNames(), array('id', 'entity_id', 'amount'));
$this->assertEqual($account->entity_id, $user->id);
$this->assertEqual($account->amount, 2000);
$this->assertEqual($user->name, "John Rambo");
}
public function testIssetForPrimaryKey()
{
$this->assertTrue(isset($this->users[0]->id));
......@@ -50,9 +111,9 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$user = new User();
$this->assertFalse(isset($user->id));
$this->assertFalse(isset($user['id']));
$this->assertFalse($user->contains('id'));
$this->assertTrue(isset($user->id));
$this->assertTrue(isset($user['id']));
$this->assertTrue($user->contains('id'));
}
public function testNotNullConstraint()
......@@ -312,60 +373,6 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
}
public function testOne2OneForeign()
{
$user = new User();
$user->name = "Richard Linklater";
$account = $user->Account;
$account->amount = 1000;
$this->assertTrue($account instanceof Account);
$this->assertEqual($account->state(), Doctrine_Record::STATE_TDIRTY);
$this->assertEqual($account->entity_id->getOid(), $user->getOid());
$this->assertEqual($account->amount, 1000);
$this->assertEqual($user->name, "Richard Linklater");
$user->save();
$user->refresh();
$account = $user->Account;
$this->assertTrue($account instanceof Account);
$this->assertEqual($account->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($account->entity_id, $user->id);
$this->assertEqual($account->amount, 1000);
$this->assertEqual($user->name, "Richard Linklater");
$user = new User();
$user->name = "John Rambo";
$account = $user->Account;
$account->amount = 2000;
$this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount"));
$this->connection->flush();
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
$this->assertTrue($account instanceof Account);
$this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount"));
$this->assertEqual($account->entity_id, $user->id);
$this->assertEqual($account->amount, 2000);
$user = $user->getTable()->find($user->id);
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
$account = $user->Account;
$this->assertTrue($account instanceof Account);
$this->assertEqual($account->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount"));
$this->assertEqual($account->entity_id, $user->id);
$this->assertEqual($account->amount, 2000);
$this->assertEqual($user->name, "John Rambo");
}
public function testGet()
{
......
<?php
/*
* $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_Ticket424B_TestCase
*
* This test case tests many-many relationship with non-autoincrement primary key
*
* @package Doctrine
* @author Tamcy <7am.online@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Ticket_424B_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{ }
public function prepareTables()
{
$this->tables = array('mmrUser_B', 'mmrGroup_B', 'mmrGroupUser_B');
parent::prepareTables();
}
protected function newGroup($code, $name)
{
$group = new mmrGroup_B();
$group->id = $code;
$group->name = $name;
$group->save();
return $group;
}
protected function newUser($code, $name, $groups)
{
$u = new mmrUser_B();
$u->id = $code;
$u->name = $name;
foreach ($groups as $idx=>$group) {
$u->Group[$idx] = $group;
}
$u->save();
return $u;
}
public function testManyManyRelationWithAliasColumns()
{
$groupA = $this->newGroup(1, 'Group A');
$groupB = $this->newGroup(2, 'Group B');
$groupC = $this->newGroup(3, 'Group C');
$john = $this->newUser(1, 'John', array($groupA, $groupB));
$peter = $this->newUser(2, 'Peter', array($groupA, $groupC));
$alan = $this->newUser(3, 'Alan', array($groupB, $groupC));
$q = new Doctrine_Query();
$gu = $q->from('mmrGroupUser_B')->execute();
$this->assertEqual(count($gu), 6);
// Direct query
$q = new Doctrine_Query();
$gu = $q->from('mmrGroupUser_B')->where('group_id = ?', $groupA->id)->execute();
$this->assertEqual(count($gu), 2);
// Query by join
$q = new Doctrine_Query();
$userOfGroupAByName = $q->from('mmrUser_B u, u.Group g')
->where('g.name = ?', array($groupA->name));
$q->execute();
$this->assertEqual(count($userOfGroupAByName), 2);
}
}
class mmrUser_B extends Doctrine_Record
{
public function setUp()
{
$this->hasMany('mmrGroup_B as Group', array('local' => 'user_id',
'foreign' => 'group_id',
'refClass' => 'mmrGroupUser_B'));
}
public function setTableDefinition()
{
// Works when
$this->hasColumn('id', 'string', 30, array ( 'primary' => true));
$this->hasColumn('name', 'string', 30);
}
}
class mmrGroup_B extends Doctrine_Record
{
public function setUp() {
$this->hasMany('mmrUser_B', array('local' => 'group_id',
'foreign' => 'user_id',
'refClass' => 'mmrGroupUser_B'));
}
public function setTableDefinition() {
// Works when
$this->hasColumn('id', 'string', 30, array ( 'primary' => true));
$this->hasColumn('name', 'string', 30);
}
}
class mmrGroupUser_B extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('user_id', 'string', 30, array('primary' => true));
$this->hasColumn('group_id', 'string', 30, array('primary' => true));
}
}
<?php
/*
* $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_Ticket424B_TestCase
*
* This test case tests many-many relationship with non-autoincrement, alias primary key
*
* @package Doctrine
* @author Tamcy <7am.online@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Ticket_424C_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{ }
public function prepareTables()
{
$this->tables = array('mmrUser_C', 'mmrGroup_C', 'mmrGroupUser_C');
parent::prepareTables();
}
protected function newGroup($code, $name)
{
$group = new mmrGroup_C();
$group->id = $code;
$group->name = $name;
$group->save();
return $group;
}
protected function newUser($code, $name, $groups)
{
$u = new mmrUser_C();
$u->id = $code;
$u->name = $name;
foreach ($groups as $idx=>$group) {
$u->Group[$idx] = $group;
}
$u->save();
return $u;
}
public function testManyManyRelationWithAliasColumns()
{
$groupA = $this->newGroup(1, 'Group A');
$groupB = $this->newGroup(2, 'Group B');
$groupC = $this->newGroup(3, 'Group C');
$john = $this->newUser(1, 'John', array($groupA, $groupB));
$peter = $this->newUser(2, 'Peter', array($groupA, $groupC));
$alan = $this->newUser(3, 'Alan', array($groupB, $groupC));
$q = new Doctrine_Query();
$gu = $q->from('mmrGroupUser_C')->execute();
$this->assertEqual(count($gu), 6);
// Direct query
$q = new Doctrine_Query();
$gu = $q->from('mmrGroupUser_C')->where('group_id = ?', $groupA->id)->execute();
$this->assertEqual(count($gu), 2);
// Query by join
$q = new Doctrine_Query();
$userOfGroupAByName = $q->from('mmrUser_C u, u.Group g')
->where('g.name = ?', array($groupA->name));
$q->execute();
$this->assertEqual(count($userOfGroupAByName), 2);
}
}
class mmrUser_C extends Doctrine_Record
{
public function setUp()
{
$this->hasMany('mmrGroup_C as Group', array('local' => 'user_id',
'foreign' => 'group_id',
'refClass' => 'mmrGroupUser_C'));
}
public function setTableDefinition()
{
// Works when
$this->hasColumn('g_id as id', 'string', 30, array ( 'primary' => true));
$this->hasColumn('name', 'string', 30);
}
}
class mmrGroup_C extends Doctrine_Record
{
public function setUp() {
$this->hasMany('mmrUser_C', array('local' => 'group_id',
'foreign' => 'user_id',
'refClass' => 'mmrGroupUser_C'));
}
public function setTableDefinition() {
// Works when
$this->hasColumn('u_id as id', 'string', 30, array ( 'primary' => true));
$this->hasColumn('name', 'string', 30);
}
}
class mmrGroupUser_C extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('user_id', 'string', 30, array('primary' => true));
$this->hasColumn('group_id', 'string', 30, array('primary' => true));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment