You are here

public function DateRecurTest::testHelperNonRecurringWithEnd in Recurring Dates Field 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/DateRecurTest.php \Drupal\Tests\date_recur\Kernel\DateRecurTest::testHelperNonRecurringWithEnd()
  2. 3.0.x tests/src/Kernel/DateRecurTest.php \Drupal\Tests\date_recur\Kernel\DateRecurTest::testHelperNonRecurringWithEnd()
  3. 3.1.x tests/src/Kernel/DateRecurTest.php \Drupal\Tests\date_recur\Kernel\DateRecurTest::testHelperNonRecurringWithEnd()

Tests accessing occurrences with fields with end date or rule.

File

tests/src/Kernel/DateRecurTest.php, line 152

Class

DateRecurTest
Tests basic functionality of date_recur fields.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testHelperNonRecurringWithEnd() {
  $entity = DrEntityTest::create();
  $entity->dr = [
    'value' => '2014-06-15T23:00:00',
    'end_value' => '2014-06-16T07:00:00',
    'rrule' => '',
    'infinite' => '0',
    'timezone' => 'Australia/Sydney',
  ];

  // Ensure a non repeating field value generates a single occurrence.

  /** @var \Drupal\date_recur\DateRange[] $occurrences */
  $occurrences = iterator_to_array($entity->dr->occurrences);
  $this
    ->assertCount(1, $occurrences);
  $tz = new \DateTimeZone('Australia/Sydney');
  $startAssert = new \DateTime('9am 16 June 2014', $tz);
  $this
    ->assertEquals($startAssert, $occurrences[0]
    ->getStart());
  $endAssert = new \DateTime('5pm 16 June 2014', $tz);
  $this
    ->assertEquals($endAssert, $occurrences[0]
    ->getEnd());
}