3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Test class for CRM_Contact_Form_Task_PDFLetterCommon.
32 class CRM_Contact_Form_Task_PrintDocumentTest
extends CiviUnitTestCase
{
34 protected $_docTypes = NULL;
36 protected $_contactIds = NULL;
38 protected function setUp() {
40 $this->_contactIds
= array(
41 $this->individualCreate(array('first_name' => 'Antonia', 'last_name' => 'D`souza')),
42 $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins')),
44 $this->_docTypes
= CRM_Core_SelectValues
::documentApplicationType();
48 * Test the documents got token replaced rightfully.
50 public function testPrintDocument() {
51 foreach (array('docx', 'odt') as $docType) {
53 'document_file' => array(
54 'name' => __DIR__
. "/sample_documents/Template.$docType",
55 'type' => $this->_docTypes
[$docType],
58 $this->_testDocumentContent($formValues, $docType);
63 * Assert the content of document
65 * @param array $formValues
68 public function _testDocumentContent($formValues, $type) {
70 $form = new CRM_Contact_Form_Task_PDFLetterCommon();
71 list($formValues, $categories, $html_message, $messageToken, $returnProperties) = $form->processMessageTemplate($formValues);
72 list($html_message, $zip) = CRM_Utils_PDF_Document
::unzipDoc($formValues['document_file_path'], $formValues['document_type']);
74 foreach ($this->_contactIds
as $item => $contactId) {
75 $params = array('contact_id' => $contactId);
76 list($contact) = CRM_Utils_Token
::getTokenDetails($params,
82 'CRM_Contact_Form_Task_PDFLetterCommon'
84 $html[] = CRM_Utils_Token
::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
87 $fileName = pathinfo($formValues['document_file_path'], PATHINFO_FILENAME
) . '.' . $type;
88 $returnContent = CRM_Utils_PDF_Document
::printDocuments($html, $fileName, $type, $zip, TRUE);
89 $returnContent = strip_tags($returnContent);
91 $this->assertTrue(strpos($returnContent, 'Hello Antonia D`souza') !== 0);
92 $this->assertTrue(strpos($returnContent, 'Hello Anthony Collins') !== 0);