Skip to content
Snippets Groups Projects
Unverified Commit d409829f authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #23577 from demeritcowboy/deleted-tests

[NFC] Bring back deleted activity email tests
parents d9b1c057 1c932c52
Branches
Tags
No related merge requests found
......@@ -1694,6 +1694,144 @@ $textValue
}
}
/**
* Same as testSendEmailWillReplaceTokensUniquelyForEachContact but with
* 3 recipients and an attachment.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testSendEmailWillReplaceTokensUniquelyForEachContact3(): void {
$contactId1 = $this->individualCreate(['last_name' => 'Red']);
$contactId2 = $this->individualCreate(['last_name' => 'Pink']);
$contactId3 = $this->individualCreate(['last_name' => 'Ochre']);
// create a logged in USER since the code references it for sendEmail user.
$this->createLoggedInUser();
$contact = $this->callAPISuccess('Contact', 'get', ['sequential' => 1, 'id' => ['IN' => [$contactId1, $contactId2, $contactId3]]]);
// Add contact tokens in subject, html , text.
$subject = __FUNCTION__ . ' subject' . '{contact.display_name}';
$html = __FUNCTION__ . ' html' . '{contact.display_name}';
// Check the smarty doesn't mess stuff up.
$text = ' text' . '{contact.display_name} {$contact.first_name}';
$filepath = Civi::paths()->getPath('[civicrm.files]/custom');
$fileName = 'test_email_create.txt';
$fileUri = "{$filepath}/{$fileName}";
// Create a file.
CRM_Utils_File::createFakeFile($filepath, 'aaaaaa', $fileName);
$form = $this->getFormObject('CRM_Contact_Form_Task_Email', [
'subject' => $subject,
'html_message' => $html,
'text_message' => $text,
'campaign_id' => $this->getCampaignID(),
'from_email_address' => 'from@example.com',
'to' => $contactId1 . '::' . $contact['values'][0]['email'] . ','
. $contactId2 . '::' . $contact['values'][1]['email'] . ','
. $contactId3 . '::' . $contact['values'][2]['email'],
'attachFile_1' => [
'uri' => $fileUri,
'type' => 'text/plain',
'location' => $fileUri,
'name' => $fileUri,
],
'attachDesc_1' => '',
], [], []);
$form->set('cid', $contactId1 . ',' . $contactId2 . ',' . $contactId3);
$form->buildForm();
$form->postProcess();
$result = $this->callAPISuccess('Activity', 'get', ['campaign_id' => $this->getCampaignID()]);
// An activity created for each of the two contacts
$this->assertEquals(3, $result['count']);
$id = 0;
foreach ($result['values'] as $activity) {
$htmlValue = str_replace('{contact.display_name}', $contact['values'][$id]['display_name'], $html);
$textValue = str_replace('{contact.display_name}', $contact['values'][$id]['display_name'], $text);
$subjectValue = str_replace('{contact.display_name}', $contact['values'][$id]['display_name'], $subject);
$details = "-ALTERNATIVE ITEM 0-
$htmlValue
-ALTERNATIVE ITEM 1-
$textValue
-ALTERNATIVE END-
";
$this->assertEquals($activity['details'], $details, 'Activity details does not match.');
$this->assertEquals($activity['subject'], $subjectValue, 'Activity subject does not match.');
$id++;
}
unlink($fileUri);
}
/**
* Checks that attachments are not duplicated for activities.
*/
public function testSendEmailDoesNotDuplicateAttachmentFileIdsForActivitiesCreated() {
$contactId1 = $this->individualCreate(['last_name' => 'Red']);
$contactId2 = $this->individualCreate(['last_name' => 'Pink']);
// create a logged in USER since the code references it for sendEmail user.
$this->createLoggedInUser();
$session = CRM_Core_Session::singleton();
$loggedInUser = $session->get('userID');
$contact = $this->callAPISuccess('Contact', 'get', ['sequential' => 1, 'id' => ['IN' => [$contactId1, $contactId2]]]);
// Create a campaign.
$result = $this->callAPISuccess('Campaign', 'create', [
'version' => $this->_apiversion,
'title' => __FUNCTION__ . ' campaign',
]);
$campaign_id = $result['id'];
$subject = __FUNCTION__ . ' subject';
$html = __FUNCTION__ . ' html';
$text = __FUNCTION__ . ' text';
$userID = $loggedInUser;
$filepath = Civi::paths()->getPath('[civicrm.files]/custom');
$fileName = "test_email_create.txt";
$fileUri = "{$filepath}/{$fileName}";
// Create a file.
CRM_Utils_File::createFakeFile($filepath, 'Bananas do not bend themselves without a little help.', $fileName);
$form = $this->getFormObject('CRM_Contact_Form_Task_Email', [
'subject' => $subject,
'html_message' => $html,
'text_message' => $text,
'campaign_id' => $campaign_id,
'from_email_address' => 'from@example.com',
'to' => $contactId1 . '::' . $contact['values'][0]['email'] . ','
. $contactId2 . '::' . $contact['values'][1]['email'],
'attachFile_1' => [
'uri' => $fileUri,
'type' => 'text/plain',
'location' => $fileUri,
'name' => $fileUri,
],
'attachDesc_1' => '',
], [], []);
$form->set('cid', $contactId1 . ',' . $contactId2);
$form->buildForm();
$form->postProcess();
$result = $this->callAPISuccess('activity', 'get', ['campaign_id' => $campaign_id]);
// An activity created for each of the two contacts, i.e two activities.
$this->assertEquals(2, $result['count']);
$activityIds = array_column($result['values'], 'id');
$result = $this->callAPISuccess('Activity', 'get', [
'return' => ['file_id'],
'id' => ['IN' => $activityIds],
'sequential' => 1,
]);
// Verify that the that both activities are linked to the same File Id.
$this->assertEquals($result['values'][0]['file_id'], $result['values'][1]['file_id']);
unlink($fileUri);
}
/**
* Adds a case with one activity.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment