* Process the form after the input has been submitted and validated.
*
* @param CRM_Contribute_Form_Task $form
+ * @param array $formValues
*/
- public static function postProcess(&$form) {
- $formValues = $form->controller->exportValues($form->getName());
+ public static function postProcess(&$form, $formValues = NULL) {
+ if (empty($formValues)) {
+ $formValues = $form->controller->exportValues($form->getName());
+ }
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($formValues);
$isPDF = FALSE;
$emailParams = array();
}
}
}
+
+ if (!empty($formValues['is_unit_test'])) {
+ return $html;
+ }
//createActivities requires both $form->_contactIds and $contacts -
//@todo - figure out why
$form->_contactIds = array_keys($contacts);
'pdf' => 'PDF',
);
- if (realpath($phpWord)) {
- $phpWord = \PhpOffice\PhpWord\IOFactory::load($phpWord, $formats[$ext]);
+ if (realpath($fileName)) {
+ $phpWord = \PhpOffice\PhpWord\IOFactory::load($fileName, $formats[$ext]);
}
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $formats[$ext]);
*/
protected $_individualId;
+ protected $_docTypes = NULL;
+
+ protected $_contactIds = NULL;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->_individualId = $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins'));
+ $this->_docTypes = CRM_Core_SelectValues::documentApplicationType();
+ }
+
/**
* Clean up after each test.
*/
}
}
+ /**
+ * Test contribution token replacement in
+ * html returned by postProcess function.
+ */
+ public function testPostProcess() {
+ $this->_individualId = $this->individualCreate();
+ foreach (array('docx', 'odt') as $docType) {
+ $formValues = array(
+ 'is_unit_test' => TRUE,
+ 'group_by' => NULL,
+ 'document_file' => array(
+ 'name' => __DIR__ . "/sample_documents/Template.$docType",
+ 'type' => $this->_docTypes[$docType],
+ ),
+ );
+
+ $contributionParams = array(
+ 'contact_id' => $this->_individualId,
+ 'total_amount' => 100,
+ 'financial_type_id' => 'Donation',
+ );
+ $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
+ $contributionId = $contribution['id'];
+ $form = new CRM_Contribute_Form_Task_PDFLetter();
+ $form->setContributionIds(array($contributionId));
+ $format = Civi::settings()->get('dateformatFull');
+ $date = CRM_Utils_Date::getToday();
+ $displayDate = CRM_Utils_Date::customFormat($date, $format);
+
+ $html = CRM_Contribute_Form_Task_PDFLetterCommon::postProcess($form, $formValues);
+ $expectedValues = array(
+ 'Hello Anthony Collins',
+ '$ 100.00',
+ $displayDate,
+ 'Donation'
+ );
+
+ foreach ($expectedValues as $val) {
+ $this->assertTrue(strpos($html[$contributionId], $val) !== 0);
+ }
+ }
+ }
+
}