NumericHelperTest.php 1.9 KB

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