NumberHelperTest.php 2.0 KB

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