You are here

public function SmsFrameworkUserActiveHoursServiceTest::testGetRanges in SMS Framework 8

Same name and namespace in other branches
  1. 2.x modules/sms_user/tests/src/Kernel/SmsFrameworkUserActiveHoursServiceTest.php \Drupal\Tests\sms_user\Kernel\SmsFrameworkUserActiveHoursServiceTest::testGetRanges()
  2. 2.1.x modules/sms_user/tests/src/Kernel/SmsFrameworkUserActiveHoursServiceTest.php \Drupal\Tests\sms_user\Kernel\SmsFrameworkUserActiveHoursServiceTest::testGetRanges()

Tests getting date ranges.

File

modules/sms_user/tests/src/Kernel/SmsFrameworkUserActiveHoursServiceTest.php, line 196

Class

SmsFrameworkUserActiveHoursServiceTest
Tests active hours service.

Namespace

Drupal\Tests\sms_user\Kernel

Code

public function testGetRanges() {
  $this
    ->setActiveHours([
    [
      'start' => '2016-03-15 tuesday 9:00',
      'end' => '2016-03-15 tuesday 17:00',
    ],
    [
      'start' => '2016-03-16 wednesday 9:00',
      'end' => '2016-03-16 wednesday 17:00',
    ],
  ]);
  $ranges = $this->activeHoursService
    ->getRanges('America/New_York');

  // Need to test timezone is same as well, as data objects will compare
  // equality across timezones.
  $this
    ->assertEquals(new DrupalDateTime('2016-03-15 tuesday 9am America/New_York'), $ranges[0]
    ->getStartDate());
  $this
    ->assertEquals('America/New_York', $ranges[0]
    ->getStartDate()
    ->getTimezone()
    ->getName());
  $this
    ->assertEquals(new DrupalDateTime('2016-03-15 tuesday 5pm America/New_York'), $ranges[0]
    ->getEndDate());
  $this
    ->assertEquals('America/New_York', $ranges[0]
    ->getEndDate()
    ->getTimezone()
    ->getName());
  $this
    ->assertEquals(new DrupalDateTime('2016-03-16 wednesday 9am America/New_York'), $ranges[1]
    ->getStartDate());
  $this
    ->assertEquals('America/New_York', $ranges[1]
    ->getStartDate()
    ->getTimezone()
    ->getName());
  $this
    ->assertEquals(new DrupalDateTime('2016-03-16 wednesday 5pm America/New_York'), $ranges[1]
    ->getEndDate());
  $this
    ->assertEquals('America/New_York', $ranges[1]
    ->getEndDate()
    ->getTimezone()
    ->getName());
}