3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Test class for CRM_Contact_Form_Task_PDFLetterCommon.
16 class CRM_Contact_Form_Task_PrintDocumentTest
extends CiviUnitTestCase
{
18 protected $_docTypes = NULL;
20 protected $_contactIds = NULL;
22 protected function setUp() {
24 $this->_contactIds
= [
25 $this->individualCreate(['first_name' => 'Antonia', 'last_name' => 'D`souza']),
26 $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']),
28 $this->_docTypes
= CRM_Core_SelectValues
::documentApplicationType();
32 * Test the documents got token replaced rightfully.
34 public function testPrintDocument() {
35 foreach (['docx', 'odt'] as $docType) {
38 'name' => __DIR__
. "/sample_documents/Template.$docType",
39 'type' => $this->_docTypes
[$docType],
42 $this->_testDocumentContent($formValues, $docType);
47 * Assert the content of document
49 * @param array $formValues
52 public function _testDocumentContent($formValues, $type) {
54 $form = new CRM_Contact_Form_Task_PDFLetterCommon();
55 list($formValues, $categories, $html_message, $messageToken, $returnProperties) = $form->processMessageTemplate($formValues);
56 list($html_message, $zip) = CRM_Utils_PDF_Document
::unzipDoc($formValues['document_file_path'], $formValues['document_type']);
58 foreach ($this->_contactIds
as $item => $contactId) {
59 $params = ['contact_id' => $contactId];
60 list($contact) = CRM_Utils_Token
::getTokenDetails($params,
66 'CRM_Contact_Form_Task_PDFLetterCommon'
68 $html[] = CRM_Utils_Token
::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
71 $fileName = pathinfo($formValues['document_file_path'], PATHINFO_FILENAME
) . '.' . $type;
72 $returnContent = CRM_Utils_PDF_Document
::printDocuments($html, $fileName, $type, $zip, TRUE);
73 $returnContent = strip_tags($returnContent);
75 $this->assertTrue(strpos($returnContent, 'Hello Antonia D`souza') !== 0);
76 $this->assertTrue(strpos($returnContent, 'Hello Anthony Collins') !== 0);