CRM-18303 Test for sending contribution on complete trxn
authorEileen <eileen@fuzion.co.nz>
Tue, 12 Apr 2016 12:31:54 +0000 (12:31 +0000)
committerEileen <eileen@fuzion.co.nz>
Tue, 12 Apr 2016 13:18:45 +0000 (13:18 +0000)
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/ContributionTest.php
tests/templates/message_templates/contribution_online_receipt_html.tpl [new file with mode: 0644]

index dd1a107c461f30ee857cbae9be41c88dd8747a42..9fdc3a5f94aaf49d7be60366a079893562b4f062 100644 (file)
@@ -3402,4 +3402,40 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     return $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id));
   }
 
+  /**
+   * Replace the template with a test-oriented template designed to show all the variables.
+   *
+   * @param string $templateName
+   */
+  protected function swapMessageTemplateForTestTemplate($templateName = 'contribution_online_receipt') {
+    $testTemplate = file_get_contents(__DIR__ . '/../../templates/message_templates/' . $templateName . '_html.tpl');
+    CRM_Core_DAO::executeQuery(
+      "UPDATE civicrm_option_group og
+      LEFT JOIN civicrm_option_value ov ON ov.option_group_id = og.id
+      LEFT JOIN civicrm_msg_template m ON m.workflow_id = ov.id
+      SET m.msg_html = '{$testTemplate}'
+      WHERE og.name = 'msg_tpl_workflow_contribution'
+      AND ov.name = '{$templateName}'
+      AND m.is_default = 1"
+    );
+  }
+
+  /**
+   * Reinstate the default template.
+   *
+   * @param string $templateName
+   */
+  protected function revertTemplateToReservedTemplate($templateName = 'contribution_online_receipt') {
+    CRM_Core_DAO::executeQuery(
+      "UPDATE civicrm_option_group og
+      LEFT JOIN civicrm_option_value ov ON ov.option_group_id = og.id
+      LEFT JOIN civicrm_msg_template m ON m.workflow_id = ov.id
+      LEFT JOIN civicrm_msg_template m2 ON m2.workflow_id = ov.id AND m2.is_reserved = 1
+      SET m.msg_html = m2.msg_html
+      WHERE og.name = 'msg_tpl_workflow_contribution'
+      AND ov.name = '{$templateName}'
+      AND m.is_default = 1"
+    );
+  }
+
 }
index d536229bd8dbc36e1582b108a064b056722160cd..7f9fdbf078cb24dcbbb44f3d3c654d9171ef167d 100644 (file)
@@ -1993,6 +1993,42 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     $mut->stop();
   }
 
