forked from civicrm/org.civicrm.civicase
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAE-823: Sets the form submission values in Session
- Loading branch information
1 parent
01ce0a4
commit c00004b
Showing
1 changed file
with
47 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?php | ||
|
||
use Civi\Test\Api3TestTrait; | ||
use CRM_Civicase_Hook_ValidateForm_SendBulkEmail as SendBulkEmailHook; | ||
|
||
/** | ||
|
@@ -11,6 +12,7 @@ class CRM_Civicase_Hook_SendBulkEmailTest extends BaseHeadlessTest { | |
|
||
use CRM_Civicase_Helpers_SessionTrait; | ||
use Helpers_MailHelpersTrait; | ||
use Api3TestTrait; | ||
|
||
/** | ||
* Instance of the form sent on the hook. | ||
|
@@ -26,14 +28,21 @@ class CRM_Civicase_Hook_SendBulkEmailTest extends BaseHeadlessTest { | |
*/ | ||
private $caseType; | ||
|
||
/** | ||
* Currently logged in User. | ||
* | ||
* @var array | ||
*/ | ||
private $loggedInUser; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
|
||
$loggedInUser = CRM_Civicase_Test_Fabricator_Contact::fabricateWithEmail(); | ||
$this->registerCurrentLoggedInContactInSession($loggedInUser['id']); | ||
$this->loggedInUser = CRM_Civicase_Test_Fabricator_Contact::fabricateWithEmail(); | ||
$this->registerCurrentLoggedInContactInSession($this->loggedInUser['id']); | ||
|
||
$this->caseType = CRM_Civicase_Test_Fabricator_CaseType::fabricate()['id']; | ||
} | ||
|
@@ -299,9 +308,20 @@ private function createCaseForContact(int $contactId) { | |
* Return the result of calling the hook. | ||
*/ | ||
private function runHook(string $subject, string $body, array $cases, array $contacts) { | ||
$formName = $this->form->getName(); | ||
$senderEmail = $this->callAPISuccess('Email', 'getsingle', ['contact_id' => $this->loggedInUser['id']]); | ||
|
||
$formValues = [ | ||
'to' => [], | ||
'cc_id' => [], | ||
'bcc_id' => [], | ||
'subject' => $subject, | ||
'text_message' => $body, | ||
'html_message' => $body, | ||
'from_email_address' => $senderEmail['id'], | ||
]; | ||
$_REQUEST['allCaseIds'] = $_GET['allCaseIds'] = implode(',', $cases); | ||
|
||
$formName = 'Test Form'; | ||
$fields = $files = $errors = []; | ||
|
||
$this->form->_contactIds = []; | ||
|
@@ -315,16 +335,34 @@ private function runHook(string $subject, string $body, array $cases, array $con | |
'contact_id' => $contact['id'], | ||
'preferred_mail_format' => 'HTML', | ||
]; | ||
$formValues['to'][] = $contact['id'] . '::' . $contact['email']; | ||
} | ||
$formValues['to'] = implode(',', $formValues['to']); | ||
|
||
$this->setFormSubmitValues($formName, $formValues); | ||
return (new SendBulkEmailHook())->run($formName, $fields, $files, $this->form, $errors); | ||
} | ||
|
||
/** | ||
* Sets the form submission values in Session and element. | ||
* | ||
* @param string $formName | ||
* The form name. | ||
* @param array $formValues | ||
* The values of the form fields. | ||
*/ | ||
private function setFormSubmitValues(string $formName, array $formValues) { | ||
$this->form->controller = new CRM_Core_Controller_Simple(get_class($this->form), $formName); | ||
$_SESSION['_' . $this->form->controller->_name . '_container']['values'][$formName] = $formValues; | ||
$_SESSION['_' . $this->form->controller->_name . '_container']['values']['Search'] = []; | ||
|
||
$this->form->addElement('hidden', 'cc_id', []); | ||
$this->form->addElement('hidden', 'bcc_id', []); | ||
$this->form->addElement('hidden', 'subject', $subject); | ||
$this->form->addElement('hidden', 'text_message', $body); | ||
$this->form->addElement('hidden', 'html_message', $body); | ||
$this->form->addElement('hidden', 'from_email_address', '[email protected]'); | ||
|
||
return (new SendBulkEmailHook())->run($formName, $fields, $files, $this->form, $errors); | ||
$this->form->addElement('hidden', 'to', $formValues['to']); | ||
$this->form->addElement('hidden', 'subject', $formValues['subject']); | ||
$this->form->addElement('hidden', 'text_message', $formValues['text_message']); | ||
$this->form->addElement('hidden', 'html_message', $formValues['html_message']); | ||
$this->form->addElement('hidden', 'from_email_address', $formValues['from_email_address']); | ||
} | ||
|
||
/** | ||
|