Commit | Line | Data |
---|---|---|
d013fe3d TR |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | Copyright CiviCRM LLC. All rights reserved. | | |
6 | | | | |
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 | +--------------------------------------------------------------------+ | |
11 | */ | |
12 | ||
13 | /** | |
14 | * Test class for CRM_Contact_Form_Task_PDFLetterCommon. | |
15 | * | |
16 | * @group headless | |
17 | */ | |
18 | class CRM_Contact_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { | |
19 | ||
20 | /** | |
21 | * Contact ID. | |
22 | * | |
23 | * @var int | |
24 | */ | |
25 | protected $contactId; | |
26 | ||
27 | /** | |
28 | * {@inheritdoc} | |
29 | */ | |
30 | protected function setUp(): void { | |
31 | parent::setUp(); | |
32 | $this->contactId = $this->createLoggedInUser(); | |
33 | } | |
34 | ||
35 | /** | |
36 | * Test the pdf filename is assigned as expected. | |
37 | * | |
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. | |
46 | * | |
47 | * @dataProvider getFilenameCases | |
48 | */ | |
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, | |
54 | '_contactIds' => [], | |
55 | 'document_type' => 'pdf', | |
56 | 'buttons' => [ | |
57 | '_qf_PDF_upload' => $isLiveMode, | |
58 | ], | |
59 | ]); | |
60 | $fileNameAssigned = NULL; | |
61 | $form->preProcess(); | |
62 | try { | |
63 | $form->postProcess(); | |
64 | } | |
65 | catch (CRM_Core_Exception_PrematureExitException $e) { | |
66 | $fileNameAssigned = $e->errorData['fileName']; | |
67 | } | |
68 | ||
69 | $this->assertEquals($expectedFilename, $fileNameAssigned); | |
70 | } | |
71 | ||
72 | /** | |
73 | * DataProvider for testFilenameIsAssigned. | |
74 | * | |
75 | * @return array | |
76 | * Array with the test information. | |
77 | */ | |
78 | public function getFilenameCases(): array { | |
79 | return [ | |
80 | [ | |
81 | 'FilenameInParam', | |
82 | 'FilenameInActivitySubject', | |
83 | NULL, | |
84 | 'FilenameInParam_preview', | |
85 | ], | |
86 | [ | |
87 | 'FilenameInParam', | |
88 | 'FilenameInActivitySubject', | |
89 | TRUE, | |
90 | 'FilenameInParam', | |
91 | ], | |
92 | [ | |
93 | NULL, | |
94 | 'FilenameInActivitySubject', | |
95 | NULL, | |
96 | 'FilenameInActivitySubject_preview', | |
97 | ], | |
98 | [ | |
99 | NULL, | |
100 | 'FilenameInActivitySubject', | |
101 | TRUE, | |
102 | 'FilenameInActivitySubject', | |
103 | ], | |
104 | [ | |
105 | NULL, | |
106 | NULL, | |
107 | NULL, | |
108 | 'CiviLetter_preview', | |
109 | ], | |
110 | [ | |
111 | NULL, | |
112 | NULL, | |
113 | TRUE, | |
114 | 'CiviLetter', | |
115 | ], | |
116 | ]; | |
117 | } | |
118 | ||
119 | } |