You are here

public function DateRecurNonRecurringHelperUnitTest::testOccurrence in Recurring Dates Field 3.x

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

Test occurrence generation with range limiters.

@covers ::getOccurrences @covers ::generateOccurrences

File

tests/src/Unit/DateRecurNonRecurringHelperUnitTest.php, line 22

Class

DateRecurNonRecurringHelperUnitTest
Tests non-recurring implementation of helper.

Namespace

Drupal\Tests\date_recur\Unit

Code

public function testOccurrence() {
  $helper = $this
    ->createHelper(new \DateTime('2am 14 April 2014'), new \DateTime('4am 14 April 2014'));

  // Test out of range (before).
  $occurrences = $helper
    ->getOccurrences(new \DateTime('1am 14 April 2014'), new \DateTime('1:30am 14 April 2014'));
  $this
    ->assertCount(0, $occurrences);

  // Test out of range (after).
  $occurrences = $helper
    ->getOccurrences(new \DateTime('4:30am 14 April 2014'), new \DateTime('5am 14 April 2014'));
  $this
    ->assertCount(0, $occurrences);

  // Test in range (intersects occurrence start).
  $occurrences = $helper
    ->getOccurrences(new \DateTime('1am 14 April 2014'), new \DateTime('3am 14 April 2014'));
  $this
    ->assertCount(1, $occurrences);

  // Test in range (exact).
  $occurrences = $helper
    ->getOccurrences(new \DateTime('2am 14 April 2014'), new \DateTime('4am 14 April 2014'));
  $this
    ->assertCount(1, $occurrences);

  // Test in range (within).
  $occurrences = $helper
    ->getOccurrences(new \DateTime('2:30am 14 April 2014'), new \DateTime('3:30am 14 April 2014'));
  $this
    ->assertCount(1, $occurrences);

  // Test in range (intersects occurrence end).
  $occurrences = $helper
    ->getOccurrences(new \DateTime('3am 14 April 2014'), new \DateTime('5am 14 April 2014'));
  $this
    ->assertCount(1, $occurrences);

  // Test in range but zero limit.
  $occurrences = $helper
    ->getOccurrences(new \DateTime('1am 14 April 2014'), new \DateTime('3am 14 April 2014'), 0);
  $this
    ->assertCount(0, $occurrences);
}