From 68cdfbaba820e4336d312282968d9f9b16829d79 Mon Sep 17 00:00:00 2001 From: phpbenben Date: Thu, 2 Aug 2007 18:57:34 +0000 Subject: [PATCH] Updated Record/StateTestCase that includes a test with a sequence of calls that check for the current values of the attributes and state of the Record class --- tests/Record/StateTestCase.php | 64 +++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/tests/Record/StateTestCase.php b/tests/Record/StateTestCase.php index 4da8c8e98..81bce56de 100644 --- a/tests/Record/StateTestCase.php +++ b/tests/Record/StateTestCase.php @@ -166,5 +166,67 @@ class Doctrine_Record_State_TestCase extends Doctrine_UnitTestCase $this->assertEqual($user->password, '123'); $this->assertEqual($count, count($this->dbh)); - } + } + + public function testProxyToDirtyToProxy() { + + define('UNAME','someuser') ; + define('UPWD1','123') ; + define('UPWD2','456') ; + define('ULNAME','somelogin') ; + + $user = new User() ; + $user->name = UNAME ; + $user->password = UPWD1 ; + $user->loginname = ULNAME ; + $user->save() ; + + $this->assertEqual($user->name,UNAME) ; + $this->assertEqual($user->password,UPWD1) ; + $this->assertEqual($user->loginname,ULNAME) ; + + // to make sure it is saved correctly + $user1 = $this->connection->queryOne("FROM User u WHERE u.name = '" . UNAME . "'"); + $this->assertEqual($user1->state(), Doctrine_Record::STATE_CLEAN); + $this->assertEqual($user1->name,UNAME) ; + $this->assertEqual($user1->password,UPWD1) ; + $this->assertEqual($user1->loginname,ULNAME) ; + + $this->connection->clear() ; + //$this->clearCache() ; + + // now lets fetch partially the object + //$users = Doctrine_Query::create($this->connection)->select('u.name')->from('User u')->where("u.name='someuser'")->execute() ; + //$user2 = $users[0] ; + $user2 = $this->connection->queryOne("SELECT u.name FROM User u WHERE u.name = '" . UNAME . "'"); + + // the object should be in state proxy with only 'name' fetched ... + $this->assertEqual($user2->state(), Doctrine_Record::STATE_PROXY); + $this->assertEqual($user2->name,UNAME) ; + $this->assertEqual($user2->password,null) ; + $this->assertEqual($user2->loginname,null) ; + + // lets edit the object + $user2->password = UPWD2 ; + + // now it should be dirty (but may be PDIRTY ... ?) + $this->assertEqual($user2->state(),Doctrine_Record::STATE_DIRTY) ; + $this->assertEqual($user2->name,UNAME) ; + $this->assertEqual($user2->password,UPWD2) ; + $this->assertEqual($user2->loginname,null) ; + + // lets save + $user2->save() ; + + // the logic would suggest the object to go back to PROXY mode (becausse $user2->loginname is null aka not sync with DB) + // because we know loginname should be equal to 'bogus' IF NOT in proxy state + $boolState = ($user2->loginname == null) && ($user2->state() === Doctrine_Record::STATE_PROXY) ; + // this one will currently fail + $this->assertTrue($boolState) ; + // this will also currently fail (becausse it currently goes back to STATE_CLEAN, which shouldnt be the case) + //$this->assertEqual($user2->state(), Doctrine_Record::STATE_PROXY); + $this->assertEqual($user2->name,UNAME) ; + $this->assertEqual($user2->password,UPWD2) ; + $this->assertEqual($user2->loginname,null) ; + } }