diff --git a/CRM/Badge/BAO/Badge.php b/CRM/Badge/BAO/Badge.php
index fc98961f7a57b213d0e76d9ab81633bb99618648..e501e95ff7515f35933e7b46b94769b61760276c 100644
--- a/CRM/Badge/BAO/Badge.php
+++ b/CRM/Badge/BAO/Badge.php
@@ -40,7 +40,7 @@ class CRM_Badge_BAO_Badge {
    * @param array $layoutInfo
    *   Associated array which contains meta data about format/layout.
    */
-  public function createLabels(&$participants, &$layoutInfo) {
+  public function createLabels($participants, &$layoutInfo) {
     $this->pdf = new CRM_Utils_PDF_Label($layoutInfo['format'], 'mm');
     $this->pdf->Open();
     $this->pdf->setPrintHeader(FALSE);
@@ -58,6 +58,9 @@ class CRM_Badge_BAO_Badge {
       $this->pdf->AddPdfLabel($formattedRow);
     }
 
+    if (CIVICRM_UF === 'UnitTests') {
+      throw new CRM_Core_Exception_PrematureExitException('pdf output called', ['formattedRow' => $formattedRow]);
+    }
     $this->pdf->Output(CRM_Utils_String::munge($layoutInfo['title'], '_', 64) . '.pdf', 'D');
     CRM_Utils_System::civiExit();
   }
diff --git a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
index f554aa905895c1f0b6ae61e0c5042f44f3a06a9d..c92b9df4715f8d26ae76099f5f040526e9592dcf 100644
--- a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
+++ b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
@@ -710,7 +710,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
         'id' => $this->getCustomFieldID('link'),
         'label' => 'test_link',
         'groupTitle' => 'Custom Group',
-        'default_value' => 'http://civicrm.org',
+        'default_value' => 'https://civicrm.org',
         'custom_group_id' => $customGroupID,
         'extends' => 'Contact',
         'extends_entity_column_value' => NULL,
diff --git a/tests/phpunit/CRM/Event/Form/Task/BadgeTest.php b/tests/phpunit/CRM/Event/Form/Task/BadgeTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..6ba914bb56ab907325094f4c2a73e79fd44119fb
--- /dev/null
+++ b/tests/phpunit/CRM/Event/Form/Task/BadgeTest.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ *  Test CRM_Event_Form_Registration functions.
+ *
+ * @package   CiviCRM
+ * @group headless
+ */
+class CRM_Event_Form_Task_BadgeTest extends CiviUnitTestCase {
+
+  use CRMTraits_Custom_CustomDataTrait;
+
+  /**
+   * Test the the submit function on the event participant submit function.
+   */
+  public function testSubmit(): void {
+    $this->createCustomGroupWithFieldOfType(['extends' => 'Participant']);
+    $contactID = $this->individualCreate();
+    $participantID = $this->participantCreate(['contact_id' => $contactID]);
+
+    $_REQUEST['context'] = 'view';
+    $_REQUEST['id'] = $participantID;
+    $_REQUEST['cid'] = $contactID;
+    /* @var CRM_Event_Form_Task_Badge $form */
+    $form = $this->getFormObject(
+      'CRM_Event_Form_Task_Badge',
+      ['badge_id' => 1],
+      NULL,
+      [
+        'task' => CRM_Core_Task::BATCH_UPDATE,
+        'radio_ts' => 'ts_sel',
+        'mark_x_' . $participantID => 1,
+      ]
+    );
+    $form->buildForm();
+    try {
+      $form->postProcess();
+    }
+    catch (CRM_Core_Exception_PrematureExitException $e) {
+      $tokens = $e->errorData['formattedRow']['token'];
+      $this->assertEquals([
+        1 => [
+          'value' => 'Annual CiviCRM meet',
+          'font_name' => 'dejavusans',
+          'font_size' => '9',
+          'font_style' => '',
+          'text_alignment' => 'L',
+          'token' => '{event.title}',
+        ],
+        2 =>
+          [
+            'value' => 'Mr. Anthony Anderson II',
+            'font_name' => 'dejavusans',
+            'font_size' => '20',
+            'font_style' => '',
+            'text_alignment' => 'C',
+            'token' => '{contact.display_name}',
+          ],
+        3 =>
+          [
+            'value' => NULL,
+            'font_name' => 'dejavusans',
+            'font_size' => '15',
+            'font_style' => '',
+            'text_alignment' => 'C',
+            'token' => '{contact.current_employer}',
+          ],
+        4 =>
+          [
+            'value' => 'October 21st',
+            'font_name' => 'dejavusans',
+            'font_size' => '9',
+            'font_style' => '',
+            'text_alignment' => 'R',
+            'token' => '{event.start_date}',
+          ],
+      ], $tokens);
+      return;
+    }
+    $this->fail('Should not be reached');
+  }
+
+}
diff --git a/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php b/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php
index 5811015977b1fa55501c316797af9b1598e08ae1..533086074d0d01e67a9be6b7391b58ef9876911d 100644
--- a/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php
+++ b/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php
@@ -24,11 +24,8 @@ trait CRMTraits_Custom_CustomDataTrait {
    * Create a custom group with fields of multiple types.
    *
    * @param array $groupParams
-   *
-   * @throws \API_Exception
-   * @throws \Civi\API\Exception\UnauthorizedException
    */
-  public function createCustomGroupWithFieldsOfAllTypes($groupParams = []) {
+  public function createCustomGroupWithFieldsOfAllTypes(array $groupParams = []): void {
     $this->createCustomGroup($groupParams);
     $this->ids['CustomField'] = $this->createCustomFieldsOfAllTypes();
   }
@@ -39,11 +36,8 @@ trait CRMTraits_Custom_CustomDataTrait {
    * @param array $params
    *
    * @return int
-   *
-   * @throws \API_Exception
-   * @throws \Civi\API\Exception\UnauthorizedException
    */
-  public function createCustomGroup($params = []) {
+  public function createCustomGroup(array $params = []): int {
     $params = array_merge([
       'title' => 'Custom Group',
       'extends' => $this->entity ?? 'Contact',
@@ -52,7 +46,15 @@ trait CRMTraits_Custom_CustomDataTrait {
       'max_multiple' => 0,
     ], $params);
     $identifier = $params['name'] ?? $params['title'];
-    $this->ids['CustomGroup'][$identifier] = CustomGroup::create(FALSE)->setValues($params)->execute()->first()['id'];
+    try {
+      $this->ids['CustomGroup'][$identifier] = CustomGroup::create(FALSE)
+        ->setValues($params)
+        ->execute()
+        ->first()['id'];
+    }
+    catch (API_Exception $e) {
+      $this->fail('Could not create group ' . $e->getMessage());
+    }
     return $this->ids['CustomGroup'][$identifier];
   }
 
@@ -63,7 +65,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return string
    */
-  public function getCustomGroupTable($identifier = 'Custom Group') {
+  public function getCustomGroupTable(string $identifier = 'Custom Group'): string {
     return $this->callAPISuccessGetValue('CustomGroup', ['id' => $this->ids['CustomGroup'][$identifier], 'return' => 'table_name']);
   }
 
@@ -75,7 +77,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return string
    */
-  protected function getCustomFieldColumnName($key) {
+  protected function getCustomFieldColumnName(string $key): string {
     return $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID($key), 'return' => 'column_name']);
   }
 
@@ -90,7 +92,6 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @param array $fieldParams
    *
-   * @throws \API_Exception
    */
   public function createCustomGroupWithFieldOfType(array $groupParams = [], string $customFieldType = 'text', ?string $identifier = NULL, array $fieldParams = []): void {
     $supported = ['text', 'select', 'date', 'checkbox', 'int', 'contact_reference', 'radio', 'multi_country'];
@@ -141,7 +142,7 @@ trait CRMTraits_Custom_CustomDataTrait {
   /**
    * @return array
    */
-  public function createCustomFieldsOfAllTypes() {
+  public function createCustomFieldsOfAllTypes(): array {
     $customGroupID = $this->ids['CustomGroup']['Custom Group'];
     $ids = [];
     $ids['text'] = (int) $this->createTextCustomField(['custom_group_id' => $customGroupID])['id'];
@@ -171,7 +172,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return string
    */
-  protected function getCustomFieldName($key) {
+  protected function getCustomFieldName(string $key): string {
     return 'custom_' . $this->getCustomFieldID($key);
   }
 
@@ -184,7 +185,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    * @return int
    * @throws \API_Exception
    */
-  protected function addOptionToCustomField($key, $values) {
+  protected function addOptionToCustomField(string $key, array $values): int {
     $optionGroupID = CustomField::get(FALSE)
       ->addWhere('id', '=', $this->getCustomFieldID($key))
       ->addSelect('option_group_id')
@@ -205,7 +206,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return string
    */
-  protected function getCustomFieldID($key) {
+  protected function getCustomFieldID(string $key): string {
     return $this->ids['CustomField'][$key];
   }
 
@@ -245,7 +246,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createIntCustomField($params = []) {
+  protected function createIntCustomField(array $params = []): array {
     $params = array_merge($this->getFieldsValuesByType('Int'), $params);
     return $this->callAPISuccess('CustomField', 'create', $params)['values'][0];
   }
@@ -258,7 +259,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createBooleanCustomField($params = []) {
+  protected function createBooleanCustomField(array $params = []): array {
     $params = array_merge($this->getFieldsValuesByType('Boolean'), $params);
     return $this->callAPISuccess('CustomField', 'create', $params)['values'][0];
   }
@@ -271,7 +272,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createContactReferenceCustomField($params = []) {
+  protected function createContactReferenceCustomField(array $params = []): array {
     $params = array_merge($this->getFieldsValuesByType('ContactReference'), $params);
     return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
   }
@@ -284,7 +285,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createTextCustomField($params = []) {
+  protected function createTextCustomField(array $params = []): array {
     $params = array_merge($this->getFieldsValuesByType('String'), $params);
     return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
   }
@@ -297,7 +298,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createLinkCustomField($params = []) {
+  protected function createLinkCustomField(array $params = []): array {
     $params = array_merge($this->getFieldsValuesByType('Link'), $params);
     return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
   }
@@ -310,7 +311,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createCountryCustomField($params = []) {
+  protected function createCountryCustomField(array $params = []): array {
     $params = array_merge($this->getFieldsValuesByType('Country'), $params);
     return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
   }
@@ -323,7 +324,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createMultiCountryCustomField($params = []) {
+  protected function createMultiCountryCustomField(array $params = []): array {
     $params = array_merge($this->getFieldsValuesByType('Country', 'Multi-Select Country'), $params);
     return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
   }
@@ -336,7 +337,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createStateCustomField($params = []) {
+  protected function createStateCustomField(array $params = []): array {
     $params = array_merge($this->getFieldsValuesByType('StateProvince'), $params);
     return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
   }
@@ -349,7 +350,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createMultiStateCustomField($params = []) {
+  protected function createMultiStateCustomField(array $params = []): array {
     $params = array_merge($this->getFieldsValuesByType('StateProvince', 'Multi-Select State/Province'), $params);
     return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
   }
@@ -362,7 +363,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createFileCustomField($params = []) {
+  protected function createFileCustomField(array $params = []): array {
     $params = array_merge($this->getFieldsValuesByType('File'), $params);
     return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
   }
@@ -400,7 +401,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createDateCustomField($params): array {
+  protected function createDateCustomField(array $params): array {
     $params = array_merge($this->getFieldsValuesByType('Date'), $params);
     return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
   }
@@ -424,7 +425,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function createIntegerRadioCustomField($params): array {
+  protected function createIntegerRadioCustomField(array $params): array {
     $params = array_merge($this->getFieldsValuesByType('Int', 'Radio'), $params);
     return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
   }
@@ -432,12 +433,12 @@ trait CRMTraits_Custom_CustomDataTrait {
   /**
    * Get default field values for the type of field.
    *
-   * @param $dataType
+   * @param string $dataType
    * @param string $htmlType
    *
-   * @return mixed
+   * @return array
    */
-  public function getFieldsValuesByType($dataType, $htmlType = 'default') {
+  public function getFieldsValuesByType(string $dataType, string $htmlType = 'default'): array {
     $values = $this->getAvailableFieldCombinations()[$dataType];
     return array_merge([
       'is_searchable' => 1,
@@ -458,7 +459,7 @@ trait CRMTraits_Custom_CustomDataTrait {
    *
    * @return array
    */
-  protected function getAvailableFieldCombinations() {
+  protected function getAvailableFieldCombinations(): array {
     return [
       'String' => [
         'default' => [
@@ -816,7 +817,7 @@ trait CRMTraits_Custom_CustomDataTrait {
           'label' => 'test_link',
           'html_type' => 'Link',
           'data_type' => 'Link',
-          'default_value' => 'http://civicrm.org',
+          'default_value' => 'https://civicrm.org',
         ],
       ],
       'ContactReference' => [