Merge pull request #21554 from eileenmcnaughton/loop
[civicrm-core.git] / tests / phpunit / CRM / Contribute / Form / Task / EmailTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Test Email task.
14 *
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contribution
17 * @group headless
18 */
19 class CRM_Contribute_Form_Task_EmailTest extends CiviUnitTestCase {
20
21 /**
22 * Clean up after each test.
23 *
24 * @throws \CRM_Core_Exception
25 * @throws \API_Exception
26 */
27 public function tearDown(): void {
28 $this->quickCleanUpFinancialEntities();
29 parent::tearDown();
30 }
31
32 /**
33 * Test that email tokens are rendered.
34 */
35 public function testEmailTokens(): void {
36 Civi::settings()->set('max_attachments', 0);
37 $contact1 = $this->individualCreate();
38 $contact2 = $this->individualCreate();
39 $userID = $this->createLoggedInUser();
40 Civi::settings()->set('allow_mail_from_logged_in_contact', TRUE);
41 $this->callAPISuccess('Email', 'create', [
42 'contact_id' => $userID,
43 'email' => 'benny_jetts@example.com',
44 'signature_html' => 'Benny, Benny',
45 'is_primary' => 1,
46 ]);
47 $contribution1 = $this->contributionCreate(['contact_id' => $contact2]);
48 $contribution2 = $this->contributionCreate(['total_amount' => 999, 'contact_id' => $contact1]);
49 $form = $this->getFormObject('CRM_Contribute_Form_Task_Email', [
50 'cc_id' => '',
51 'bcc_id' => '',
52 'to' => implode(',', [
53 $contact1 . '::teresajensen-nielsen65@spamalot.co.in',
54 $contact2 . '::bob@example.com',
55 ]),
56 'subject' => '{contact.display_name}',
57 'text_message' => '{contribution.total_amount}',
58 'html_message' => '{domain.name}',
59 ], [], [
60 'radio_ts' => 'ts_sel',
61 'task' => CRM_Core_Task::TASK_EMAIL,
62 'mark_x_' . $contribution1 => 1,
63 'mark_x_' . $contribution2 => 1,
64 ]);
65 $form->set('cid', $contact1 . ',' . $contact2);
66 $form->buildForm();
67 $this->assertEquals('<br/><br/>--Benny, Benny', $form->_defaultValues['html_message']);
68 $form->postProcess();
69 }
70
71 }