UtilsDeTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. require_once 'tests/UtilsTest.php';
  3. class UtilsDeTest extends UtilsTest
  4. {
  5. /**
  6. * Test date_format().
  7. */
  8. public function testDateFormat()
  9. {
  10. $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
  11. $this->assertRegExp('/1\. Januar 2017 (um )?10:11:12 GMT\+0?3(:00)?/', format_date($date, true, true));
  12. }
  13. /**
  14. * Test date_format() without time.
  15. */
  16. public function testDateFormatNoTime()
  17. {
  18. $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
  19. $this->assertRegExp('/1\. Januar 2017/', format_date($date, false,true));
  20. }
  21. /**
  22. * Test date_format() using builtin PHP function strftime.
  23. */
  24. public function testDateFormatDefault()
  25. {
  26. $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
  27. $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, true, false));
  28. }
  29. /**
  30. * Test date_format() using builtin PHP function strftime without time.
  31. */
  32. public function testDateFormatDefaultNoTime()
  33. {
  34. $date = DateTime::createFromFormat('Ymd_His', '20170201_101112');
  35. $this->assertEquals('01.02.2017', format_date($date, false, false));
  36. }
  37. /**
  38. * Test autoLocale with a simple value
  39. */
  40. public function testAutoLocaleValid()
  41. {
  42. $current = setlocale(LC_ALL, 0);
  43. $header = 'en-us';
  44. autoLocale($header);
  45. $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
  46. setlocale(LC_ALL, $current);
  47. }
  48. /**
  49. * Test autoLocale with an alternative locale value
  50. */
  51. public function testAutoLocaleValidAlternative()
  52. {
  53. $current = setlocale(LC_ALL, 0);
  54. $header = 'en_us.UTF8';
  55. autoLocale($header);
  56. $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
  57. setlocale(LC_ALL, $current);
  58. }
  59. /**
  60. * Test autoLocale with multiples value, the first one is valid
  61. */
  62. public function testAutoLocaleMultipleFirstValid()
  63. {
  64. $current = setlocale(LC_ALL, 0);
  65. $header = 'en-us,de-de';
  66. autoLocale($header);
  67. $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
  68. setlocale(LC_ALL, $current);
  69. }
  70. /**
  71. * Test autoLocale with multiples value, the second one is available
  72. */
  73. public function testAutoLocaleMultipleSecondAvailable()
  74. {
  75. $current = setlocale(LC_ALL, 0);
  76. $header = 'mag_IN,fr-fr';
  77. autoLocale($header);
  78. $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0));
  79. setlocale(LC_ALL, $current);
  80. }
  81. /**
  82. * Test autoLocale without value: defaults to en_US.
  83. */
  84. public function testAutoLocaleBlank()
  85. {
  86. $current = setlocale(LC_ALL, 0);
  87. autoLocale('');
  88. $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
  89. setlocale(LC_ALL, $current);
  90. }
  91. /**
  92. * Test autoLocale with an unavailable value: defaults to en_US.
  93. */
  94. public function testAutoLocaleUnavailable()
  95. {
  96. $current = setlocale(LC_ALL, 0);
  97. autoLocale('mag_IN');
  98. $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
  99. setlocale(LC_ALL, $current);
  100. }
  101. }