diff --git a/CRM/Contact/Form/Task/PDFLetterCommon.php b/CRM/Contact/Form/Task/PDFLetterCommon.php index f87eb267d02c..44716b10478e 100644 --- a/CRM/Contact/Form/Task/PDFLetterCommon.php +++ b/CRM/Contact/Form/Task/PDFLetterCommon.php @@ -42,22 +42,8 @@ public static function getLoggingOptions() { * @param CRM_Core_Form $form */ public static function preProcess(&$form) { - if (!isset($form->_single)) { - // @todo ensure this is already set. - $form->_single = FALSE; - } - $form->_emails = []; - - // @TODO remove these line and to it somewhere more appropriate. Currently some classes (e.g Case - // are having to re-write contactIds afterwards due to this inappropriate variable setting - // If we don't have any contact IDs, use the logged in contact ID - $form->_contactIds = $form->_contactIds ?: [CRM_Core_Session::getLoggedInContactID()]; - - $fromEmailValues = CRM_Core_BAO_Email::getFromEmail(); - - $form->_emails = $fromEmailValues; $defaults = []; - $form->_fromEmails = $fromEmailValues; + $form->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); if (is_numeric(key($form->_fromEmails))) { $emailID = (int) key($form->_fromEmails); $defaults = CRM_Core_BAO_Email::getEmailSignatureDefaults($emailID); @@ -66,19 +52,7 @@ public static function preProcess(&$form) { $defaults['from_email_address'] = current(CRM_Core_BAO_Domain::getNameAndEmail(FALSE, TRUE)); } $form->setDefaults($defaults); - $messageText = []; - $messageSubject = []; - $dao = new CRM_Core_BAO_MessageTemplate(); - $dao->is_active = 1; - $dao->find(); - while ($dao->fetch()) { - $messageText[$dao->id] = $dao->msg_text; - $messageSubject[$dao->id] = $dao->msg_subject; - } - - $form->assign('message', $messageText); - $form->assign('messageSubject', $messageSubject); - parent::preProcess($form); + $form->setTitle('Print/Merge Document'); } /** diff --git a/tests/phpunit/CRM/Contact/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contact/Form/Task/PDFLetterCommonTest.php index cdd3d9f3ad73..4b0ec36074e9 100644 --- a/tests/phpunit/CRM/Contact/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contact/Form/Task/PDFLetterCommonTest.php @@ -47,25 +47,19 @@ protected function setUp(): void { * @dataProvider getFilenameCases */ public function testFilenameIsAssigned(?string $pdfFileName, ?string $activitySubject, ?bool $isLiveMode, string $expectedFilename): void { + // @todo - remove this cid - it helps direct the form controller but is + // pretty cludgey. $_REQUEST['cid'] = $this->contactId; $form = $this->getFormObject('CRM_Contact_Form_Task_PDF', [ 'pdf_file_name' => $pdfFileName, 'subject' => $activitySubject, - '_contactIds' => [], 'document_type' => 'pdf', 'buttons' => [ '_qf_PDF_upload' => $isLiveMode, ], ]); - $fileNameAssigned = NULL; - $form->preProcess(); - try { - $form->postProcess(); - } - catch (CRM_Core_Exception_PrematureExitException $e) { - $fileNameAssigned = $e->errorData['fileName']; - } - + $form->_contactIds = [$this->contactId]; + $fileNameAssigned = $this->submitForm($form)['fileName']; $this->assertEquals($expectedFilename, $fileNameAssigned); } @@ -116,4 +110,21 @@ public function getFilenameCases(): array { ]; } + /** + * @param \CRM_Core_Form $form + * + * @return int|mixed + */ + protected function submitForm(CRM_Core_Form $form) { + $form->preProcess(); + try { + $form->postProcess(); + } + catch (CRM_Core_Exception_PrematureExitException $e) { + return $e->errorData; + + } + $this->fail('line should be unreachable'); + } + } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index e3220d8c3715..f51b6ba85751 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3336,7 +3336,6 @@ public function onPost($op, $objectName, $objectId, &$objectRef) { * @param string $pageName * * @return \CRM_Core_Form - * @throws \CRM_Core_Exception */ public function getFormObject($class, $formValues = [], $pageName = '') { $_POST = $formValues;