From: demeritcowboy Date: Mon, 15 Aug 2022 13:54:40 +0000 (-0400) Subject: add test for editing activity subject to file on case X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e2f11e3996ae792c9f0e45c45c0eba263088df5e;p=civicrm-core.git add test for editing activity subject to file on case --- diff --git a/tests/phpunit/CRM/Case/BAO/CaseTest.php b/tests/phpunit/CRM/Case/BAO/CaseTest.php index 4315091d5a..5e4e9b044b 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTest.php @@ -1275,6 +1275,48 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { ); } + /** + * 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 */ diff --git a/tests/phpunit/api/v3/ActivityCaseTest.php b/tests/phpunit/api/v3/ActivityCaseTest.php index 98243164e6..26d914b953 100644 --- a/tests/phpunit/api/v3/ActivityCaseTest.php +++ b/tests/phpunit/api/v3/ActivityCaseTest.php @@ -71,6 +71,39 @@ class api_v3_ActivityCaseTest extends CiviCaseTestCase { } } + /** + * 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']));