NumericHelperTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. App::uses('NumericHelper', 'Tools.View/Helper');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. App::uses('View', 'View');
  5. /**
  6. * Numeric Test Case
  7. */
  8. class NumericHelperTest extends MyCakeTestCase {
  9. public function setUp() {
  10. parent::setUp();
  11. Configure::write('Localization', array(
  12. 'decimals' => ',',
  13. 'thousands' => '.'
  14. ));
  15. NumberLib::config();
  16. $this->Numeric = new NumericHelper(new View(null));
  17. }
  18. /**
  19. * test format
  20. *
  21. * TODO: move to NumberLib test?
  22. *
  23. * @return void
  24. * 2009-03-11 ms
  25. */
  26. public function testFormat() {
  27. $is = $this->Numeric->format('22');
  28. $expected = '22,00';
  29. $this->assertEquals($expected, $is);
  30. $is = $this->Numeric->format('22.30', array('places'=>1));
  31. $expected = '22,3';
  32. $this->assertEquals($expected, $is);
  33. $is = $this->Numeric->format('22.30', array('places'=>-1));
  34. $expected = '20';
  35. $this->assertEquals($expected, $is);
  36. $is = $this->Numeric->format('22.30', array('places'=>-2));
  37. $expected = '0';
  38. $this->assertEquals($expected, $is);
  39. $is = $this->Numeric->format('22.30', array('places'=>3));
  40. $expected = '22,300';
  41. $this->assertEquals($expected, $is);
  42. $is = $this->Numeric->format('abc', array('places'=>2));
  43. $expected = '---';
  44. $this->assertEquals($expected, $is);
  45. /*
  46. $is = $this->Numeric->format('12.2', array('places'=>'a'));
  47. $expected = '12,20';
  48. $this->assertEquals($expected, $is);
  49. */
  50. $is = $this->Numeric->format('22.3', array('places'=>2, 'before'=>'EUR '));
  51. $expected = 'EUR 22,30';
  52. $this->assertEquals($expected, $is);
  53. $is = $this->Numeric->format('22.3', array('places'=>2, 'after'=>' EUR'));
  54. $expected = '22,30 EUR';
  55. $this->assertEquals($expected, $is);
  56. $is = $this->Numeric->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->Numeric);
  64. }
  65. }