From 362a820de3a9bb6874e84735f931cea949798d48 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 6 Oct 2020 12:11:38 +1300 Subject: [PATCH] Add supporting test --- CRM/Contact/Form/Task/LabelCommon.php | 5 +- .../CRM/Member/Form/Task/LabelTest.php | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/CRM/Member/Form/Task/LabelTest.php diff --git a/CRM/Contact/Form/Task/LabelCommon.php b/CRM/Contact/Form/Task/LabelCommon.php index 8265c5a4e1..5b7a295e87 100644 --- a/CRM/Contact/Form/Task/LabelCommon.php +++ b/CRM/Contact/Form/Task/LabelCommon.php @@ -30,7 +30,10 @@ class CRM_Contact_Form_Task_LabelCommon { * @param string $fileName * The name of the file to save the label in. */ - public static function createLabel(&$contactRows, &$format, $fileName = 'MailingLabels_CiviCRM.pdf') { + public static function createLabel($contactRows, $format, $fileName = 'MailingLabels_CiviCRM.pdf') { + if (CIVICRM_UF === 'UnitTests') { + throw new CRM_Core_Exception_PrematureExitException('civiExit called', ['rows' => $contactRows, 'format' => $format, 'file_name' => $fileName]); + } $pdf = new CRM_Utils_PDF_Label($format, 'mm'); $pdf->Open(); $pdf->AddPage(); diff --git a/tests/phpunit/CRM/Member/Form/Task/LabelTest.php b/tests/phpunit/CRM/Member/Form/Task/LabelTest.php new file mode 100644 index 0000000000..2860d6e657 --- /dev/null +++ b/tests/phpunit/CRM/Member/Form/Task/LabelTest.php @@ -0,0 +1,53 @@ +assertArrayHasKey(201, $tasks, print_r($tasks, TRUE)); + $tasks = CRM_Member_Task::permissionedTaskTitles(CRM_Core_Permission::EDIT); + $this->assertArrayHasKey(201, $tasks); + $membershipID = $this->contactMembershipCreate(['contact_id' => $this->individualCreate()]); + /* @var CRM_Member_Form_Task_Label $form */ + $form = $this->getFormObject('CRM_Member_Form_Task_Label', [ + 'task' => 201, + 'radio_ts' => 'ts_sel', + ], 'Search'); + + $_SESSION['_' . $form->controller->_name . '_container']['values']['Label'] = [ + 'location_type_id' => NULL, + 'label_name' => 3475, + ]; + $form->preProcess(); + $form->ids = [$membershipID => $membershipID]; + $form->buildForm(); + try { + $form->postProcess(); + } + catch (CRM_Core_Exception_PrematureExitException $e) { + $this->assertEquals(3475, $e->errorData['format']); + } + } + +} -- 2.25.1