NumberHelperTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Tools\TestCase\View\Helper;
  3. use Tools\View\Helper\NumberHelper;
  4. use Cake\TestSuite\TestCase;
  5. use Cake\View\View;
  6. use Cake\Core\Configure;
  7. use Tools\Utility\Number;
  8. /**
  9. * Number Test Case
  10. */
  11. class NumberHelperTest extends TestCase {
  12. public function setUp() {
  13. parent::setUp();
  14. Configure::write('Localization', array(
  15. 'decimals' => ',',
  16. 'thousands' => '.'
  17. ));
  18. Number::config();
  19. $this->Number = new NumberHelper(new View(null));
  20. }
  21. /**
  22. * Test format
  23. *
  24. * TODO: move to NumberLib test?
  25. *
  26. * @return void
  27. */
  28. public function testFormat() {
  29. $is = $this->Number->format('22');
  30. $expected = '22';
  31. $this->assertEquals($expected, $is);
  32. $is = $this->Number->format('22.01');
  33. $expected = '22,01';
  34. $this->assertEquals($expected, $is);
  35. $is = $this->Number->format('22', ['places' => 2]);
  36. $expected = '22,00';
  37. $this->assertEquals($expected, $is);
  38. $is = $this->Number->format('22.30', array('places' => 1));
  39. $expected = '22,3';
  40. $this->assertEquals($expected, $is);
  41. $is = $this->Number->format('22.30', array('precision' => -1));
  42. $expected = '22';
  43. $this->assertEquals($expected, $is);
  44. $is = $this->Number->format('22.30', array('places' => 3));
  45. $expected = '22,300';
  46. $this->assertEquals($expected, $is);
  47. $is = $this->Number->format('abc', array('places' => 2));
  48. $expected = '0,00';
  49. $this->assertEquals($expected, $is);
  50. $is = $this->Number->format('22.3', array('places' => 2, 'before' => 'EUR '));
  51. $expected = 'EUR 22,30';
  52. $this->assertEquals($expected, $is);
  53. $is = $this->Number->format('22.3', array('places' => 2, 'after' => ' EUR'));
  54. $expected = '22,30 EUR';
  55. $this->assertEquals($expected, $is);
  56. $is = $this->Number->format('22.3', array('places' => 2, 'after' => 'x', 'before' => 'v'));
  57. $expected = 'v22,30x';
  58. $this->assertEquals($expected, $is);
  59. #TODO: more
  60. }
  61. public function tearDown() {
  62. parent::tearDown();
  63. unset($this->Number);
  64. }
  65. }