View source
<?php
namespace Drupal\Tests\tamper\Unit\Plugin\Tamper;
use Drupal\tamper\Plugin\Tamper\NumberFormat;
class NumberFormatTest extends TamperPluginTestBase {
protected function instantiatePlugin() {
return new NumberFormat([], 'number_format', [], $this
->getMockSourceDefinition());
}
public function testNumberFormatDefault() {
$config = [
NumberFormat::SETTING_DECIMALS => '0',
NumberFormat::SETTING_DEC_POINT => '.',
NumberFormat::SETTING_THOUSANDS_SEP => ',',
];
$plugin = new NumberFormat($config, 'number_format', [], $this
->getMockSourceDefinition());
$this
->assertEquals('1,235', $plugin
->tamper('1234.56'));
}
public function testNumberFormatFrenchNotation() {
$config = [
NumberFormat::SETTING_DECIMALS => '2',
NumberFormat::SETTING_DEC_POINT => ',',
NumberFormat::SETTING_THOUSANDS_SEP => ' ',
];
$plugin = new NumberFormat($config, 'number_format', [], $this
->getMockSourceDefinition());
$this
->assertEquals('1 234,56', $plugin
->tamper('1234.56'));
}
public function testNumberFormatDefaultWithNumber() {
$config = [
NumberFormat::SETTING_DECIMALS => '2',
NumberFormat::SETTING_DEC_POINT => '.',
NumberFormat::SETTING_THOUSANDS_SEP => '',
];
$plugin = new NumberFormat($config, 'number_format', [], $this
->getMockSourceDefinition());
$this
->assertEquals('1234.57', $plugin
->tamper(1234.5678));
}
public function testNumberFormatFrenchNotationWithNumber() {
$config = [
NumberFormat::SETTING_DECIMALS => '2',
NumberFormat::SETTING_DEC_POINT => ',',
NumberFormat::SETTING_THOUSANDS_SEP => ' ',
];
$plugin = new NumberFormat($config, 'number_format', [], $this
->getMockSourceDefinition());
$this
->assertEquals('1 234,57', $plugin
->tamper(1234.5678));
}
}