function DateFormatterTest::testRfc2822DateFormat
Same name in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Datetime/DateFormatterTest.php \Drupal\KernelTests\Core\Datetime\DateFormatterTest::testRfc2822DateFormat()
Tests that an RFC2822 formatted date always returns an English string.
@covers ::format
See also
http://www.faqs.org/rfcs/rfc2822.html
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Datetime/ DateFormatterTest.php, line 124
Class
- DateFormatterTest
- Tests date formatting.
Namespace
Drupal\KernelTests\Core\DatetimeCode
public function testRfc2822DateFormat() : void {
$days_of_week_abbr = [
'Sun',
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat',
];
foreach ($days_of_week_abbr as $day_of_week_abbr) {
$this->setSetting('locale_custom_strings_' . self::LANGCODE, [
'Abbreviated weekday' => [
$day_of_week_abbr => $this->randomString(3),
],
]);
}
/** @var \Drupal\Core\Datetime\DateFormatterInterface $formatter */
$formatter = $this->container
->get('date.formatter');
// Check that RFC2822 format date is returned regardless of langcode.
$this->assertEquals('Sat, 02 Feb 2019 13:30:00 +0100', $formatter->format(1549110600, 'custom', 'r', 'Europe/Berlin', static::LANGCODE));
$this->assertEquals('Sat, 02 Feb 2019 13:30:00 +0100', $formatter->format(1549110600, 'custom', 'r', 'Europe/Berlin'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.