class DateRecurNonRecurringHelperUnitTest in Recurring Dates Field 8.2
Same name and namespace in other branches
- 3.x tests/src/Unit/DateRecurNonRecurringHelperUnitTest.php \Drupal\Tests\date_recur\Unit\DateRecurNonRecurringHelperUnitTest
- 3.0.x tests/src/Unit/DateRecurNonRecurringHelperUnitTest.php \Drupal\Tests\date_recur\Unit\DateRecurNonRecurringHelperUnitTest
- 3.1.x tests/src/Unit/DateRecurNonRecurringHelperUnitTest.php \Drupal\Tests\date_recur\Unit\DateRecurNonRecurringHelperUnitTest
Tests non-recurring implementation of helper.
@coversDefaultClass \Drupal\date_recur\DateRecurNonRecurringHelper @group date_recur
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\date_recur\Unit\DateRecurNonRecurringHelperUnitTest
Expanded class hierarchy of DateRecurNonRecurringHelperUnitTest
File
- tests/
src/ Unit/ DateRecurNonRecurringHelperUnitTest.php, line 14
Namespace
Drupal\Tests\date_recur\UnitView source
class DateRecurNonRecurringHelperUnitTest extends UnitTestCase {
/**
* Test occurrence generation with range limiters.
*
* @covers ::getOccurrences
* @covers ::generateOccurrences
*/
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);
}
/**
* Tests invalid argument for limit.
*/
public function testInvalidLimit() {
$helper = $this
->createHelper(new \DateTime('2am 14 April 2014'), new \DateTime('4am 14 April 2014'));
$this
->setExpectedException(\InvalidArgumentException::class, 'Invalid count limit.');
$helper
->getOccurrences(new \DateTime('1am 14 April 2014'), new \DateTime('3am 14 April 2014'), -1);
}
/**
* Creates a new helper.
*
* @param \DateTimeInterface[]|null[] $args
* Uses same arguments as
* \Drupal\date_recur\DateRecurNonRecurringHelper::createInstance without
* the RRULE arg.
*
* @return \Drupal\date_recur\DateRecurHelperInterface
* A new date recur helper instance.
*
* @see \Drupal\date_recur\DateRecurHelperInterface::createInstance
*/
protected function createHelper(?\DateTimeInterface ...$args) {
return DateRecurNonRecurringHelper::createInstance('', ...$args);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DateRecurNonRecurringHelperUnitTest:: |
protected | function | Creates a new helper. | |
DateRecurNonRecurringHelperUnitTest:: |
public | function | Tests invalid argument for limit. | |
DateRecurNonRecurringHelperUnitTest:: |
public | function | Test occurrence generation with range limiters. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |