/** * Tests multiple update with relations */ public function testUpdateMultipleWithRelations() { $contract1 = $this->_getContract('contract 1'); $contract2 = $this->_getContract('contract 2'); $contract1 = Sales_Controller_Contract::getInstance()->create($contract1); $contract2 = Sales_Controller_Contract::getInstance()->create($contract2); // peter, bob, laura, lisa list($contact1, $contact2, $contact3, $contact4) = $this->_createContacts(); // add contact2 as customer relation to contract2 $this->_setContractRelations($contract2, array($contact2), 'CUSTOMER'); $contract1and2Ids = array($contract1->id, $contract2->id); $tbJson = new Tinebase_Frontend_Json(); // add Responsible contact1 to both contracts $response = $tbJson->updateMultipleRecords('Sales', 'Contract', array(array('name' => '%RESPONSIBLE-Addressbook_Model_Contact', 'value' => $contact1->getId())), array(array('field' => 'id', 'operator' => 'in', 'value' => $contract1and2Ids))); $this->assertEquals(2, count($response['results'])); $contract1re = $this->_instance->getContract($contract1->getId()); $contract2re = $this->_instance->getContract($contract2->getId()); // only one CUSTOMER relation is allowed, contract2 still has related contact2 $this->assertEquals(1, count($contract1re['relations']), 'contract1 relations count failed: ' . print_r($contract1re, true)); $this->assertEquals(2, count($contract2re['relations']), 'contract2 relations count failed: ' . print_r($contract2re, true)); $this->assertEquals($contact1->getId(), $contract1re['relations'][0]['related_id']); if ($contract2re['relations'][1]['related_id'] == $contact1->getId()) { $this->assertEquals($contact1->getId(), $contract2re['relations'][1]['related_id']); $this->assertEquals($contact2->getId(), $contract2re['relations'][0]['related_id']); } else { $this->assertEquals($contact2->getId(), $contract2re['relations'][1]['related_id']); $this->assertEquals($contact1->getId(), $contract2re['relations'][0]['related_id']); } // update customer to contact3 and add responsible to contact4, so contract1 and 2 will have 2 relations $response = $tbJson->updateMultipleRecords('Sales', 'Contract', array(array('name' => '%CUSTOMER-Addressbook_Model_Contact', 'value' => $contact3->getId()), array('name' => '%RESPONSIBLE-Addressbook_Model_Contact', 'value' => $contact4->getId())), array(array('field' => 'id', 'operator' => 'in', 'value' => $contract1and2Ids))); $this->assertEquals(count($response['results']), 2); $contract1re = $this->_instance->getContract($contract1->getId()); $contract2re = $this->_instance->getContract($contract2->getId()); $this->assertEquals(2, count($contract1re['relations'])); $this->assertEquals(2, count($contract2re['relations'])); // remove customer $response = $tbJson->updateMultipleRecords('Sales', 'Contract', array(array('name' => '%CUSTOMER-Addressbook_Model_Contact', 'value' => '')), array(array('field' => 'id', 'operator' => 'in', 'value' => $contract1and2Ids))); $this->assertEquals(2, count($response['results'])); $contract1res = $this->_instance->getContract($contract1->getId()); $contract2res = $this->_instance->getContract($contract2->getId()); $this->assertEquals(1, count($contract1res['relations'])); $this->assertEquals(1, count($contract2res['relations'])); }
/** * this test is for Tinebase_Frontend_Json updateMultipleRecords with contact data in the addressbook app */ public function testUpdateMultipleRecords() { $companies = array('Janes', 'Johns', 'Bobs'); $contacts = array(); $createdCustomField = $this->_createCustomfield(); $changes = array(array('name' => 'url', 'value' => "http://www.phpunit.de"), array('name' => 'adr_one_region', 'value' => 'PHPUNIT_multipleUpdate'), array('name' => 'customfield_' . $createdCustomField->name, 'value' => 'PHPUNIT_multipleUpdate')); foreach ($companies as $company) { $contact = $this->_addContact($company); $contactIds[] = $contact['id']; } $filter = array(array('field' => 'id', 'operator' => 'in', 'value' => $contactIds)); $json = new Tinebase_Frontend_Json(); $result = $json->updateMultipleRecords('Addressbook', 'Contact', $changes, $filter); // look if all 3 contacts are updated $this->assertEquals(3, $result['totalcount'], 'Could not update the correct number of records'); // check if default field adr_one_region value was found $sFilter = array(array('field' => 'adr_one_region', 'operator' => 'equals', 'value' => 'PHPUNIT_multipleUpdate')); $searchResult = $this->_uit->searchContacts($sFilter, $this->objects['paging']); // look if all 3 contacts are found again by default field, and check if default field got properly updated $this->assertEquals(3, $searchResult['totalcount'], 'Could not find the correct number of records by adr_one_region'); $record = array_pop($searchResult['results']); // check if customfieldvalue was updated properly $this->assertTrue(isset($record['customfields']), 'No customfields in record'); $this->assertEquals($record['customfields'][$createdCustomField->name], 'PHPUNIT_multipleUpdate', 'Customfield was not updated as expected'); // check if other default field value was updated properly $this->assertEquals($record['url'], 'http://www.phpunit.de', 'DefaultField "url" was not updated as expected'); // check 'changed' systemnote $this->_checkChangedNote($record['id'], 'adr_one_region ( -> PHPUNIT_multipleUpdate) url ( -> http://www.phpunit.de) customfields ( -> {'); // check invalid data $changes = array(array('name' => 'type', 'value' => 'Z')); $result = $json->updateMultipleRecords('Addressbook', 'Contact', $changes, $filter); $this->assertEquals(3, $result['failcount'], 'failcount does not show the correct number'); $this->assertEquals(0, $result['totalcount'], 'totalcount does not show the correct number'); }
/** * testUpdateMultipleTimesheets * @see http://forge.tine20.org/mantisbt/view.php?id=5878 */ public function testUpdateMultipleTimesheets() { // create 100+ timesheets $first = $this->_getTimesheet(array(), TRUE); for ($i = 0; $i < 122; $i++) { $this->_getTimesheet(array('timeaccount_id' => $first->timeaccount_id), TRUE); } // update multi with filter $filterArray = $this->_getTimesheetDateFilter(); $filterArray[] = array('field' => 'is_cleared_combined', 'operator' => 'equals', 'value' => 0); $tinebaseJson = new Tinebase_Frontend_Json(); $result = $tinebaseJson->updateMultipleRecords('Timetracker', 'Timesheet', array(array('name' => 'is_cleared', 'value' => 1)), $filterArray); // check if all got updated $this->assertEquals($result['totalcount'], 123); $this->assertEquals($result['failcount'], 0); $this->assertEquals(1, $result['results'][0]['is_cleared'], print_r($result['results'][0], TRUE)); $this->assertEquals(1, $result['results'][122]['is_cleared'], print_r($result['results'][122], TRUE)); }