function DateHelperTest::testDayOfWeek
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php \Drupal\Tests\Core\Datetime\DateHelperTest::testDayOfWeek()
- 11.x core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php \Drupal\Tests\Core\Datetime\DateHelperTest::testDayOfWeek()
@covers ::dayOfWeek
File
-
core/
tests/ Drupal/ Tests/ Core/ Datetime/ DateHelperTest.php, line 216
Class
- DateHelperTest
- @coversDefaultClass \Drupal\Core\Datetime\DateHelper @group Datetime
Namespace
Drupal\Tests\Core\DatetimeCode
public function testDayOfWeek() : void {
// 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::dayOfWeek());
$this->assertNotNull(DateHelper::dayOfWeek(FALSE));
$this->assertNotNull(DateHelper::dayOfWeek(''));
// Pass nothing and expect to get NULL.
$this->assertNull(DateHelper::dayOfWeek(0));
$this->assertNull(DateHelper::dayOfWeek('0'));
// December 31st 2022 is a Saturday.
$value = '2022-12-31 00:00:00';
$dateString = DateHelper::dayOfWeek($value);
$this->assertEquals('6', $dateString);
// November 30th 2020 is a Monday.
$value = '2020-11-30 00:00:00';
$dateString = DateHelper::dayOfWeek($value);
$this->assertEquals('1', $dateString);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.