/**
  * singleton
  *
  * @return Tasks_Controller_Task
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Tasks_Controller_Task();
     }
     return self::$_instance;
 }
예제 #2
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->_controller = Tasks_Controller_Task::getInstance();
     $this->_minimalDatas = array('Task' => array('summary' => 'minimal task by PHPUnit::Tasks_ControllerTest'));
     $this->_testTask1 = new Tasks_Model_Task(array('container_id' => NULL, 'created_by' => 6, 'creation_time' => Tinebase_DateTime::now(), 'is_deleted' => 0, 'deleted_time' => NULL, 'deleted_by' => NULL, 'percent' => 70, 'completed' => NULL, 'due' => Tinebase_DateTime::now()->addMonth(1), 'description' => str_pad('', 1000, '.'), 'geo' => 0.2345, 'location' => 'here and there', 'organizer' => 4, 'priority' => 2, 'summary' => 'our first test task', 'url' => 'http://www.testtask.com'), true, false);
     $this->_testTask1->convertDates = true;
     $this->_persistantTestTask1 = $this->_controller->create($this->_testTask1);
     //parent::setUp();
 }
 /**
  * @see 0011234: automatically add task for responsible person on lead import
  */
 public function testAutoTaskImport()
 {
     Crm_Config::getInstance()->set(Crm_Config::LEAD_IMPORT_AUTOTASK, true);
     $personalContainerOfSClever = $this->_getPersonalContainer('Tasks', $this->_personas['sclever']);
     $this->_setPersonaGrantsForTestContainer($personalContainerOfSClever->getId(), 'sclever', true, false);
     $result = $this->testImport(false);
     foreach ($result['results'] as $lead) {
         foreach ($lead->relations as $relation) {
             if ($relation->type === 'TASK') {
                 $this->_tasksToDelete[] = $relation->related_id;
             }
         }
     }
     $translate = Tinebase_Translation::getTranslation('Crm');
     $tasksFilter = new Tasks_Model_TaskFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $personalContainerOfSClever->getId()), array('field' => 'summary', 'operator' => 'equals', 'value' => $translate->_('Edit new lead'))));
     $tasks = Tasks_Controller_Task::getInstance()->search($tasksFilter);
     $this->_tasksToDelete = array_merge($this->_tasksToDelete, $tasks->getArrayOfIds());
     $this->assertEquals(1, count($tasks), 'could not find task in sclevers container: ' . print_r($personalContainerOfSClever->toArray(), true));
     $task = $tasks->getFirstRecord();
     $this->assertEquals($this->_personas['sclever']['accountId'], $task->organizer);
     $this->assertEquals('IN-PROCESS', $task->status);
 }
 /**
  * try to add/search/delete a lead with linked contact, task and product
  * 
  * @see 0007214: if lead with linked task is saved, alarm is discarded
  */
 public function testAddGetSearchDeleteLead()
 {
     $savedLead = $this->_saveLead();
     $getLead = $this->_instance->getLead($savedLead['id']);
     $searchLeads = $this->_instance->searchLeads($this->_getLeadFilter(), '');
     // test manual resolving of organizer in related_record and set it back for following tests
     for ($i = 0; $i < count($getLead['relations']); $i++) {
         if (isset($getLead['relations'][$i]['related_record']['organizer'])) {
             $this->assertTrue(is_array($getLead['relations'][$i]['related_record']['organizer']));
             $getLead['relations'][$i]['related_record']['organizer'] = $getLead['relations'][$i]['related_record']['organizer']['accountId'];
         }
     }
     // assertions
     $this->assertEquals($getLead, $savedLead);
     $this->assertEquals($getLead['notes'][0]['note'], 'phpunit test note');
     $this->assertTrue($searchLeads['totalcount'] > 0);
     $this->assertTrue(isset($searchLeads['totalleadstates']) && count($searchLeads['totalleadstates']) > 0);
     $this->assertEquals($getLead['description'], $searchLeads['results'][0]['description']);
     $this->assertEquals(200, $searchLeads['results'][0]['turnover'], 'turnover has not been calculated using product prices');
     $this->assertEquals($searchLeads['results'][0]['turnover'] * $getLead['probability'] / 100, $searchLeads['results'][0]['probableTurnover']);
     // now we need 2 relations here (frontend search shall return relations with related_model Addressbook_Model_Contact or Sales_Model_Product
     $this->assertEquals(2, count($searchLeads['results'][0]['relations']), 'did not get all relations');
     $relatedTask = null;
     foreach ($getLead['relations'] as $rel) {
         if ($rel['type'] == 'TASK') {
             $relatedTask = $rel['related_record'];
         }
     }
     $this->assertTrue($relatedTask !== null);
     $this->assertEquals($this->_getTask()->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($relatedTask['alarms']) && count($relatedTask['alarms']) === 1, 'alarm missing in related task: ' . print_r($relatedTask, TRUE));
     $relatedTaskId = $relatedTask['id'];
     $relatedTask = NULL;
     // 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($this->_getContact()->n_fn, $relatedContact['n_fn'], 'contact name does not match');
     $this->assertFalse(is_array($relatedTask), 'task must not be found');
     $this->assertTrue(isset($relatedProduct), 'product not found');
     $this->assertEquals($this->_getProduct()->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');
     Tasks_Controller_Task::getInstance()->get($relatedTaskId);
 }
 /**
  * testDateTimeModlog
  * 
  * @see 0000996: add changes in relations/linked objects to modlog/history
  */
 public function testDateTimeModlog()
 {
     $task = Tasks_Controller_Task::getInstance()->create(new Tasks_Model_Task(array('summary' => 'test task')));
     $task->due = Tinebase_DateTime::now();
     $updatedTask = Tasks_Controller_Task::getInstance()->update($task);
     $task->seq = 1;
     $modlog = $this->_modLogClass->getModificationsBySeq($task, 2);
     $this->assertEquals(1, count($modlog));
     $this->assertEquals((string) $task->due, (string) $modlog->getFirstRecord()->new_value, 'new value mismatch: ' . print_r($modlog->toArray(), TRUE));
 }
 /**
  * creates a task by the given data
  */
 protected function _getTask($data)
 {
     $defaults = array('priority' => 'NORMAL', 'percent' => 70, 'due' => Tinebase_DateTime::now()->addMonth(1), 'summary' => 'demo task', 'container_id' => $this->_sharedTaskContainer->getId());
     // create test task
     $task = new Tasks_Model_Task(array_merge($defaults, $data));
     $tc = Tasks_Controller_Task::getInstance();
     $tc->doContainerACLChecks(false);
     $task = $tc->create($task);
     return $task;
 }
 /**
  * Deletes an existing Task
  *
  * @param array $ids 
  * @return string
  */
 public function deleteTasks($ids)
 {
     return $this->_delete($ids, Tasks_Controller_Task::getInstance());
 }
예제 #8
0
 /**
  * try to create a pdf with a linked task
  *
  */
 public function testLeadPdfLinkedTask()
 {
     // create lead + task + link
     $task = Tasks_Controller_Task::getInstance()->create($this->objects['linkedTask']);
     $lead = Crm_Controller_Lead::getInstance()->get($this->objects['leadWithLink']->getId());
     $lead->relations = array(array('own_model' => 'Crm_Model_Lead', 'own_backend' => 'Sql', 'own_id' => $lead->getId(), 'own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Tasks_Model_Task', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $task->getId(), 'type' => 'TASK'));
     $lead = Crm_Controller_Lead::getInstance()->update($lead);
     $pdf = new Crm_Export_Pdf();
     $pdf->generate($lead);
     $pdfOutput = $pdf->render();
     //$pdf->save("test.pdf");
     $this->assertEquals(1, preg_match("/^%PDF-1.4/", $pdfOutput), "no pdf generated");
     $this->assertEquals(1, preg_match("/" . $task->summary . "/", $pdfOutput), "no summary found");
     // remove
     Tasks_Controller_Task::getInstance()->delete($task->getId());
     // purge all relations
     $backend = new Tinebase_Relation_Backend_Sql();
     $backend->purgeAllRelations('Crm_Model_Lead', 'Sql', $this->objects['leadWithLink']->getId());
 }
 /**
  * try to search for tasks
  *
  */
 public function testSearchTasks()
 {
     // create task
     $task = $this->_getTask();
     $task = Tasks_Controller_Task::getInstance()->create($task);
     // search tasks
     $tasks = $this->_backend->searchTasks($this->_getFilter(), $this->_getPaging());
     // check
     $count = count($tasks['totalcount']);
     $this->assertGreaterThan(0, $count);
     // delete task
     $this->_backend->deleteTasks(array($task->getId()));
     // search and check again
     $tasks = $this->_backend->searchTasks($this->_getFilter(), $this->_getPaging());
     $this->assertEquals($count - 1, $tasks['totalcount']);
 }
 /**
  * search tasks
  *
  * @param      $containerId
  * @param null $summary
  * @return array|Tinebase_Record_RecordSet
  */
 protected function _searchTestTasks($containerId, $summary = null)
 {
     if (!$summary) {
         $translate = Tinebase_Translation::getTranslation('Crm');
         $summary = $translate->_('Edit new lead');
     }
     $tasksFilter = new Tasks_Model_TaskFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $containerId), array('field' => 'summary', 'operator' => 'contains', 'value' => $summary)));
     $tasks = Tasks_Controller_Task::getInstance()->search($tasksFilter);
     $this->_tasksToDelete = array_merge($this->_tasksToDelete, $tasks->getArrayOfIds());
     return $tasks;
 }
 public function _testTasks()
 {
     $allUsers = Tinebase_User::getInstance()->getFullUsers('');
     $numSearches = 0;
     foreach ($allUsers as $user) {
         if ($numSearches > 120) {
             break;
         }
         echo ".";
         $filterData = array(array('field' => 'container_id', 'operator' => 'in', 'value' => '/'));
         $filter = new Tasks_Model_TaskFilter($filterData);
         Tasks_Controller_Task::getInstance()->search($filter, NULL, FALSE);
         //$json = new Tasks_Frontend_Json();
         //$json->searchTasks($filterData, array());
         $numSearches += 1;
     }
 }
 /**
  * add auto tasks if config option is set and lead has responsible person
  *
  * @param Crm_Model_Lead $lead
  */
 protected function _addLeadAutoTaskForResponsibles(Crm_Model_Lead $lead)
 {
     $responsibles = $lead->getResponsibles();
     if (count($responsibles) === 0) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' No responsibles found');
         }
         return;
     }
     $translate = Tinebase_Translation::getTranslation('Crm');
     // create task (if current user has edit grant for other users default tasks container)
     $autoTask = new Tasks_Model_Task(array('summary' => $translate->_('Edit new lead'), 'due' => Tinebase_DateTime::now()->addHour(2), 'status' => 'IN-PROCESS', 'relations' => array(array('own_model' => 'Tasks_Model_Task', 'own_backend' => 'Sql', 'own_id' => 0, 'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'type' => 'TASK', 'related_record' => $lead, 'related_id' => $lead->getId(), 'related_model' => 'Crm_Model_Lead', 'related_backend' => 'Sql'))));
     foreach ($responsibles as $responsible) {
         if ($responsible->type !== Addressbook_Model_Contact::CONTACTTYPE_USER) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Responsible is no user');
             }
             continue;
         }
         try {
             $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $responsible->account_id);
         } catch (Tinebase_Exception_NotFound $tenf) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Could not find user');
             }
             continue;
         }
         $autoTaskForResponsible = clone $autoTask;
         $responsibleContainer = Tinebase_Container::getInstance()->getDefaultContainer('Tasks_Model_Task', $user->getId(), 'defaultTaskList');
         if (!$responsibleContainer) {
             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Could not find default container of user with ADD grant');
             }
             continue;
         }
         $autoTaskForResponsible->container_id = $responsibleContainer->getId();
         $autoTaskForResponsible->organizer = $responsible->account_id;
         Tasks_Controller_Task::getInstance()->create($autoTaskForResponsible);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Created auto task for user ' . $user->getId() . ' in container ' . $responsibleContainer->name);
         }
     }
 }
