Skip to content
Snippets Groups Projects
Commit b49c6d38 authored by dpi's avatar dpi
Browse files

Issue #3153976 by AndyF: Can't iterate DateRecurNonRecurringHelper

parent 116c83b9
No related branches found
No related tags found
No related merge requests found
...@@ -126,7 +126,7 @@ class DateRecurNonRecurringHelper implements DateRecurHelperInterface { ...@@ -126,7 +126,7 @@ class DateRecurNonRecurringHelper implements DateRecurHelperInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function valid(): bool { public function valid(): bool {
return TRUE; return !is_null(key($this->occurrences));
} }
/** /**
......
...@@ -94,6 +94,32 @@ class DateRecurNonRecurringHelperUnitTest extends UnitTestCase { ...@@ -94,6 +94,32 @@ class DateRecurNonRecurringHelperUnitTest extends UnitTestCase {
); );
} }
/**
* Test the helper works as an iterator.
*/
public function testIteration() {
$format = 'ga j F Y';
$start = '2am 14 April 2014';
$end = '4am 14 April 2014';
$helper = $this->createHelper(
new \DateTime($start),
new \DateTime($end)
);
$occurrences = [];
// Iterate the occurences.
foreach ($helper as $date_range) {
$occurrences[] = $date_range;
}
// There should be only one result.
/** @var \Drupal\date_recur\DateRange $occurrence */
$occurrence = reset($occurrences);
$this->assertCount(1, $occurrences);
$this->assertSame($occurrence->getStart()->format($format), $start);
$this->assertSame($occurrence->getEnd()->format($format), $end);
}
/** /**
* Creates a new helper. * Creates a new helper.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment