]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/intl/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / intl / Symfony / Component / Intl / Tests / DateFormatter / IntlDateFormatterTest.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Intl\Tests\DateFormatter;
13
14 use Symfony\Component\Intl\DateFormatter\IntlDateFormatter;
15 use Symfony\Component\Intl\Globals\IntlGlobals;
16
17 class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
18 {
19 public function testConstructor()
20 {
21 $formatter = new IntlDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN, 'y-M-d');
22 $this->assertEquals('y-M-d', $formatter->getPattern());
23 }
24
25 /**
26 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
27 */
28 public function testConstructorWithUnsupportedLocale()
29 {
30 new IntlDateFormatter('pt_BR', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT);
31 }
32
33 public function testStaticCreate()
34 {
35 $formatter = IntlDateFormatter::create('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT);
36 $this->assertInstanceOf('\Symfony\Component\Intl\DateFormatter\IntlDateFormatter', $formatter);
37 }
38
39 public function testFormatWithUnsupportedTimestampArgument()
40 {
41 $formatter = $this->getDefaultDateFormatter();
42
43 $localtime = array(
44 'tm_sec' => 59,
45 'tm_min' => 3,
46 'tm_hour' => 15,
47 'tm_mday' => 15,
48 'tm_mon' => 3,
49 'tm_year' => 112,
50 'tm_wday' => 0,
51 'tm_yday' => 105,
52 'tm_isdst' => 0
53 );
54
55 try {
56 $formatter->format($localtime);
57 } catch (\Exception $e) {
58 $this->assertInstanceOf('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException', $e);
59
60 if (version_compare(PHP_VERSION, '5.3.4', '>=')) {
61 $this->assertStringEndsWith('Only integer unix timestamps and DateTime objects are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
62 } else {
63 $this->assertStringEndsWith('Only integer unix timestamps are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
64 }
65 }
66 }
67
68 /**
69 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
70 */
71 public function testFormatWithUnimplementedChars()
72 {
73 $pattern = 'Y';
74 $formatter = new IntlDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN, $pattern);
75 $formatter->format(0);
76 }
77
78 /**
79 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
80 */
81 public function testFormatWithNonIntegerTimestamp()
82 {
83 $formatter = $this->getDefaultDateFormatter();
84 $formatter->format(array());
85 }
86
87 public function testGetErrorCode()
88 {
89 $formatter = $this->getDefaultDateFormatter();
90 $this->assertEquals(IntlGlobals::getErrorCode(), $formatter->getErrorCode());
91 }
92
93 public function testGetErrorMessage()
94 {
95 $formatter = $this->getDefaultDateFormatter();
96 $this->assertEquals(IntlGlobals::getErrorMessage(), $formatter->getErrorMessage());
97 }
98
99 public function testIsLenient()
100 {
101 $formatter = $this->getDefaultDateFormatter();
102 $this->assertFalse($formatter->isLenient());
103 }
104
105 /**
106 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
107 */
108 public function testLocaltime()
109 {
110 $formatter = $this->getDefaultDateFormatter();
111 $formatter->localtime('Wednesday, December 31, 1969 4:00:00 PM PT');
112 }
113
114 /**
115 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentNotImplementedException
116 */
117 public function testParseWithNotNullPositionValue()
118 {
119 $position = 0;
120 $formatter = $this->getDefaultDateFormatter('y');
121 $this->assertSame(0, $formatter->parse('1970', $position));
122 }
123
124 /**
125 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
126 */
127 public function testSetCalendar()
128 {
129 $formatter = $this->getDefaultDateFormatter();
130 $formatter->setCalendar(IntlDateFormatter::GREGORIAN);
131 }
132
133 /**
134 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
135 */
136 public function testSetLenient()
137 {
138 $formatter = $this->getDefaultDateFormatter();
139 $formatter->setLenient(true);
140 }
141
142 /**
143 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
144 */
145 public function testFormatWithGmtTimeZoneAndMinutesOffset()
146 {
147 parent::testFormatWithGmtTimeZoneAndMinutesOffset();
148 }
149
150 /**
151 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
152 */
153 public function testFormatWithNonStandardTimezone()
154 {
155 parent::testFormatWithNonStandardTimezone();
156 }
157
158 public function parseStandaloneAmPmProvider()
159 {
160 return $this->notImplemented(parent::parseStandaloneAmPmProvider());
161 }
162
163 public function parseDayOfWeekProvider()
164 {
165 return $this->notImplemented(parent::parseDayOfWeekProvider());
166 }
167
168 public function parseDayOfYearProvider()
169 {
170 return $this->notImplemented(parent::parseDayOfYearProvider());
171 }
172
173 public function parseQuarterProvider()
174 {
175 return $this->notImplemented(parent::parseQuarterProvider());
176 }
177
178 protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
179 {
180 return new IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern);
181 }
182
183 protected function getIntlErrorMessage()
184 {
185 return IntlGlobals::getErrorMessage();
186 }
187
188 protected function getIntlErrorCode()
189 {
190 return IntlGlobals::getErrorCode();
191 }
192
193 protected function isIntlFailure($errorCode)
194 {
195 return IntlGlobals::isFailure($errorCode);
196 }
197
198 /**
199 * Just to document the differences between the stub and the intl
200 * implementations. The intl can parse any of the tested formats alone. The
201 * stub does not implement them as it would be needed to add more
202 * abstraction, passing more context to the transformers objects. Any of the
203 * formats are ignored alone or with date/time data (years, months, days,
204 * hours, minutes and seconds).
205 *
206 * Also in intl, format like 'ss E' for '10 2' (2nd day of year
207 * + 10 seconds) are added, then we have 86,400 seconds (24h * 60min * 60s)
208 * + 10 seconds
209 *
210 * @param array $dataSets
211 *
212 * @return array
213 */
214 private function notImplemented(array $dataSets)
215 {
216 return array_map(function ($row) {
217 return array($row[0], $row[1], 0);
218 }, $dataSets);
219 }
220 }