function DateTest::testGetSampleDateFormats

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::testGetSampleDateFormats()
  2. 8.9.x core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::testGetSampleDateFormats()
  3. 10 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::testGetSampleDateFormats()

Tests the getSampleDateFormats method.

@covers \Drupal\Core\Datetime\DateFormatter::getSampleDateFormats

File

core/tests/Drupal/Tests/Core/Datetime/DateTest.php, line 172

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 testGetSampleDateFormats() : void {
    $timestamp = strtotime('2015-03-22 14:23:00');
    $expected = $this->dateFormatter
        ->getSampleDateFormats('en', $timestamp, 'Australia/Sydney');
    // Removed characters related to timezone 'e' and 'T', as test does not have
    // timezone set.
    // cspell:disable-next-line
    $date_characters = 'dDjlNSwzWFmMntLoYyaABgGhHisuIOPZcrU';
    $date_chars = str_split($date_characters);
    foreach ($date_chars as $val) {
        $this->assertEquals($expected[$val], date($val, $timestamp));
    }
}

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