Skip to content

Commit

Permalink
Add supporting test
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 6, 2020
1 parent e9411af commit 2fb1811
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CRM/Contact/Form/Task/LabelCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
53 changes: 53 additions & 0 deletions tests/phpunit/CRM/Member/Form/Task/LabelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* @package CiviCRM_APIv3
* @subpackage API_Contribution
* @group headless
*/
class CRM_Member_Form_Task_LabelTest extends CiviUnitTestCase {

/**
* Test print label.
*
* This is a 'no error' test to support refactoring. It ensures no fatal is hit & lays
* the basis for more tests later.
*/
public function testMembershipTokenReplacementInPDF() {
// First check tasks are there is some weird static caching that could mess us up.
$tasks = CRM_Member_Task::tasks();
$this->assertArrayHasKey(201, $tasks);
$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']);
}
}

}

0 comments on commit 2fb1811

Please sign in to comment.