You are here

public function OfficeHoursDatetimeUnitTest::testDateTimeIsEmpty in Office Hours 8

Tests using entity fields of the datetime field type.

File

tests/src/Unit/OfficeHoursDatetimeUnitTest.php, line 30

Class

OfficeHoursDatetimeUnitTest
Tests the new entity API for the office_hours field type.

Namespace

Drupal\Tests\office_hours\Unit

Code

public function testDateTimeIsEmpty() {
  $this::assertTrue(OfficeHoursDatetime::isEmpty(NULL), 'Test Datetime NULL is empty.');
  $this::assertNotTrue(OfficeHoursDatetime::isEmpty(-1), 'Test 24:00 is not empty.');
  $this::assertTrue(OfficeHoursDatetime::isEmpty(''), 'Test empty slot is empty.');
  $this::assertTrue(OfficeHoursDatetime::isEmpty([
    'time' => '',
  ]), "Test empty 'time' value is empty.");
  $this::assertNotTrue(OfficeHoursDatetime::isEmpty([
    'time' => 'a time',
  ]), "Test not-empty 'time' value is not empty.");
  $this::assertTrue(OfficeHoursDatetime::isEmpty([
    'day' => '2',
    'starthours' => '',
    'endhours' => '',
    'comment' => '',
  ]), "Test complete array - only 'day' is set.");
  $this::assertNotTrue(OfficeHoursDatetime::isEmpty([
    'day' => '2',
    'starthours' => '',
    'endhours' => '',
    'comment' => 'There is a comment, so not empty.',
  ]), "Test complete array - only 'day' and 'comment' is set.");
  $this::assertTrue(OfficeHoursDatetime::isEmpty([
    'day' => NULL,
    'starthours' => NULL,
    'endhours' => NULL,
    'comment' => NULL,
  ]), "Test complete array with 4 NULL (from devel_generate).");
}