NumericHelperTest.php 2.0 KB

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