예제 #1
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']);
 }
 /**
  * testDeleteLeadWithAttachment
  * 
  * @see 0005024: allow to attach external files to records
  */
 public function testDeleteLeadWithAttachment()
 {
     $lead = $this->testCreateLeadWithAttachment();
     $this->_instance->deleteLeads(array($lead['id']));
     $this->assertFalse($this->_fsController->fileExists($this->_objects['paths'][0]));
 }
예제 #3
0
 /**
  * Tears down the fixture
  * This method is called after a test is executed.
  *
  * @access protected
  */
 protected function tearDown()
 {
     $this->_json->deleteLeads($this->_objects['lead']['id']);
     Addressbook_Controller_Contact::getInstance()->delete($this->_objects['lead']['relations'][0]['related_id']);
 }