. */ /** * Doctrine_Record_State_TestCase * * @package Doctrine * @author Konsta Vesterinen * @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_Record_Synchronize_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { parent::prepareTables(); } public function prepareData() { $user = new User(); $user->name = 'John'; $user->Email->address = 'john@mail.com'; $user->Phonenumber[0]->phonenumber = '555 123'; $user->Phonenumber[1]->phonenumber = '555 448'; $user->save(); } public function testSynchronizeRecord() { $user = Doctrine_Query::create()->from('User u, u.Email, u.Phonenumber')->fetchOne(); $userArray = $user->toArray(true); $this->assertEqual($user->Phonenumber->count(), 2); $this->assertEqual($user->Phonenumber[0]->phonenumber, '555 123'); // modify a Phonenumber $userArray['Phonenumber'][0]['phonenumber'] = '555 321'; // delete a Phonenumber array_pop($userArray['Phonenumber']); $user->synchronizeWithArray($userArray); $this->assertEqual($user->Phonenumber->count(), 1); $this->assertEqual($user->Phonenumber[0]->phonenumber, '555 321'); // change Email $userArray['Email']['address'] = 'johndow@mail.com'; $user->synchronizeWithArray($userArray); $this->assertEqual($user->Email->address, 'johndow@mail.com'); $user->save(); } public function testSynchronizeAfterSaveRecord() { $user = Doctrine_Query::create()->from('User u, u.Email, u.Phonenumber')->fetchOne(); $this->assertEqual($user->Phonenumber->count(), 1); $this->assertEqual($user->Phonenumber[0]->phonenumber, '555 321'); $this->assertEqual($user->Email->address, 'johndow@mail.com'); } public function testSynchronizeAddRecord() { $user = Doctrine_Query::create()->from('User u, u.Email, u.Phonenumber')->fetchOne(); $userArray = $user->toArray(true); $userArray['Phonenumber'][] = array('phonenumber' => '333 238'); $user->synchronizeWithArray($userArray); $this->assertEqual($user->Phonenumber->count(), 2); $this->assertEqual($user->Phonenumber[1]->phonenumber, '333 238'); $user->save(); } public function testSynchronizeAfterAddRecord() { $user = Doctrine_Query::create()->from('User u, u.Email, u.Phonenumber')->fetchOne(); $this->assertEqual($user->Phonenumber->count(), 2); $this->assertEqual($user->Phonenumber[1]->phonenumber, '333 238'); } public function testSynchronizeRemoveRecord() { $user = Doctrine_Query::create()->from('User u, u.Email, u.Phonenumber')->fetchOne(); $userArray = $user->toArray(true); unset($userArray['Phonenumber']); unset($userArray['Email']); $user->synchronizeWithArray($userArray); $this->assertEqual($user->Phonenumber->count(), 0); $this->assertTrue(!isset($user->Email)); $user->save(); } public function testSynchronizeAfterRemoveRecord() { $user = Doctrine_Query::create()->from('User u, u.Email, u.Phonenumber')->fetchOne(); $this->assertEqual($user->Phonenumber->count(), 0); $this->assertTrue(!isset($user->Email)); } }