function DateHelperTest::testDayOfWeekName

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php \Drupal\Tests\Core\Datetime\DateHelperTest::testDayOfWeekName()
  2. 11.x core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php \Drupal\Tests\Core\Datetime\DateHelperTest::testDayOfWeekName()

@covers ::dayOfWeekName

File

core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php, line 239

Class

DateHelperTest
@coversDefaultClass \Drupal\Core\Datetime\DateHelper @group Datetime

Namespace

Drupal\Tests\Core\Datetime

Code

public function testDayOfWeekName() {
    // Passing NULL, FALSE, or an empty string should default to now. Just
    // check these are NOT null to avoid copying the implementation here.
    $this->assertNotNull(DateHelper::dayOfWeekName());
    $this->assertNotNull(DateHelper::dayOfWeekName(FALSE));
    $this->assertNotNull(DateHelper::dayOfWeekName(''));
    // Pass nothing and expect to get NULL.
    $this->assertNull(DateHelper::dayOfWeekName(0));
    $this->assertNull(DateHelper::dayOfWeekName('0'));
    // December 31st 2022 is a Saturday.
    $value = '2022-12-31 00:00:00';
    $dateString = DateHelper::dayOfWeekName($value);
    $this->assertEquals('Sat', $dateString);
    // November 30th 2020 is a Monday.
    $value = '2020-11-30 00:00:00';
    $dateString = DateHelper::dayOfWeekName($value);
    $this->assertEquals('Mon', $dateString);
}

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