/**
  * testConcurrentRelationSetting
  * 
  * @see 0007108: inspect and solve concurrency conflicts when setting lead relations
  * @see 0000554: modlog: records can't be updated in less than 1 second intervals
  */
 public function testConcurrentRelationSetting()
 {
     $leadData = $this->_instance->saveLead($this->_getLead()->toArray());
     $task = $this->_getTask();
     $taskJson = new Tasks_Frontend_Json();
     $taskData = $task->toArray();
     $taskData['relations'] = array(array('type' => 'TASK', 'own_model' => 'Tasks_Model_Task', 'own_backend' => 'Sql', 'own_degree' => 'sibling', 'related_model' => 'Crm_Model_Lead', 'related_backend' => 'Sql', 'related_id' => $leadData['id'], 'related_record' => $leadData));
     $taskData = $taskJson->saveTask($taskData);
     $taskData['description'] = 1;
     $taskJson->saveTask($taskData);
     $savedLead = $this->_instance->getLead($leadData['id']);
     $savedLead['relations'][0]['related_record']['description'] = '2';
     $savedLead['relations'][0]['related_record']['due'] = '2012-10-18 12:54:33';
     // client may send wrong seq -> this should cause a concurrency conflict
     $savedLead['relations'][0]['related_record']['seq'] = 0;
     try {
         $this->_instance->saveLead($savedLead);
         $this->fail('expected concurrency exception');
     } catch (Tinebase_Timemachine_Exception_ConcurrencyConflict $ttecc) {
         $this->assertEquals('concurrency conflict!', $ttecc->getMessage());
     }
 }
Exemplo n.º 2
0
 /**
  * try to add a lead and link a contact
  *
  */
 public function testAddGetSearchDeleteLead()
 {
     // create lead with task and contact
     $contact = $this->_getContact();
     $task = $this->_getTask();
     $lead = $this->_getLead();
     $product = $this->_getProduct();
     $price = 200;
     $leadData = $lead->toArray();
     $leadData['relations'] = array(array('type' => 'TASK', 'related_record' => $task->toArray()), array('type' => 'PARTNER', 'related_record' => $contact->toArray()), array('type' => 'PRODUCT', 'related_record' => $product->toArray(), 'remark' => array('price' => $price)));
     // add note
     $note = array('note_type_id' => 1, 'note' => 'phpunit test note');
     $leadData['notes'] = array($note);
     $savedLead = $this->_instance->saveLead($leadData);
     $getLead = $this->_instance->getLead($savedLead['id']);
     $searchLeads = $this->_instance->searchLeads($this->_getLeadFilter(), '');
     //print_r($searchLeads);
     // assertions
     $this->assertEquals($getLead, $savedLead);
     $this->assertEquals($getLead['notes'][0]['note'], $note['note']);
     $this->assertTrue($searchLeads['totalcount'] > 0);
     $this->assertTrue(isset($searchLeads['totalleadstates']) && count($searchLeads['totalleadstates']) > 0);
     $this->assertEquals($lead->description, $searchLeads['results'][0]['description']);
     $this->assertEquals($price, $searchLeads['results'][0]['turnover'], 'turnover has not been calculated using product prices');
     $this->assertEquals($searchLeads['results'][0]['turnover'] * $lead->probability / 100, $searchLeads['results'][0]['probableTurnover']);
     $this->assertTrue(count($searchLeads['results'][0]['relations']) == 3, 'did not get all relations');
     // get related records and check relations
     foreach ($searchLeads['results'][0]['relations'] as $relation) {
         switch ($relation['type']) {
             case 'PRODUCT':
                 //print_r($relation);
                 $this->assertEquals(200, $relation['remark']['price'], 'product price (remark) does not match');
                 $relatedProduct = $relation['related_record'];
                 break;
             case 'TASK':
                 $relatedTask = $relation['related_record'];
                 break;
             case 'PARTNER':
                 $relatedContact = $relation['related_record'];
                 break;
         }
     }
     $this->assertTrue(isset($relatedContact), 'contact not found');
     $this->assertEquals($contact->n_fn, $relatedContact['n_fn'], 'contact name does not match');
     $this->assertTrue(isset($relatedTask), 'task not found');
     $this->assertEquals($task->summary, $relatedTask['summary'], 'task summary does not match');
     $defaultTaskContainerId = Tinebase_Core::getPreference('Tasks')->getValue(Tasks_Preference::DEFAULTTASKLIST);
     $this->assertEquals($defaultTaskContainerId, $relatedTask['container_id']);
     $this->assertTrue(isset($relatedProduct), 'product not found');
     $this->assertEquals($product->name, $relatedProduct['name'], 'product name does not match');
     // delete all
     $this->_instance->deleteLeads($savedLead['id']);
     Addressbook_Controller_Contact::getInstance()->delete($relatedContact['id']);
     Sales_Controller_Product::getInstance()->delete($relatedProduct['id']);
     // check if delete worked
     $result = $this->_instance->searchLeads($this->_getLeadFilter(), '');
     $this->assertEquals(0, $result['totalcount']);
     // check if linked task got removed as well
     $this->setExpectedException('Tinebase_Exception_NotFound');
     $task = Tasks_Controller_Task::getInstance()->get($relatedTask['id']);
 }