Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default activity on webform if filed on case #950

Open
wants to merge 1 commit into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/WebformCivicrmPreProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,15 @@ private function findExistingActivities() {
'is_deleted' => '0',
'is_current_revision' => '1',
'options' => ['limit' => 1],
'activity_type_id' => $this->data['activity'][$n]['activity'][1]['activity_type_id'],
];
$params['activity_type_id'] = $this->data['activity'][$n]['activity'][1]['activity_type_id'];
$caseType = $this->data['activity'][$n]['case_type_id'] ?? NULL;
if (!empty($caseType) && $caseType[0] === '#') {
$case_num = substr($caseType, 1);
if (!empty($this->ent['case'][$case_num]['id'])) {
$params['case_id'] = $this->ent['case'][$case_num]['id'];
}
}
$items = $this->utils->wf_crm_apivalues('activity', 'get', $params);
if (isset($items[0]['id'])) {
$this->ent['activity'][$n] = ['id' => $items[0]['id']];
Expand Down
61 changes: 61 additions & 0 deletions tests/src/FunctionalJavascript/CaseSubmissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,70 @@ protected function setUp(): void {
$this->getSession()->getPage()->checkField('Case Subject');
$this->getSession()->getPage()->checkField('Case Start Date');

// Configure Activity Tab
$this->getSession()->getPage()->clickLink('Activities');
$this->getSession()->getPage()->selectFieldOption('activity_number_of_activity', 1);
$this->assertSession()->waitForField('civicrm_1_activity_1_activity_subject');
$this->htmlOutput();
$this->getSession()->getPage()->selectFieldOption('Update Existing Activity', 'Scheduled');
$this->getSession()->getPage()->selectFieldOption('File On Case', 'Case 1');
$this->assertSession()->assertWaitOnAjaxRequest();

$this->getSession()->getPage()->checkField('Activity Subject');
$this->getSession()->getPage()->selectFieldOption('Activity Type', 'Follow up');
$this->assertSession()->assertWaitOnAjaxRequest();

$this->saveCiviCRMSettings();
}

/**
* Verify correct Case and related Activity
* is loaded on the webform by default.
*/
public function testCaseActivityDefaults() {
$cases = [
[
'subject' => 'Case 1 subject',
'status' => 'Closed',
'activity_subject' => 'Followup Activity from Case 1',
],
[
'subject' => 'Case 2 subject',
'status' => 'Open',
'activity_subject' => 'Followup Activity from Case 2',
],
];
// Create case 1 with status=Resolved
// Create case 2 with status=Ongoing
foreach ($cases as $params) {
$case = \Civi\Api4\CiviCase::create(TRUE)
->addValue('case_type_id.name', 'housing_support')
->addValue('status_id:name', $params['status'])
->addValue('contact_id', $this->rootUserCid)
->addValue('subject', $params['subject'])
->addValue('creator_id', $this->rootUserCid)
->execute()
->first();

// Add subject to the followup activity
\Civi\Api4\Activity::update(TRUE)
->addValue('subject', $params['activity_subject'])
->addWhere('case_id', '=', $case['id'])
->addWhere('activity_type_id:name', '=', 'Follow up')
->execute()
->first();
}

// Load the webform
$this->drupalGet($this->webform->toUrl('canonical'));
$this->htmlOutput();
$this->assertPageNoErrorMessages();

// Ensure case subject and activity subject is populated correctly.
$this->assertSession()->fieldValueEquals('civicrm_1_case_1_case_subject', 'Case 2 subject');
$this->assertSession()->fieldValueEquals('civicrm_1_activity_1_activity_subject', 'Followup Activity from Case 2');
}

/**
* Test Case Submission.
*/
Expand Down
Loading