Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
d409829f
Unverified
Commit
d409829f
authored
2 years ago
by
Eileen McNaughton
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #23577 from demeritcowboy/deleted-tests
[NFC] Bring back deleted activity email tests
parents
d9b1c057
1c932c52
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/phpunit/CRM/Activity/BAO/ActivityTest.php
+138
-0
138 additions, 0 deletions
tests/phpunit/CRM/Activity/BAO/ActivityTest.php
with
138 additions
and
0 deletions
tests/phpunit/CRM/Activity/BAO/ActivityTest.php
+
138
−
0
View file @
d409829f
...
...
@@ -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.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment