public function CommerceBaseTesterTestCase::testCurrencyRounding in Commerce Core 7
Test the currency value rounding.
File
- tests/
commerce_base.test, line 919 - Defines abstract base test class for the Commerce module tests.
Class
- CommerceBaseTesterTestCase
- Test class to test the CommerceBaseTestCase functions. All testTestFoo functions have "testTest" in the name to indicate that they are verifying that a test is working. Somewhat "meta" to do this, but it eases test development.
Code
public function testCurrencyRounding() {
// array( rounding_step => array( 'value' => 'expected result'));
$rounding_numbers = array(
'0.05' => array(
'1' => '1',
'5' => '5',
'777' => '777',
'1.22' => '1.20',
'12.2249' => '12.20',
'1200.225' => '1200.25',
'0.2749' => '0.25',
'490.275' => '490.30',
),
'0.02' => array(
'1' => '1',
'777' => '777',
'1.205' => '1.20',
'12.20999' => '12.20',
'1200.21' => '1200.22',
'0.26999' => '0.26',
'490.2712' => '490.28',
),
'0.5' => array(
'1' => '1',
'5' => '5',
'1.22' => '1',
'12.2499' => '12',
'1200.25' => '1200.5',
'0.749' => '0.5',
'490.75' => '491.0',
),
'0.2' => array(
'1' => '1',
'777' => '777',
'1.05' => '1',
'12.0999' => '12',
'1200.1' => '1200.2',
'0.6999' => '0.6',
'490.712' => '490.8',
),
);
foreach ($rounding_numbers as $rounding_step => $numbers) {
foreach ($numbers as $input => $output) {
$currency = array(
'decimals' => 2,
'rounding_step' => $rounding_step,
);
$result = commerce_currency_round($input, $currency);
$this
->assertEqual($result, $output, t('Rounding !input to !output with the rounding step: !rounding_step', array(
'!input' => $input,
'!output' => $output,
'!rounding_step' => $rounding_step,
)));
}
}
}