Add second currency example
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 28 Jun 2022 05:35:33 +0000 (17:35 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 29 Jun 2022 02:21:37 +0000 (14:21 +1200)
CRM/Contribute/WorkflowMessage/Contribution/BasicContribution.php

index 954385ac82e7b848b461c24511303598de345352..bce3c8ca0ff25466157cddf255444a52dad20e23 100644 (file)
@@ -19,11 +19,18 @@ class CRM_Contribute_WorkflowMessage_Contribution_BasicContribution extends Work
     $workflows = ['contribution_online_receipt', 'contribution_offline_receipt', 'contribution_invoice_receipt'];
     foreach ($workflows as $workflow) {
       yield [
-        'name' => 'workflow/' . $workflow . '/' . $this->getExampleName(),
-        'title' => ts('Completed Contribution'),
+        'name' => 'workflow/' . $workflow . '/basic_eur',
+        'title' => ts('Completed Contribution') . ' : ' . 'CAD',
         'tags' => ['preview'],
         'workflow' => $workflow,
       ];
+      yield [
+        'name' => 'workflow/' . $workflow . '/' . 'basic_cad',
+        'title' => ts('Completed Contribution') . ' : ' . 'CAD',
+        'tags' => ['preview'],
+        'workflow' => 'contribution_offline_receipt',
+        'currency' => 'CAD',
+      ];
     }
   }
 
@@ -33,14 +40,12 @@ class CRM_Contribute_WorkflowMessage_Contribution_BasicContribution extends Work
    * @param array $example
    *
    * @throws \API_Exception
-   * @throws \CRM_Core_Exception
-   * @throws \Civi\API\Exception\UnauthorizedException
    */
   public function build(array &$example): void {
     $workFlow = WorkflowMessage::get(TRUE)->addWhere('name', '=', $example['workflow'])->execute()->first();
     $this->setWorkflowName($workFlow['name']);
     $messageTemplate = new $workFlow['class']();
-    $this->addExampleData($messageTemplate);
+    $this->addExampleData($messageTemplate, $example);
     $example['data'] = $this->toArray($messageTemplate);
   }
 
@@ -48,16 +53,24 @@ class CRM_Contribute_WorkflowMessage_Contribution_BasicContribution extends Work
    * Add relevant example data.
    *
    * @param \CRM_Contribute_WorkflowMessage_ContributionOfflineReceipt|\CRM_Contribute_WorkflowMessage_ContributionOnlineReceipt|\CRM_Contribute_WorkflowMessage_ContributionInvoiceReceipt $messageTemplate
+   * @param array $example
    *
+   * @throws \API_Exception
    * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
+   * @throws \Civi\API\Exception\UnauthorizedException
    */
-  private function addExampleData(GenericWorkflowMessage $messageTemplate): void {
+  private function addExampleData(GenericWorkflowMessage $messageTemplate, $example): void {
     $messageTemplate->setContact(\Civi\Test::example('entity/Contact/Barb'));
-    $messageTemplate->setContribution(\Civi\Test::example('entity/Contribution/Euro5990/completed'));
+    $contribution = \Civi\Test::example('entity/Contribution/Euro5990/completed');
+    if (isset($example['currency'])) {
+      $contribution['currency'] = $example['currency'];
+    }
     $mockOrder = new CRM_Financial_BAO_Order();
     $mockOrder->setTemplateContributionID(50);
     $mockOrder->setPriceSetToDefault('contribution');
     $messageTemplate->setOrder($mockOrder);
+    $messageTemplate->setContribution($contribution);
   }
 
 }