Skip to content

Commit

Permalink
Merge pull request #31686 from eileenmcnaughton/rel_clea
Browse files Browse the repository at this point in the history
Standardise setUp for CiviCase shared code
  • Loading branch information
eileenmcnaughton authored Jan 2, 2025
2 parents f52a0d6 + 8855790 commit d2012fa
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 541 deletions.
4 changes: 1 addition & 3 deletions CRM/Case/XMLProcessor/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,8 @@ public function isActivityPresent(&$params) {
* @param array $params
*
* @return bool
* @throws CRM_Core_Exception
* @throws Exception
*/
public function createActivity($activityTypeXML, &$params) {
public function createActivity($activityTypeXML, &$params): bool {
$activityTypeName = (string) $activityTypeXML->name;
$activityTypes = CRM_Case_PseudoConstant::caseActivityType(TRUE, TRUE);
$activityTypeInfo = $activityTypes[$activityTypeName] ?? NULL;
Expand Down
48 changes: 0 additions & 48 deletions tests/fixtures/case_relationships.json

This file was deleted.

52 changes: 0 additions & 52 deletions tests/fixtures/contacts.json

This file was deleted.

51 changes: 15 additions & 36 deletions tests/phpunit/CRM/Activity/Page/AJAXTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,27 @@
/**
* @group headless
*/
class CRM_Activity_Page_AJAXTest extends CiviUnitTestCase {

/**
* @var int
*/
private $loggedInUser;

/**
* @var int
*/
private $target;

public function setUp(): void {
parent::setUp();

$this->loadAllFixtures();

CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');

$this->loggedInUser = $this->createLoggedInUser();
$this->target = $this->individualCreate();
}
class CRM_Activity_Page_AJAXTest extends CiviCaseTestCase {

/**
* Test the underlying function that implements file-on-case.
*
* The UI is a quickform but it's only realized as a popup ajax form that
* The UI is a quick form but it's only realized as a popup ajax form that
* doesn't have its own postProcess. Instead the values are ultimately
* passed to the function this test is testing. So there's no form or ajax
* being tested here, just the final act of filing the activity.
*/
public function testConvertToCaseActivity(): void {
$activity = $this->callAPISuccess('Activity', 'create', [
'source_contact_id' => $this->loggedInUser,
'source_contact_id' => $this->createLoggedInUser(),
'activity_type_id' => 'Meeting',
'subject' => 'test file on case',
'status_id' => 'Completed',
'target_id' => $this->target,
'target_id' => $this->individualCreate([], 'target'),
]);

$case = $this->callAPISuccess('Case', 'create', [
'contact_id' => $this->target,
'contact_id' => $this->ids['Contact']['target'],
'case_type_id' => 'housing_support',
'subject' => 'Needs housing',
]);
Expand All @@ -53,7 +32,7 @@ public function testConvertToCaseActivity(): void {
'activityID' => $activity['id'],
'caseID' => $case['id'],
'mode' => 'file',
'targetContactIds' => $this->target,
'targetContactIds' => $this->ids['Contact']['target'],
];
$result = CRM_Activity_Page_AJAX::_convertToCaseActivity($params);

Expand All @@ -72,9 +51,9 @@ public function testConvertToCaseActivity(): void {
* Similar to testConvertToCaseActivity above but for copy-to-case.
*/
public function testCopyToCase(): void {
$case1 = $this->callAPISuccess('Case', 'create', [
'contact_id' => $this->target,
'case_type_id' => 'housing_support',
$case1 = $this->createTestEntity('Case', [
'contact_id' => $this->individualCreate([], 'target'),
'case_type_id:name' => 'housing_support',
'subject' => 'Needs housing',
]);
$contact2 = $this->individualCreate([], 1, TRUE);
Expand All @@ -85,11 +64,11 @@ public function testCopyToCase(): void {
]);

$activity = $this->callAPISuccess('Activity', 'create', [
'source_contact_id' => $this->loggedInUser,
'source_contact_id' => $this->createLoggedInUser(),
'activity_type_id' => 'Meeting',
'subject' => 'To be copied to case',
'status_id' => 'Completed',
'target_id' => $this->target,
'target_id' => $this->ids['Contact']['target'],
'case_id' => $case1['id'],
]);

Expand Down Expand Up @@ -127,7 +106,7 @@ public function testCopyToCase(): void {
*/
public function testMoveToCase(): void {
$case1 = $this->callAPISuccess('Case', 'create', [
'contact_id' => $this->target,
'contact_id' => $this->individualCreate([], 'target'),
'case_type_id' => 'housing_support',
'subject' => 'Needs housing',
]);
Expand All @@ -139,11 +118,11 @@ public function testMoveToCase(): void {
]);

$activity = $this->callAPISuccess('Activity', 'create', [
'source_contact_id' => $this->loggedInUser,
'source_contact_id' => $this->createLoggedInUser(),
'activity_type_id' => 'Meeting',
'subject' => 'To be moved to case',
'status_id' => 'Completed',
'target_id' => $this->target,
'target_id' => $this->ids['Contact']['target'],
'case_id' => $case1['id'],
]);

Expand Down Expand Up @@ -189,7 +168,7 @@ public function testPreserveFilters(): void {
// Need a logged in user since the filter is per-contact, but this
// cid is the visited contact so could be anything, but might as well
// use this one.
'cid' => $this->loggedInUser,
'cid' => $this->createLoggedInUser(),
'draw' => '5',
'columns' => [
0 => [
Expand Down
42 changes: 3 additions & 39 deletions tests/phpunit/CRM/Case/BAO/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,7 @@
* Class CRM_Case_BAO_CaseTest
* @group headless
*/
class CRM_Case_BAO_CaseTest extends CiviUnitTestCase {

const TABLES_TO_TRUNCATE = [
'civicrm_activity',
'civicrm_group_contact',
'civicrm_contact',
'civicrm_custom_group',
'civicrm_custom_field',
'civicrm_case',
'civicrm_case_contact',
'civicrm_case_activity',
'civicrm_case_type',
'civicrm_file',
'civicrm_entity_file',
'civicrm_activity_contact',
'civicrm_managed',
'civicrm_relationship',
'civicrm_relationship_type',
];

public function setUp(): void {
parent::setUp();

$this->quickCleanup(self::TABLES_TO_TRUNCATE);

$this->loadAllFixtures();

// I don't understand why need to disable but if don't then only one
// case type is defined on 2nd and subsequent dataprovider runs.
CRM_Core_BAO_ConfigSetting::disableComponent('CiviCase');
CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
}
class CRM_Case_BAO_CaseTest extends CiviCaseTestCase {

/**
* Make sure that the latest case activity works accurately.
Expand All @@ -57,21 +26,16 @@ public function testCaseActivity(): void {
}
}

protected function tearDown(): void {
$this->quickCleanup(self::TABLES_TO_TRUNCATE, TRUE);
parent::tearDown();
}

public function testAddCaseToContact(): void {
$this->createLoggedInUser();
$params = [
'case_id' => 1,
'contact_id' => 17,
'contact_id' => $this->individualCreate(),
];
CRM_Case_BAO_CaseContact::writeRecord($params);

$recent = CRM_Utils_Recent::get();
$this->assertEquals('Test Contact - Housing Support', $recent[0]['title']);
$this->assertEquals('Mr. Anthony Anderson II - Housing Support', $recent[0]['title']);
}

/**
Expand Down
46 changes: 25 additions & 21 deletions tests/phpunit/CRM/Case/Form/CaseViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ public function testSearchFilterDropdown(): void {
// We don't care about the first one, just check it's what we expect
$this->assertEquals('- select activity type -', $options[0]['text']);
unset($options[0]);
$expected = [];
foreach ([
'Follow up',
'Income and benefits stabilization',
'Long-term housing plan',
'Medical evaluation',
'Mental health evaluation',
'Open Case',
'Secure temporary housing',
] as $expectedValue) {
$expected[] = [CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', $expectedValue) => $expectedValue];
}
$mappedOptions = array_map(function($v) {
return [$v['attr']['value'] => $v['text']];
}, $options);
$this->assertEquals([
[14 => 'Follow up'],
[61 => 'Income and benefits stabilization'],
[59 => 'Long-term housing plan'],
[56 => 'Medical evaluation'],
[57 => 'Mental health evaluation'],
[13 => 'Open Case'],
[58 => 'Secure temporary housing'],
], array_values($mappedOptions));
$this->assertEquals($expected, array_values($mappedOptions));

// Now add some activities where the type might not even be in the config.
$this->callAPISuccess('Activity', 'create', [
Expand Down Expand Up @@ -70,20 +74,20 @@ public function testSearchFilterDropdown(): void {
$options = $form->getElement('activity_type_filter_id')->_options;
unset($options[0]);
$mappedOptions = array_map(function($v) {
return [$v['attr']['value'] => $v['text']];
return $v['text'];
}, $options);
$this->assertEquals([
[3 => 'Email'],
[14 => 'Follow up'],
[12 => 'Inbound Email'],
[61 => 'Income and benefits stabilization'],
[59 => 'Long-term housing plan'],
[56 => 'Medical evaluation'],
[1 => 'Meeting'],
[57 => 'Mental health evaluation'],
[13 => 'Open Case'],
[2 => 'Phone Call'],
[58 => 'Secure temporary housing'],
'Email',
'Follow up',
'Inbound Email',
'Income and benefits stabilization',
'Long-term housing plan',
'Medical evaluation',
'Meeting',
'Mental health evaluation',
'Open Case',
'Phone Call',
'Secure temporary housing',
], array_values($mappedOptions));
}

Expand Down
Loading

0 comments on commit d2012fa

Please sign in to comment.