+
+  /**
+   * Complete the transaction using the template with all the possible.
+   */
+  public function testCompleteTransactionWithTestTemplate() {
+    $this->swapMessageTemplateForTestTemplate();
+    $mut = new CiviMailUtils($this, TRUE);
+    $this->createLoggedInUser();
+    $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
+    $contribution = $this->callAPISuccess('contribution', 'create', $params);
+    $this->callAPISuccess('contribution', 'completetransaction', array(
+      'id' => $contribution['id'],
+      'trxn_date' => date('2011-04-09'),
+      'trxn_id' => 'kazam',
+    ));
+    $receive_date = $this->callAPISuccess('Contribution', 'getvalue', array('id' => $contribution['id'], 'return' => 'receive_date'));
+    $mut->checkMailLog(array(
+      'email:::anthony_anderson@civicrm.org',
+      'is_monetary:::1',
+      'amount:::100.00',
+      'currency:::USD',
+      'receive_date:::' . date('Ymd', strtotime($receive_date)),
+      'receipt_date:::' . date('Ymd'),
+      'contributeMode:::notify',
+      'title:::Contribution',
+      'displayName:::Mr. Anthony Anderson II',
+      'trxn_id:::kazam',
+      'contactID:::' . $params['contact_id'],
+      'contributionID:::' . $contribution['id'],
+      'financialTypeId:::1',
+      'financialTypeName:::Donation',
+    ));
+    $mut->stop();
+    $this->revertTemplateToReservedTemplate();
+  }
+
   /**
    * Test completing first transaction in a recurring series.
    *
diff --git a/tests/templates/message_templates/contribution_online_receipt_html.tpl b/tests/templates/message_templates/contribution_online_receipt_html.tpl
new file mode 100644 (file)
index 0000000..e7a5bfc
--- /dev/null
@@ -0,0 +1,110 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+</head>
+<body>
+  receive_date:::{$receive_date}
+  receipt_date:::{$receipt_date}
+  receipt_text:::{$receipt_text}
+  is_pay_later:::{$is_pay_later}
+  displayName:::{$displayName}
+  financialTypeId:::{$financialTypeId}
+  financialTypeName:::{$financialTypeName}
+  contactID:::{$contactID}
+  contributionID:::{$contributionID}
+  amount:::{$amount}
+  amount_level:::{$amount_level}
+  pay_later_receipt:::{$pay_later_receipt}
+  headerStyle:::{$headerStyle}
+  valueStyle:::{$valueStyle}
+  labelStyle:::{$labelStyle}
+  priceSetID:::{$priceSetID}
+  currency:::{$currency}
+  is_quick_config:::{$is_quick_config}
+  getTaxDetails:::{$getTaxDetails}
+  totalTaxAmount:::{$totalTaxAmount}
+  is_monetary:::{$is_monetary}
+  isShare:::{$isShare}
+  honor_block_is_active:::{$honor_block_is_active}
+  soft_credit_type:::{$soft_credit_type}
+  is_recur:::{$is_recur}
+  contributeMode:::{$contributeMode}
+  trxn_id:::{$trxn_id}
+  cancelSubscriptionUrl:::{$cancelSubscriptionUrl}
+  updateSubscriptionBillingUrl:::{$updateSubscriptionBillingUrl}
+  updateSubscriptionUrl:::{$updateSubscriptionUrl}
+  priceset:::{$priceset}
+  taxTerm:::{$taxTerm}
+  pcpBlock:::{$pcpBlock}
+  pcp_display_in_roll:::{$pcp_display_in_roll}
+  pcp_roll_nickname:::{$pcp_roll_nickname}
+  pcp_personal_note:::{$pcp_personal_note}
+  onBehalfProfile_grouptitle:::{$onBehalfProfile_grouptitle}
+  email:::{$email}
+  contributionPageId:::{$contributionPageId}
+  title:::{$title}
+  isBillingAddressRequiredForPayLater:::{$isBillingAddressRequiredForPayLater}
+  billingName:::{$billingName}
+  address:::{$address}
+  credit_card_type:::{$credit_card_type}
+  credit_card_number:::{$credit_card_number}
+  credit_card_exp_date:::{$credit_card_exp_date}
+  selectPremium:::{$selectPremium}
+  product_name:::{$product_name}
+  option:::{$option}
+  sku:::{$sku}
+  start_date:::{$start_date}
+  end_date:::{$end_date}
+  is_deductible:::{$is_deductible}
+  contact_email:::{$contact_email}
+  contact_phone:::{$contact_phone}
+  price:::{$price}
+  customPre_grouptitle:::{$customPre_grouptitle}
+  customPost_grouptitle:::{$customPost_grouptitle}
+ {foreach from=$lineItem item=value key=priceset}
+  {foreach from=$value item=line}
+     line.html_type:::{$line.html_type}
+     line.label:::{$line.label}
+     line.field_title:::{$line.field_title}
+     line.description:::{$line.description}
+     line.qty:::{$line.qty}
+     line.unit_price:::{$line.unit_price}
+     line.tax_rate:::{$line.tax_rate}
+     line.tax_amount:::{$line.tax_amount}
+     line.line_total:::{$line.line_total}
+  {/foreach}
+ {/foreach}
+ {foreach from=$dataArray item=value key=priceset}
+    dataArray: priceset:::$priceset
+    dataArray: value:::$value
+ {/foreach}
+ {foreach from=$honoreeProfile item=value key=label}
+    honoreeProfile: label:::$label
+    honoreeProfile: value:::$value
+ {/foreach}
+ {foreach from=$softCreditTypes item=softCreditType key=n}
+    softCreditType:::$softCreditType
+  {foreach from=$softCredits.$n item=value key=label}
+     softCredits: label:::$label
+     softCredits: value:::$value
+  {/foreach}
+ {/foreach}
+ {foreach from=$onBehalfProfile item=onBehalfValue key=onBehalfName}
+    onBehalfName:::$onBehalfName
+    onBehalfValue:::$onBehalfValue
+ {/foreach}
+ {foreach from=$customPre item=customValue key=customName}
+    customPre: customName:::$customName
+    customPre: customValue:::$customValue
+ {/foreach}
+ {foreach from=$customPost item=customValue key=customName}
+    customPost: customName:::$customName
+    customPost: customValue:::$customValue
+ {/foreach}
+ {foreach from=$trackingFields item=trackingValue key=trackingName}
+   trackingName:::$trackingName
+   trackingValue:::$trackingValue
+ {/foreach}
+
+</body>
+</html>