function DateTest::testRfc2822DateFormat

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::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/Tests/Core/Datetime/DateTest.php, line 437

Class

DateTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Datetime%21DateFormatter.php/class/DateFormatter/11.x" title="Provides a service to handle various date related functionality." class="local">\Drupal\Core\Datetime\DateFormatter</a> @group Datetime

Namespace

Drupal\Tests\Core\Datetime

Code

public function testRfc2822DateFormat() : void {
    $timestamp = 1549110600;
    $langcodes = array_keys(LanguageManager::getStandardLanguageList());
    $langcodes[] = NULL;
    foreach ($langcodes as $langcode) {
        $formatted_date = $this->dateFormatter
            ->format($timestamp, 'custom', 'r', 'Europe/Berlin', $langcode);
        // Check that RFC2822 format date is returned regardless of langcode.
        $this->assertSame('Sat, 02 Feb 2019 13:30:00 +0100', $formatted_date);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.