NumericHelperTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. App::import('Helper', 'Tools.Numeric');
  3. App::uses('MyCakeTestCase', 'Tools.Lib');
  4. App::uses('View', 'View');
  5. /**
  6. * Numeric Test Case
  7. *
  8. * @package cake.tests
  9. * @subpackage cake.tests.cases.libs.view.helpers
  10. */
  11. class NumericHelperTest extends MyCakeTestCase {
  12. /**
  13. * setUp method
  14. *
  15. * @access public
  16. * @return void
  17. */
  18. public function setUp() {
  19. $this->Numeric = new NumericHelper(new View(null));
  20. }
  21. /**
  22. * test cweek
  23. *
  24. * @access public
  25. * @return void
  26. * 2009-03-11 ms
  27. */
  28. public function testFormat() {
  29. $is = $this->Numeric->format('22');
  30. $expected = '22,00';
  31. $this->assertEquals($expected, $is);
  32. $is = $this->Numeric->format('22.30', 1);
  33. $expected = '22,3';
  34. $this->assertEquals($expected, $is);
  35. $is = $this->Numeric->format('22.30', -1);
  36. $expected = '20';
  37. $this->assertEquals($expected, $is);
  38. $is = $this->Numeric->format('22.30', -2);
  39. $expected = '0';
  40. $this->assertEquals($expected, $is);
  41. $is = $this->Numeric->format('22.30', 3);
  42. $expected = '22,300';
  43. $this->assertEquals($expected, $is);
  44. $is = $this->Numeric->format('abc', 2);
  45. $expected = '---';
  46. $this->assertEquals($expected, $is);
  47. $is = $this->Numeric->format('12.2', 'a');
  48. $expected = '12,20';
  49. $this->assertEquals($expected, $is);
  50. $is = $this->Numeric->format('22.3', 2, array('before'=>'EUR '));
  51. $expected = 'EUR 22,30';
  52. $this->assertEquals($expected, $is);
  53. $is = $this->Numeric->format('22.3', 2, array('after'=>' EUR'));
  54. $expected = '22,30 EUR';
  55. $this->assertEquals($expected, $is);
  56. $is = $this->Numeric->format('22.3', 2, array('after'=>'x','before'=>'v'));
  57. $expected = 'v22,30x';
  58. $this->assertEquals($expected, $is);
  59. #TODO: more
  60. }
  61. /**
  62. * tearDown method
  63. *
  64. * @access public
  65. * @return void
  66. */
  67. public function tearDown() {
  68. unset($this->Numeric);
  69. }
  70. }