);
}
+ /**
+ * Same as testFileOnCaseBySubject but editing an existing non-case activity
+ */
+ public function testFileOnCaseByEditingSubject() {
+ $loggedInUserId = $this->createLoggedInUser();
+ $clientId = $this->individualCreate();
+ $caseObj = $this->createCase($clientId, $loggedInUserId);
+ $activity = $this->callAPISuccess('Activity', 'create', [
+ 'source_contact_id' => $loggedInUserId,
+ 'target_contact_id' => $clientId,
+ 'activity_type_id' => 1,
+ 'subject' => 'Starting as non-case activity',
+ ]);
+ $subject = 'Now should be a case activity [case #' . $caseObj->id . ']';
+ $form = $this->getFormObject('CRM_Activity_Form_Activity', [
+ 'id' => $activity['id'],
+ 'source_contact_id' => $loggedInUserId,
+ 'target_contact_id' => $clientId,
+ 'subject' => $subject,
+ 'activity_date_time' => date('Y-m-d H:i:s'),
+ 'activity_type_id' => 1,
+ ]);
+ $form->postProcess();
+
+ $activity = $this->callAPISuccess('Activity', 'getsingle', [
+ 'id' => $activity['id'],
+ 'return' => ['case_id'],
+ ]);
+ // Note it's an array
+ $this->assertEquals([$caseObj->id], $activity['case_id']);
+
+ // Double-check
+ $queryParams = [1 => [$activity['id'], 'Integer']];
+ $this->assertEquals(
+ $caseObj->id,
+ CRM_Core_DAO::singleValueQuery('SELECT ca.case_id
+ FROM civicrm_case_activity ca
+ INNER JOIN civicrm_activity a ON ca.activity_id = a.id
+ WHERE a.id = %1', $queryParams)
+ );
+ }
+
/**
* Basic case create test with an Org client
*/
}
}
+ /**
+ * Same as testActivityCreateOnCase but editing an existing non-case activity
+ */
+ public function testActivityEditAddingCaseIdInSubject() {
+ $activity = $this->callAPISuccess('Activity', 'create', [
+ 'source_contact_id' => $this->_cid,
+ 'activity_type_id' => 'Meeting',
+ 'subject' => 'Starting as non-case activity 1',
+ ]);
+ $hash = substr(sha1(CIVICRM_SITE_KEY . $this->_case['id']), 0, 7);
+ // edit activity and put hash in the subject
+ $activity = $this->callAPISuccess('Activity', 'create', [
+ 'id' => $activity['id'],
+ 'subject' => "Now should be a case activity 1 [case #{$hash}]",
+ ]);
+ $case = $this->callAPISuccessGetSingle('Activity', ['return' => ['case_id'], 'id' => $activity['id']]);
+ // It should be filed on the case now
+ $this->assertEquals($this->_case['id'], $case['case_id'][0]);
+
+ // Now same thing but just with the id not the hash
+ $activity = $this->callAPISuccess('Activity', 'create', [
+ 'source_contact_id' => $this->_cid,
+ 'activity_type_id' => 'Meeting',
+ 'subject' => 'Starting as non-case activity 2',
+ ]);
+ $activity = $this->callAPISuccess('Activity', 'create', [
+ 'id' => $activity['id'],
+ 'subject' => "Now should be a case activity 2 [case #{$this->_case['id']}]",
+ ]);
+ $case = $this->callAPISuccessGetSingle('Activity', ['return' => ['case_id'], 'id' => $activity['id']]);
+ $this->assertEquals($this->_case['id'], $case['case_id'][0]);
+ }
+
public function testGet() {
$this->assertTrue(is_numeric($this->_case['id']));
$this->assertTrue(is_numeric($this->_otherActivity['id']));