silverstripe-framework/tests/model/DBCurrencyTest.php
Sam Minnee aeccb8b8e0 API: Move DBField subclasses into SilverStripe\Model\FieldType namespace
API: Deprecate SS_Datetime.

The DBField subclasses are have all been renamed to start with “DB” and
be in the SilverStripe\Model\FieldType namespace. To keep DataObject
definitions concise, the original short variations of their names are
preserved as service definitions. Most of the field generation code
doesn’t need to change, but where field classes are referenced directly,
changes will be needed.

SS_Datetime, which is commonly referenced outside the model system
itself, has been preserved as a subclass of DBDatetime. This has been
marked as deprecated and can be removed in SilverStripe 5.

A few places that referred to $db and $casting values weren’t using
the Injector to instantiate the relevant classes. This meant that the
remapping we have created as part of moving classes into a namespace
didn’t work.
2016-03-22 18:09:30 +13:00

45 lines
1.3 KiB
PHP

<?php
use SilverStripe\Model\FieldType\DBCurrency;
/**
* @package framework
* @subpackage tests
*/
class DBCurrencyTest extends SapphireTest {
public function testNiceFormatting() {
// Test a bunch of different data values and results in Nice() and Whole()
$tests = array(
// Test basic operation
'$50.00' => array('$50.00', '$50'),
// Test removal of junk text
'this is -50.29 dollars' => array('($50.29)', '($50)'),
'this is -50.79 dollars' => array('($50.79)', '($51)'),
'this is 50.79 dollars' => array('$50.79', '$51'),
// Test negative numbers
'-1000' => array('($1,000.00)','($1,000)'),
'-$2,000' => array('($2,000.00)', '($2,000)'),
// Test thousands comma
'5000' => array('$5,000.00', '$5,000'),
// Test scientific notation
'5.68434188608E-14' => array('$0.00', '$0'),
'5.68434188608E7' => array('$56,843,418.86', '$56,843,419'),
"Sometimes Es are still bad: 51 dollars, even though they\'re used in scientific notation"
=> array('$51.00', '$51'),
"What about 5.68434188608E7 in the middle of a string" => array('$56,843,418.86', '$56,843,419'),
);
foreach($tests as $value => $niceValues) {
$c = new DBCurrency('MyField');
$c->setValue($value);
$this->assertEquals($niceValues[0], $c->Nice());
$this->assertEquals($niceValues[1], $c->Whole());
}
}
}