Skip to content

Commit

Permalink
Use new money formatting util for smarty formatting
Browse files Browse the repository at this point in the history
This switches us from the old function to the new function
  • Loading branch information
eileenmcnaughton committed Dec 29, 2021
1 parent 78c122b commit ae29360
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 53 deletions.
6 changes: 3 additions & 3 deletions CRM/Core/Smarty/plugins/modifier.crmMoney.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
*
* @param float $amount
* The monetary amount up for display.
* @param string $currency
* @param string|null $currency
* The (optional) currency.
*
* @return string
* formatted monetary amount
*
* @throws \CRM_Core_Exception
*/
function smarty_modifier_crmMoney($amount, $currency = NULL) {
return CRM_Utils_Money::format($amount, $currency);
function smarty_modifier_crmMoney($amount, ?string $currency = NULL): string {
return Civi::format()->money($amount, $currency);
}
9 changes: 4 additions & 5 deletions tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ public function testDashboardContentContributionsWithInvoicingEnabled(): void {
/**
* Test the content of the dashboard.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testDashboardContentContributions() {
public function testDashboardContentContributions(): void {
$this->contributionCreate(['contact_id' => $this->contactID]);
$this->contributions[] = civicrm_api3('Contribution', 'get', [
'contact_id' => $this->contactID,
Expand All @@ -151,7 +150,7 @@ public function testDashboardContentContributions() {
$expectedStrings = [
'Your Contribution(s)',
'<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th>',
'<td>$ 100.00 </td><td>Donation</td>',
'<td>$100.00 </td><td>Donation</td>',
'<td>Completed</td>',
];
$this->assertPageContains($expectedStrings);
Expand Down Expand Up @@ -183,8 +182,8 @@ public function testDashboardPartialPayments() {
$expectedStrings = [
'Your Contribution(s)',
'<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th>',
'<td>$ 25.00 </td><td>Donation</td>',
'<td>$ 14.00</td><td>Partially paid</td>',
'<td>$25.00 </td><td>Donation</td>',
'<td>$14.00</td><td>Partially paid</td>',
'Pay Now',
];
$this->assertPageContains($expectedStrings);
Expand Down
20 changes: 10 additions & 10 deletions tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public function testAddPaymentUsingCreditCardForPartiallyPaidContribution() {
'From: [email protected]',
'Dear Anthony,',
'Payment Details',
'Total Fee: $ 100.00',
'This Payment Amount: $ 70.00',
'Balance Owed: $ 0.00 ',
'Total Fee: $100.00',
'This Payment Amount: $70.00',
'Balance Owed: $0.00 ',
'Billing Name and Address',
'Vancouver, AE 1321312',
'Visa',
Expand Down Expand Up @@ -180,7 +180,7 @@ public function testAddPaymentForPartiallyPaidContribution() {
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testMultiplePaymentForPartiallyPaidContribution() {
public function testMultiplePaymentForPartiallyPaidContribution(): void {
$this->createPartiallyPaidOrder();

// pay additional amount
Expand Down Expand Up @@ -236,9 +236,9 @@ public function testMultiplePaymentForPartiallyPaidContributionWithOneCreditCard
$mut->checkMailLog([
'Dear Anthony,',
'Below you will find a receipt for this payment.',
'Total Fee: $ 100.00',
'This Payment Amount: $ 50.00',
'Balance Owed: $ 20.00 ',
'Total Fee: $100.00',
'This Payment Amount: $50.00',
'Balance Owed: $20.00 ',
'Paid By: Check',
'Check Number: check-12345',
],
Expand Down Expand Up @@ -266,9 +266,9 @@ public function testAddPaymentUsingCreditCardForPendingPayLaterContribution() {

$mut->checkMailLog([
'Below you will find a receipt for this payment.',
'Total Fee: $ 100.00',
'This Payment Amount: $ 100.00',
'Balance Owed: $ 0.00 ',
'Total Fee: $100.00',
'This Payment Amount: $100.00',
'Balance Owed: $0.00 ',
'Paid By: Credit Card',
'***********1111',
'Billing Name and Address',
Expand Down
16 changes: 7 additions & 9 deletions tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testInvoiceForDueDate() {
$this->assertStringContainsString('PAYMENT ADVICE', $invoiceHTML[$contribution['id']]);

$this->assertStringContainsString('AMOUNT DUE:</font></b></td>
<td style="text-align:right;"><b><font size="1">$ 92.00</font></b></td>', $invoiceHTML[$contribution3['id']]);
<td style="text-align:right;"><b><font size="1">$92.00</font></b></td>', $invoiceHTML[$contribution3['id']]);
}

/**
Expand All @@ -86,7 +86,7 @@ public function testInvoiceForDueDate() {
*
* @throws \CRM_Core_Exception
*/
public function testInvoiceForLineItems() {
public function testInvoiceForLineItems(): void {

$this->enableTaxAndInvoicing();

Expand Down Expand Up @@ -154,23 +154,21 @@ public function testInvoiceForLineItems() {
$lineItems = $this->callAPISuccess('LineItem', 'get', ['contribution_id' => $order['id']]);

foreach ($lineItems['values'] as $lineItem) {
$this->assertStringContainsString("<font size=\"1\">$ {$lineItem['line_total']}</font>", $invoiceHTML);
$this->assertStringContainsString("<font size=\"1\">$" . $lineItem['line_total'] . '</font>', $invoiceHTML);
}

$totalAmount = $this->formatMoneyInput($order['values'][$order['id']]['total_amount']);
$this->assertStringContainsString("TOTAL USD</font></b></td>
<td style=\"text-align:right;\"><font size=\"1\">$ $totalAmount</font>", $invoiceHTML);
<td style=\"text-align:right;\"><font size=\"1\">$" . $totalAmount . '</font>', $invoiceHTML);

}

/**
* Test invoices if payment is made with different currency.
*
* https://lab.civicrm.org/dev/core/issues/2269
*
* @throws \CRM_Core_Exception
*/
public function testThatInvoiceShowTheActuallContributionCurrencyInsteadOfTheDefaultOne() {
public function testThatInvoiceShowsTheActualContributionCurrencyInsteadOfTheDefaultOne(): void {
$this->setDefaultCurrency('USD');

$this->_individualId = $this->individualCreate();
Expand All @@ -187,8 +185,8 @@ public function testThatInvoiceShowTheActuallContributionCurrencyInsteadOfTheDef
$this->assertStringNotContainsString('$', $invoiceHTML);
$this->assertStringNotContainsString('Amount USD', $invoiceHTML);
$this->assertStringNotContainsString('TOTAL USD', $invoiceHTML);
$this->assertStringContainsString('£ 0.00', $invoiceHTML);
$this->assertStringContainsString('£ 100.00', $invoiceHTML);
$this->assertStringContainsString('£0.00', $invoiceHTML);
$this->assertStringContainsString('£100.00', $invoiceHTML);
$this->assertStringContainsString('Amount GBP', $invoiceHTML);
$this->assertStringContainsString('TOTAL GBP', $invoiceHTML);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public function testPostProcessGroupByContact(): void {
-->
<tr>
<td>25 December 2016</td>
<td>$ 100.00</td>
<td>$100.00</td>
<td>Donation</td>
<td></td>
</tr>
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function testIPNPaymentMembershipRecurSuccessNoLeakage(): void {
$mut->checkAllMailLog([
'Membership Type: General',
'Mr. Anthony Anderson II" <[email protected]>',
'Amount: $ 200.00',
'Amount: $200.00',
'Membership Start Date:',
'Supporter Profile',
'First Name: Anthony',
Expand All @@ -323,7 +323,7 @@ public function testIPNPaymentMembershipRecurSuccessNoLeakage(): void {
'Membership Type: General',
'Mrs. Antonia Anderson II',
'[email protected]',
'Amount: $ 200.00',
'Amount: $200.00',
'Membership Start Date:',
'Transaction #: hers',
'Supporter Profile',
Expand Down Expand Up @@ -363,7 +363,7 @@ public function testIPNPaymentMembershipRecurSuccessNoLeakageOnlineThenOffline()
$mut->checkAllMailLog([
'Membership Type: General',
'Mr. Anthony Anderson II" <[email protected]>',
'Amount: $ 200.00',
'Amount: $200.00',
'Membership Start Date:',
'Supporter Profile',
'First Name: Anthony',
Expand All @@ -387,7 +387,7 @@ public function testIPNPaymentMembershipRecurSuccessNoLeakageOnlineThenOffline()
'Membership Type: General',
'Mrs. Antonia Anderson II',
'[email protected]',
'Amount: $ 200.00',
'Amount: $200.00',
'Membership Start Date:',
'Transaction #: hers',
'This membership will be automatically renewed every',
Expand Down
9 changes: 4 additions & 5 deletions tests/phpunit/CRM/Member/Form/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
*
* Connect to the database, truncate the tables that will be used
* and redirect stdin to a temporary file.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function setUp(): void {
$this->_apiversion = 3;
Expand Down Expand Up @@ -567,7 +564,7 @@ public function testSubmit(string $thousandSeparator): void {
]),
], 'online');
$this->mut->checkMailLog([
CRM_Utils_Money::format('1234.56'),
Civi::format()->money('1234.56'),
'Receipt text',
]);
$this->mut->stop();
Expand Down Expand Up @@ -1269,11 +1266,13 @@ public function buildAmountMembershipDiscount($pageType, &$form, &$amount) {
*
* @return \CRM_Member_Form_Membership
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
protected function getForm($formValues = []) {
protected function getForm($formValues = []): CRM_Member_Form_Membership {
if (isset($_REQUEST['cid'])) {
unset($_REQUEST['cid']);
}
/* @var CRM_Member_Form_Membership $form*/
$form = $this->getFormObject('CRM_Member_Form_Membership', $formValues);
$form->preProcess();
return $form;
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/api/v3/ContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public function testSubmitMembershipBlockIsSeparatePaymentPayLaterWithEmail(): v
$this->assertCount(2, $contributions);
$this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => ['IN' => array_keys($contributions)]]);
$mut->checkMailLog([
'Membership Amount -... $ 2.00',
'Membership Amount -... $2.00',
]);
$mut->stop();
$mut->clearMessages();
Expand Down Expand Up @@ -555,8 +555,8 @@ public function testSubmitMembershipBlockIsSeparatePaymentWithEmail(): void {
// line and no total line.
$mut->checkAllMailLog(
[
'Amount: $ 2.00',
'Amount: $ 88.00',
'Amount: $2.00',
'Amount: $88.00',
'Membership Fee',
],
[
Expand Down Expand Up @@ -591,7 +591,7 @@ public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWit
$this->assertEquals($membership['contact_id'], $contributions[$membershipPayment['contribution_id']]['contact_id']);
$mut->checkMailLog([
'Gruff',
'General Membership: $ 0.00',
'General Membership: $0.00',
'Membership Fee',
]);
$mut->stop();
Expand Down Expand Up @@ -662,7 +662,7 @@ public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow():
}
// The total string is currently absent & it seems worse with - although at some point
// it may have been intended
$mut->checkAllMailLog(['$ 2.00', 'Contribution Amount', '$ 88.00'], ['Total:']);
$mut->checkAllMailLog(['$2.00', 'Contribution Amount', '$88.00'], ['Total:']);
$mut->stop();
$mut->clearMessages();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3652,7 +3652,7 @@ public function testSendMail(): void {
'receipt_from_email' => '[email protected]',
]);
$mut->checkMailLog([
'$ 100.00',
'$100.00',
'Contribution Information',
], [
'Event',
Expand Down
20 changes: 10 additions & 10 deletions tests/phpunit/api/v3/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function testPaymentSendContributionReceipt(): void {
$contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]);
$this->assertNotEmpty($contribution['receipt_date']);
$mut->checkMailLog([
'Price Field - Price Field 1 1 $ 100.00 $ 100.00',
'Price Field - Price Field 1 1 $100.00 $100.00',
'event place',
'streety street',
]);
Expand Down Expand Up @@ -293,10 +293,10 @@ public function testPaymentEmailReceipt(): void {
$mut->checkMailLog([
'From: "FIXME" <[email protected]>',
'Dear Anthony,',
'Total Fee: $ 300.00',
'This Payment Amount: $ 50.00',
'Total Fee: $300.00',
'This Payment Amount: $50.00',
//150 was paid in the 1st payment.
'Balance Owed: $ 100.00',
'Balance Owed: $100.00',
'Event Information and Location',
'Paid By: Check',
'Check Number: 345',
Expand Down Expand Up @@ -331,9 +331,9 @@ public function testPaymentEmailReceiptFullyPaid(): void {
'From: "FIXME" <[email protected]>',
'Dear Anthony,',
'Below you will find a receipt for this payment.',
'Total Fee: $ 300.00',
'This Payment Amount: $ 150.00',
'Balance Owed: $ 0.00',
'Total Fee: $300.00',
'This Payment Amount: $150.00',
'Balance Owed: $0.00',
'Thank you for completing this payment.',
]);
}
Expand Down Expand Up @@ -382,12 +382,12 @@ public function testRefundEmailReceipt(string $thousandSeparator): void {
$mut->checkMailLog([
'Dear Anthony,',
'A refund has been issued based on changes in your registration selections.',
'Total Fee: $ 300' . $decimalSeparator . '00',
'Refund Amount: $ -30' . $decimalSeparator . '00',
'Total Fee: $300' . $decimalSeparator . '00',
'Refund Amount: -$30' . $decimalSeparator . '00',
'Event Information and Location',
'Paid By: Check',
'Transaction Date: November 13th, 2018 12:01 PM',
'Total Paid: $ 170' . $decimalSeparator . '00',
'Total Paid: $170' . $decimalSeparator . '00',
]);
}

Expand Down

0 comments on commit ae29360

Please sign in to comment.