NumberHelperTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. $this->skipIf(true, 'FIXME');
  36. $is = $this->Number->format('22');
  37. $expected = '22,00';
  38. $this->assertEquals($expected, $is);
  39. $is = $this->Number->format('22.30', array('places' => 1));
  40. $expected = '22,3';
  41. $this->assertEquals($expected, $is);
  42. $is = $this->Number->format('22.30', array('places' => -1));
  43. $expected = '20';
  44. $this->assertEquals($expected, $is);
  45. $is = $this->Number->format('22.30', array('places' => -2));
  46. $expected = '0';
  47. $this->assertEquals($expected, $is);
  48. $is = $this->Number->format('22.30', array('places' => 3));
  49. $expected = '22,300';
  50. $this->assertEquals($expected, $is);
  51. $is = $this->Number->format('abc', array('places' => 2));
  52. $expected = '---';
  53. $this->assertEquals($expected, $is);
  54. /*
  55. $is = $this->Number->format('12.2', array('places'=>'a'));
  56. $expected = '12,20';
  57. $this->assertEquals($expected, $is);
  58. */
  59. $is = $this->Number->format('22.3', array('places' => 2, 'before' => 'EUR '));
  60. $expected = 'EUR 22,30';
  61. $this->assertEquals($expected, $is);
  62. $is = $this->Number->format('22.3', array('places' => 2, 'after' => ' EUR'));
  63. $expected = '22,30 EUR';
  64. $this->assertEquals($expected, $is);
  65. $is = $this->Number->format('22.3', array('places' => 2, 'after' => 'x', 'before' => 'v'));
  66. $expected = 'v22,30x';
  67. $this->assertEquals($expected, $is);
  68. #TODO: more
  69. }
  70. public function tearDown() {
  71. parent::tearDown();
  72. unset($this->Number);
  73. }
  74. }