NumericHelperTest.php 1.9 KB

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