StubIntlDateFormatterTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Locale\Stub;
  11. use Symfony\Component\Locale\Locale;
  12. use Symfony\Component\Locale\Stub\StubIntlDateFormatter;
  13. class StubIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function formatProvider()
  16. {
  17. return array(
  18. array('y-M-d', 0, '1970-1-1'),
  19. /* escaping */
  20. array("'M", 0, 'M'),
  21. array("'y-'M-'d", 0, 'y-M-d'),
  22. array("'yy", 0, 'yy'),
  23. array("'''yy", 0, "'yy"),
  24. array("''y", 0, "'1970"),
  25. array("''yy", 0, "'70"),
  26. /* months */
  27. array('M', 0, '1'),
  28. array('MM', 0, '01'),
  29. array('MMM', 0, 'Jan'),
  30. array('MMMM', 0, 'January'),
  31. array('MMMMM', 0, 'J'),
  32. /* this is stupid */
  33. array('MMMMMM', 0, '00001'),
  34. /* years */
  35. array('y', 0, '1970'),
  36. array('yy', 0, '70'),
  37. array('yyy', 0, '1970'),
  38. array('yyyy', 0, '1970'),
  39. array('yyyyy', 0, '01970'),
  40. array('yyyyyy', 0, '001970'),
  41. /* day */
  42. array('d', 0, '1'),
  43. array('dd', 0, '01'),
  44. array('ddd', 0, '001'),
  45. );
  46. }
  47. /**
  48. * @expectedException InvalidArgumentException
  49. */
  50. public function testConstructorWithUnsupportedLocale()
  51. {
  52. $formatter = new StubIntlDateFormatter('pt_BR', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
  53. }
  54. public function testConstructor()
  55. {
  56. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC', StubIntlDateFormatter::GREGORIAN, 'Y-M-d');
  57. $this->assertEquals('Y-M-d', $formatter->getPattern());
  58. }
  59. /**
  60. * @dataProvider formatProvider
  61. */
  62. public function testFormat($pattern, $timestamp, $expected)
  63. {
  64. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC', StubIntlDateFormatter::GREGORIAN, $pattern);
  65. $this->assertEquals($expected, $formatter->format($timestamp), 'Check date format with stub implementation.');
  66. if (extension_loaded('intl')) {
  67. $formatter = new \IntlDateFormatter('en', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
  68. $this->assertEquals($expected, $formatter->format($timestamp), 'Check date format with intl extension.');
  69. }
  70. }
  71. /**
  72. * @expectedException RuntimeException
  73. */
  74. public function testGetCalendar()
  75. {
  76. $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
  77. $formatter->getCalendar();
  78. }
  79. }