From b80f2ad175aa2cec13e02b498f392c2ddba96654 Mon Sep 17 00:00:00 2001 From: Eileen Date: Tue, 12 Apr 2016 12:31:54 +0000 Subject: [PATCH] CRM-18303 Test for sending contribution on complete trxn --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 36 ++++++ tests/phpunit/api/v3/ContributionTest.php | 36 ++++++ .../contribution_online_receipt_html.tpl | 110 ++++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 tests/templates/message_templates/contribution_online_receipt_html.tpl diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index dd1a107c46..9fdc3a5f94 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -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" + ); + } + } diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index d536229bd8..7f9fdbf078 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -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 index 0000000000..e7a5bfc52c --- /dev/null +++ b/tests/templates/message_templates/contribution_online_receipt_html.tpl @@ -0,0 +1,110 @@ + + + + + + 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} + + + -- 2.25.1