/** * testSaveContractWithManyRelations * * @group longrunning * * @see 0008586: when saving record with too many relations, modlog breaks * @see 0008712: testSaveContractWithManyRelations test lasts too long * @see 0009152: saving of record fails because of too many relations */ public function testSaveContractWithManyRelations() { $contractArray = $this->testAddContract(); $contacts = $this->_createContacts(500); $this->_setContractRelations($contractArray, $contacts); sleep(1); $updatedContractArray = $this->_instance->getContract($contractArray['id']); $updatedAgainContractArray = $this->_instance->saveContract($updatedContractArray); $this->assertEquals(500, count($updatedAgainContractArray['relations'])); $this->assertTrue(empty($updatedAgainContractArray['relations'][0]['last_modified_time']), 'relation changed'); $updatedAgainContractArray['relations'][0]['related_backend'] = 'sql'; $updatedAgainContractArray['relations'][0]['related_record']['adr_one_locality'] = 'örtchen'; $updatedAgainContractArray = $this->_instance->saveContract($updatedAgainContractArray); $this->assertEquals(500, count($updatedAgainContractArray['relations'])); }
/** * try to update a contract (with relations) * */ public function testUpdateContract() { $contract = $this->_getContract(); $contractData = $this->_instance->saveContract($contract->toArray()); $contractData = $this->_instance->getContract($contractData['id']); // add account and contact + update contract $contractData['relations'] = $this->_getRelations(); //print_r($contractData); $contractUpdated = $this->_instance->saveContract($contractData); //print_r($contractUpdated); // check $this->assertEquals($contractData['id'], $contractUpdated['id']); $this->assertGreaterThan(0, count($contractUpdated['relations'])); $this->assertEquals('Addressbook_Model_Contact', $contractUpdated['relations'][0]['related_model']); $this->assertEquals(Sales_Model_Contract::RELATION_TYPE_CUSTOMER, $contractUpdated['relations'][0]['type']); $this->assertEquals(Tinebase_Core::getUser()->getId(), $contractUpdated['relations'][1]['related_id']); $this->assertEquals(Sales_Model_Contract::RELATION_TYPE_ACCOUNT, $contractUpdated['relations'][1]['type']); // cleanup $this->_instance->deleteContracts($contractData['id']); Addressbook_Controller_Contact::getInstance()->delete($contractUpdated['relations'][0]['related_id']); $this->_decreaseNumber(); }
/** * test constraints after changing relation */ public function testTimeaccountRelation() { $sjson = new Sales_Frontend_Json(); $tjson = new Timetracker_Frontend_Json(); $ta = $tjson->saveTimeaccount(array('number' => 43379, 'title' => 'bla')); $c1 = $sjson->saveContract(array('number' => '1', 'description' => 'blub bla', 'title' => 'blub')); $c2 = $sjson->saveContract(array('number' => '2', 'description' => 'bla blub', 'title' => 'bla')); $c1['relations'] = array(array('related_model' => 'Timetracker_Model_Timeaccount', 'related_id' => $ta['id'], 'related_degree' => 'sibling', 'type' => 'TIME_ACCOUNT', 'remark' => 'unittest', 'related_backend' => 'Sql')); $c1 = $sjson->saveContract($c1); $c1Id = $c1['id']; // delete timeaccount relation from the first contract $c1 = $sjson->getContract($c1Id); $c1['relations'] = array(); $c1 = $sjson->saveContract($c1); // save second contract having the timeaccount related $c2['relations'] = array(array('related_model' => 'Timetracker_Model_Timeaccount', 'related_id' => $ta['id'], 'related_degree' => 'sibling', 'type' => 'TIME_ACCOUNT', 'remark' => 'unittest', 'related_backend' => 'Sql')); $c2 = $sjson->saveContract($c2); $this->assertEquals(1, count($c2['relations'])); }
/** * testTransfer * * @see 0009210: Allow to change relations * https://forge.tine20.org/mantisbt/view.php?id=9210 */ public function testTransfer() { $sclever = Addressbook_Controller_Contact::getInstance()->get($this->_personas['sclever']->contact_id, null, false); $pwulf = Addressbook_Controller_Contact::getInstance()->get($this->_personas['pwulf']->contact_id, null, false); $container = Tinebase_Container::getInstance()->create(new Tinebase_Model_Container(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Sales')->getId(), 'type' => Tinebase_Model_Container::TYPE_SHARED, 'backend' => 'sql', 'name' => 'testsdf'))); $contract = new Sales_Model_Contract(array('number' => '23547', 'title' => 'test', 'container_id' => $container->getId())); $contract = Sales_Controller_Contract::getInstance()->create($contract); $contract2 = new Sales_Model_Contract(array('number' => '23347', 'title' => 'test', 'container_id' => $container->getId())); $contract2 = Sales_Controller_Contract::getInstance()->create($contract2); $json = new Sales_Frontend_Json(); $contractJson = $contract->toArray(); $contractJson['relations'][] = array('own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Addressbook_Model_Contact', 'related_record' => $sclever->toArray(), 'type' => 'CUSTOMER'); $contractJson = $json->saveContract($contractJson); $contract2Json = $contract2->toArray(); $contract2Json['relations'][] = array('own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Addressbook_Model_Contact', 'related_record' => $sclever->toArray(), 'type' => 'PARTNER'); $contract2Json['relations'][] = array('own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Addressbook_Model_Contact', 'related_record' => $pwulf->toArray(), 'type' => 'PARTNER'); $contract2Json = $json->saveContract($contract2Json); $this->assertEquals($sclever->getId(), $contractJson['relations'][0]['related_id']); $skipped = Tinebase_Relations::getInstance()->transferRelations($sclever->getId(), $pwulf->getId(), 'Addressbook_Model_Contact'); $this->assertEquals(1, count($skipped)); $skipped = array_pop($skipped); $this->assertEquals($sclever->getId(), $skipped['own_id']); $contractJson = $json->getContract($contract->getId()); $this->assertEquals($pwulf->getId(), $contractJson['relations'][0]['related_id']); $this->setExpectedException('Tinebase_Exception_NotFound'); Tinebase_Relations::getInstance()->transferRelations($sclever->getId(), $pwulf->getId(), 'Addressbook_Model_Contract'); }
/** * test if relation record gets deleted on both sides on deleting the relation on one side */ public function testDeleteTimeaccountWitContractRelation() { $taContainer = Tinebase_Container::getInstance()->getDefaultContainer('Timetracker_Model_Timeaccount'); $cContainer = Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract'); $ta = new Timetracker_Model_Timeaccount(array('number' => 83209, 'title' => 'unitttest', 'container_id' => $taContainer->getId())); $contract = new Sales_Model_Contract(array('number' => 83209, 'title' => 'unittest', 'container_id' => $cContainer->getId())); $contract = Sales_Controller_Contract::getInstance()->create($contract); $ta = Timetracker_Controller_Timeaccount::getInstance()->create($ta); $r = new Tinebase_Model_Relation(array('own_model' => 'Timetracker_Model_Timeaccount', 'own_backend' => 'Sql', 'own_degree' => 'sibling', 'own_id' => $ta->getId(), 'remark' => 'PHP UNITTEST', 'related_model' => 'Sales_Model_Contract', 'related_backend' => 'Sql', 'related_id' => $contract->getId(), 'type' => 'CONTRACT')); $ta->relations = array($r); $ta = Timetracker_Controller_Timeaccount::getInstance()->update($ta); $feTa = new Timetracker_Frontend_Json(); $feCo = new Sales_Frontend_Json(); $jsonTa = $feTa->getTimeaccount($ta->getId()); $jsonCo = $feCo->getContract($contract->getId()); $this->assertEquals(1, count($jsonTa['relations'])); $this->assertEquals(1, count($jsonCo['relations'])); $feTa->deleteTimeaccounts(array($ta->getId())); $jsonCo = $feCo->getContract($contract->getId()); $this->assertEquals(0, count($jsonCo['relations'])); }