Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - CRM-19701: Amount not formatted for currency without symbol. #9476

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CRM/Utils/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ public static function format($amount, $currency = NULL, $format = NULL, $onlyNu
}

if (!self::$_currencySymbols) {
self::$_currencySymbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array(
//CRM-19701: Filter out currencies which do not have symbol.
self::$_currencySymbols = array_filter(CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array(
'keyColumn' => 'name',
'labelColumn' => 'symbol',
));
))
);
}

if (!$currency) {
Expand Down
60 changes: 60 additions & 0 deletions tests/phpunit/CRM/Utils/MoneyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Class CRM_Utils_MoneyTest
* @group headless
*/
class CRM_Utils_MoneyTest extends CiviUnitTestCase {

/**
* Test CRM_Utils_Money::format()
*/
public function testFormat() {
$formattedAmount = CRM_Utils_Money::format(1000, 'USD');
$this->assertEquals('$ 1,000.00', $formattedAmount);

$formattedAmount = CRM_Utils_Money::format(1000, 'USD', '%a');
$this->assertEquals('1,000.00', $formattedAmount);

$formattedAmount = CRM_Utils_Money::format(1000, 'USD', '%C %a');
$this->assertEquals('USD 1,000.00', $formattedAmount);

$formattedAmount = CRM_Utils_Money::format(1000, 'USD', '%C %a', TRUE);
$this->assertEquals('1000.00', $formattedAmount);

$formattedAmount = CRM_Utils_Money::format(1000, 'CHE');
$this->assertEquals('CHE 1,000.00', $formattedAmount);

$formattedAmount = CRM_Utils_Money::format(1000, 'CHE', '%c %a');
$this->assertEquals('CHE 1,000.00', $formattedAmount);

$formattedAmount = CRM_Utils_Money::format(1000, 'CHE', '%c %a', TRUE);
$this->assertEquals('1000.00', $formattedAmount);
}

}