-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
[Ref] Extend email trait test, process more sanely #21553
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,19 +80,6 @@ public function testPostProcessWithSignature(): void { | |
|
||
Civi::settings()->set('allow_mail_from_logged_in_contact', 1); | ||
$loggedInContactID = $this->createLoggedInUser(); | ||
/* @var CRM_Contact_Form_Task_Email $form*/ | ||
$form = $this->getFormObject('CRM_Contact_Form_Task_Email'); | ||
|
||
for ($i = 0; $i < 27; $i++) { | ||
$email = 'spy' . $i . '@secretsquirrels.com'; | ||
$contactID = $this->individualCreate(['email' => $email]); | ||
$form->_contactIds[$contactID] = $contactID; | ||
$form->_toContactEmails[$this->callAPISuccessGetValue('Email', ['return' => 'id', 'email' => $email])] = $email; | ||
} | ||
$deceasedContactID = $this->individualCreate(['is_deceased' => 1, 'email' => '[email protected]']); | ||
$form->_contactIds[$deceasedContactID] = $deceasedContactID; | ||
$form->_toContactEmails[$this->callAPISuccessGetValue('Email', ['return' => 'id', 'email' => '[email protected]'])] = '[email protected]'; | ||
|
||
$loggedInEmail = $this->callAPISuccess('Email', 'create', [ | ||
'email' => '[email protected]', | ||
'location_type_id' => 1, | ||
|
@@ -101,15 +88,35 @@ public function testPostProcessWithSignature(): void { | |
'signature_text' => 'This is a test Signature', | ||
'signature_html' => '<p>This is a test Signature</p>', | ||
]); | ||
|
||
$to = $form_contactIds = $form_toContactEmails = []; | ||
for ($i = 0; $i < 27; $i++) { | ||
$email = 'spy' . $i . '@secretsquirrels.com'; | ||
$contactID = $this->individualCreate(['email' => $email]); | ||
$form_contactIds[$contactID] = $contactID; | ||
$to[] = $contactID . '::' . $email; | ||
} | ||
$deceasedContactID = $this->individualCreate(['is_deceased' => 1, 'email' => '[email protected]']); | ||
$to[] = $deceasedContactID . '::' . '[email protected]'; | ||
/* @var CRM_Contact_Form_Task_Email $form*/ | ||
$form = $this->getFormObject('CRM_Contact_Form_Task_Email', [ | ||
'to' => implode(',', $to), | ||
]); | ||
$form->_contactIds = $form_contactIds; | ||
$form->_contactIds[$deceasedContactID] = $deceasedContactID; | ||
|
||
$form->_allContactIds = $form->_toContactIds = $form->_contactIds; | ||
$form->_emails = [$loggedInEmail['id'] => '[email protected]']; | ||
$form->_fromEmails = [$loggedInEmail['id'] => '[email protected]']; | ||
// This rule somehow disappears if there's a form-related test before us, | ||
// so register it again. See packages/HTML/QuickForm/file.php. | ||
// update - actually - it's never registered. Even in form made | ||
// I can see it missing - It's really weird. | ||
$form->registerRule('maxfilesize', 'callback', '_ruleCheckMaxFileSize', 'HTML_QuickForm_file'); | ||
$form->isSearchContext = FALSE; | ||
$form->buildForm(); | ||
$form->submit(array_merge($form->_defaultValues, [ | ||
// @todo - it's better to pass these into getForm | ||
// and access them on the form using $this->getSubmittedValue(). | ||
'from_email_address' => $loggedInEmail['id'], | ||
'subject' => 'Really interesting stuff', | ||
'bcc_id' => $bcc, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* Test Email task. | ||
* | ||
* @package CiviCRM_APIv3 | ||
* @subpackage API_Contribution | ||
* @group headless | ||
*/ | ||
class CRM_Contribute_Form_Task_EmailTest extends CiviUnitTestCase { | ||
|
||
/** | ||
* Clean up after each test. | ||
* | ||
* @throws \CRM_Core_Exception | ||
* @throws \API_Exception | ||
*/ | ||
public function tearDown(): void { | ||
$this->quickCleanUpFinancialEntities(); | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* Test that email tokens are rendered. | ||
*/ | ||
public function testEmailTokens(): void { | ||
Civi::settings()->set('max_attachments', 0); | ||
$contact1 = $this->individualCreate(); | ||
$contact2 = $this->individualCreate(); | ||
$userID = $this->createLoggedInUser(); | ||
Civi::settings()->set('allow_mail_from_logged_in_contact', TRUE); | ||
$this->callAPISuccess('Email', 'create', [ | ||
'contact_id' => $userID, | ||
'email' => '[email protected]', | ||
'signature_html' => 'Benny, Benny', | ||
'is_primary' => 1, | ||
]); | ||
$contribution1 = $this->contributionCreate(['contact_id' => $contact2]); | ||
$contribution2 = $this->contributionCreate(['total_amount' => 999, 'contact_id' => $contact1]); | ||
$form = $this->getFormObject('CRM_Contribute_Form_Task_Email', [ | ||
'cc_id' => '', | ||
'bcc_id' => '', | ||
'to' => implode(',', [ | ||
$contact1 . '::[email protected]', | ||
$contact2 . '::[email protected]', | ||
]), | ||
'subject' => '{contact.display_name}', | ||
'text_message' => '{contribution.total_amount}', | ||
'html_message' => '{domain.name}', | ||
], [], [ | ||
'radio_ts' => 'ts_sel', | ||
'task' => CRM_Core_Task::TASK_EMAIL, | ||
'mark_x_' . $contribution1 => 1, | ||
'mark_x_' . $contribution2 => 1, | ||
]); | ||
$form->set('cid', $contact1 . ',' . $contact2); | ||
$form->buildForm(); | ||
$this->assertEquals('<br/><br/>--Benny, Benny', $form->_defaultValues['html_message']); | ||
$form->postProcess(); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key part of the change to this test - we are now passing 'to' as a submitted value rather than setting properties on the form (this is a good change)