SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/tests/i18nTest.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. use Sprout\Helpers\I18n;
  15.  
  16. class i18nTest extends PHPUnit_Framework_TestCase
  17. {
  18.  
  19. public function dataNumber()
  20. {
  21. return array(
  22. array('AUS', 1234.123, 0, '1,234'),
  23. array('AUS', 1234.123, 1, '1,234.1'),
  24. array('AUS', 1234.123, 2, '1,234.12'),
  25. array('AUS', -1234.123, 1, '-1,234.1'),
  26.  
  27. // Other countries which format numbers the same as AUS
  28. array('GBR', 1234.123, 2, '1,234.12'),
  29. array('JPN', 1234.123, 2, '1,234.12'),
  30. array('USD', 1234.123, 2, '1,234.12'),
  31.  
  32. // Canada uses spaces instead of commas (in English)
  33. array('CAN', 1234.123, 2, '1 234.12'),
  34.  
  35. // Numbering in india is ... odd.
  36. array('IND', 2, 0, '2'),
  37. array('IND', 12, 0, '12'),
  38. array('IND', 212, 0, '212'),
  39. array('IND', 1212, 0, '1,212'),
  40. array('IND', 21212, 0, '21,212'),
  41. array('IND', 121212, 0, '1,21,212'),
  42. array('IND', 2121212, 0, '21,21,212'),
  43. array('IND', 12121212, 0, '1,21,21,212'),
  44. array('IND', 212121212, 0, '21,21,21,212'),
  45. array('IND', 121212.1, 1, '1,21,212.1'),
  46. array('IND', 2121212.1, 1, '21,21,212.1'),
  47. array('IND', 12121212.1, 1, '1,21,21,212.1'),
  48. array('IND', 212121212.1, 1, '21,21,21,212.1'),
  49. );
  50. }
  51.  
  52. public function dataMoney()
  53. {
  54. return array(
  55. array('AUS', 1234.123, '$1,234.12'),
  56. array('AUS', -1234.123, '-$1,234.12'),
  57.  
  58. array('JPN', 1234.123, '¥1,234'),
  59. array('JPN', -1234.123, '-¥1,234'),
  60.  
  61. array('IND', 1234.123, 'Rs.1,234'),
  62. array('IND', -1234.123, '-Rs.1,234'),
  63. array('IND', -121234.123, '-Rs.1,21,234'),
  64. );
  65. }
  66.  
  67.  
  68.  
  69. /**
  70.   * @dataProvider dataNumber
  71.   **/
  72. public function testNumber($country, $number, $precision, $expected)
  73. {
  74. I18n::setLocale($country);
  75. $got = I18n::number($number, $precision);
  76. $this->assertEquals($expected, $got);
  77. }
  78.  
  79. /**
  80.   * @dataProvider dataMoney
  81.   **/
  82. public function testMoney($country, $number, $expected)
  83. {
  84. I18n::setLocale($country);
  85. $got = I18n::money($number);
  86. $this->assertEquals($expected, $got);
  87. }
  88.  
  89.  
  90.  
  91. public function testDates()
  92. {
  93. $this->assertTrue(I18n::shortdate(strtotime('2012-01-01')) == '1/1/2012');
  94. $this->assertTrue(I18n::longdate(strtotime('2012-01-01')) == 'Sun 1st Jan 2012');
  95. $this->assertTrue(I18n::time(strtotime('10:00:00')) == '10:00am');
  96. }
  97.  
  98. }
  99.