function DrupalDateTimeTest::testRfc2822DateFormat

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

Class

DrupalDateTimeTest
@coversDefaultClass \Drupal\Core\Datetime\DrupalDateTime @group Datetime

Namespace

Drupal\Tests\Core\Datetime

Code

public function testRfc2822DateFormat() : void {
    $language_manager = $this->createMock(LanguageManager::class);
    $language_manager->expects($this->any())
        ->method('getCurrentLanguage')
        ->willReturn(new Language([
        'id' => $this->randomMachineName(2),
    ]));
    $container = new ContainerBuilder();
    $container->set('language_manager', $language_manager);
    \Drupal::setContainer($container);
    $time = '2019-02-02T13:30';
    $timezone = new \DateTimeZone('Europe/Berlin');
    $langcodes = array_keys(LanguageManager::getStandardLanguageList());
    $langcodes[] = NULL;
    foreach ($langcodes as $langcode) {
        $datetime = new DrupalDateTime($time, $timezone, [
            'langcode' => $langcode,
        ]);
        // Check that RFC2822 format date is returned regardless of langcode.
        $this->assertEquals('Sat, 02 Feb 2019 13:30:00 +0100', $datetime->format('r'));
    }
}

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