예제 #13
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']);
 }
 /**
  * try to set / get linked tasks
  *
  */
 public function testLinkedTasks()
 {
     $task = Tasks_Controller_Task::getInstance()->create($this->_objects['task']);
     // link task
     $lead = Crm_Controller_Lead::getInstance()->get($GLOBALS['Addressbook_ControllerTest']['leadId']);
     $lead->relations = array(array('own_model' => 'Crm_Model_Lead', 'own_backend' => 'Sql', 'own_id' => $GLOBALS['Addressbook_ControllerTest']['leadId'], 'own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Tasks_Model_Task', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $task->getId(), 'type' => 'TASK'));
     $lead = Crm_Controller_Lead::getInstance()->update($lead);
     // check linked tasks
     $updatedLead = Crm_Controller_Lead::getInstance()->get($GLOBALS['Addressbook_ControllerTest']['leadId']);
     //print_r($updatedLead->toArray());
     $this->assertGreaterThan(0, count($updatedLead->relations));
     $this->assertEquals($task->getId(), $updatedLead->relations[0]->related_id);
 }
 /**
  * return Tasks_Model_Task and convert contact id to model if needed
  * 
  * @return Tasks_Model_Task
  */
 public function getRecord()
 {
     if (!$this->_task instanceof Tasks_Model_Task) {
         $this->_task = Tasks_Controller_Task::getInstance()->get($this->_task);
         // resolve alarms
         //Tasks_Controller_Task::getInstance()->getAlarms($this->_task);
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " " . print_r($this->_task->toArray(), true));
     }
     return $this->_task;
 }
예제 #16
0
 /**
  * test server entries
  * 
  * @see #5894: Tasks sync is broken (http://forge.tine20.org/mantisbt/view.php?id=5894)
  */
 public function testGetServerEntries()
 {
     $controller = new ActiveSync_Controller_Tasks($this->objects['deviceIPhone'], new Tinebase_DateTime(null, null, 'de_DE'));
     $syncable = $this->_getContainerWithSyncGrant();
     Tasks_Controller_Task::getInstance()->create(new Tasks_Model_Task(array('container_id' => $syncable->getId(), 'summary' => 'sync test task', 'status' => 'NEEDS-ACTION')));
     $entries = $controller->getServerEntries($syncable->getId(), Syncope_Command_Sync::FILTER_INCOMPLETE);
     $this->assertEquals(1, count($entries));
 }