4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
14 * Test class for CRM_Contact_Form_Task_PDFLetterCommon.
18 class CRM_Contact_Form_Task_PDFLetterCommonTest
extends CiviUnitTestCase
{
30 protected function setUp(): void
{
32 $this->contactId
= $this->createLoggedInUser();
36 * Test the pdf filename is assigned as expected.
38 * @param string|null $pdfFileName
39 * Value for pdf_file_name param.
40 * @param string|null $activitySubject
41 * Value of the subject of the activity.
42 * @param bool|null $isLiveMode
43 * TRUE when the form is in live mode, NULL when it is a preview.
44 * @param string $expectedFilename
45 * Expected filename assigned to the pdf.
47 * @dataProvider getFilenameCases
49 public function testFilenameIsAssigned(?
string $pdfFileName, ?
string $activitySubject, ?
bool $isLiveMode, string $expectedFilename): void
{
50 $_REQUEST['cid'] = $this->contactId
;
51 $form = $this->getFormObject('CRM_Contact_Form_Task_PDF', [
52 'pdf_file_name' => $pdfFileName,
53 'subject' => $activitySubject,
55 'document_type' => 'pdf',
57 '_qf_PDF_upload' => $isLiveMode,
60 $fileNameAssigned = NULL;
65 catch (CRM_Core_Exception_PrematureExitException
$e) {
66 $fileNameAssigned = $e->errorData
['fileName'];
69 $this->assertEquals($expectedFilename, $fileNameAssigned);
73 * DataProvider for testFilenameIsAssigned.
76 * Array with the test information.
78 public function getFilenameCases(): array {
82 'FilenameInActivitySubject',
84 'FilenameInParam_preview',
88 'FilenameInActivitySubject',
94 'FilenameInActivitySubject',
96 'FilenameInActivitySubject_preview',
100 'FilenameInActivitySubject',
102 'FilenameInActivitySubject',
108 'CiviLetter_preview',