/** * Assert the content of document * * @param array $formValues * @param array $type */ public function _testDocumentContent($formValues, $type) { $html = array(); $form = new CRM_Contact_Form_Task_PDFLetterCommon(); list($formValues, $categories, $html_message, $messageToken, $returnProperties) = $form->processMessageTemplate($formValues); list($html_message, $zip) = CRM_Utils_PDF_Document::unzipDoc($formValues['document_file_path'], $formValues['document_type']); foreach ($this->_contactIds as $item => $contactId) { $params = array('contact_id' => $contactId); list($contact) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, FALSE, FALSE, NULL, $messageToken, 'CRM_Contact_Form_Task_PDFLetterCommon'); $html[] = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken); } $returnContent = CRM_Utils_PDF_Document::printDocuments($formValues['document_file_path'], $html, $type, $zip, TRUE); $returnContent = strip_tags($returnContent); $this->assertTrue(strpos($returnContent, 'Hello Antonia D`souza') !== 0); $this->assertTrue(strpos($returnContent, 'Hello Anthony Collins') !== 0); }
/** * Process the form after the input has been submitted and validated. * * @param CRM_Core_Form $form */ public static function postProcess(&$form) { $formValues = $form->controller->exportValues($form->getName()); list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($formValues); $buttonName = $form->controller->getButtonName(); $skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE; $skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE; $html = $document = array(); // CRM-16725 Skip creation of activities if user is previewing their PDF letter(s) if ($buttonName == '_qf_PDF_upload') { self::createActivities($form, $html_message, $form->_contactIds); } if (!empty($formValues['document_file_path'])) { list($html_message, $zip) = CRM_Utils_PDF_Document::unzipDoc($formValues['document_file_path'], $formValues['document_type']); } foreach ($form->_contactIds as $item => $contactId) { $caseId = NULL; $params = array('contact_id' => $contactId); list($contact) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, $skipOnHold, $skipDeceased, NULL, $messageToken, 'CRM_Contact_Form_Task_PDFLetterCommon'); if (civicrm_error($contact)) { $notSent[] = $contactId; continue; } $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken); if (!empty($form->_caseId)) { $caseId = $form->_caseId; } if (empty($caseId) && !empty($form->_caseIds[$item])) { $caseId = $form->_caseIds[$item]; } if ($caseId) { $tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseId, $tokenHtml, $messageToken); } $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, TRUE); if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) { $smarty = CRM_Core_Smarty::singleton(); // also add the contact tokens to the template $smarty->assign_by_ref('contact', $contact); $tokenHtml = $smarty->fetch("string:{$tokenHtml}"); } $html[] = $tokenHtml; } $type = $formValues['document_type']; if ($type == 'pdf') { CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues); } elseif (!empty($formValues['document_file_path'])) { CRM_Utils_PDF_Document::printDocuments($formValues['document_file_path'], $html, $type, $zip); } else { CRM_Utils_PDF_Document::html2doc($html, "CiviLetter.{$type}", $formValues); } $form->postProcessHook(); CRM_Utils_System::civiExit(1); }