NumericHelperTest.php 2.0 KB

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