public function DateRecurTest::testGetOccurrences in Recurring Dates Field 3.x
Same name and namespace in other branches
- 8.2 tests/src/Kernel/DateRecurTest.php \Drupal\Tests\date_recur\Kernel\DateRecurTest::testGetOccurrences()
- 3.0.x tests/src/Kernel/DateRecurTest.php \Drupal\Tests\date_recur\Kernel\DateRecurTest::testGetOccurrences()
- 3.1.x tests/src/Kernel/DateRecurTest.php \Drupal\Tests\date_recur\Kernel\DateRecurTest::testGetOccurrences()
Tests adding a field, setting values, reading occurrences.
File
- tests/
src/ Kernel/ DateRecurTest.php, line 84
Class
- DateRecurTest
- Tests basic functionality of date_recur fields.
Namespace
Drupal\Tests\date_recur\KernelCode
public function testGetOccurrences() {
$this
->installEntitySchema('entity_test');
$field_storage = FieldStorageConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'abc',
'type' => 'date_recur',
'settings' => [
'datetime_type' => DateRecurItem::DATETIME_TYPE_DATETIME,
],
]);
$field_storage
->save();
$field = [
'field_name' => 'abc',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
];
FieldConfig::create($field)
->save();
$entity = EntityTest::create();
$entity->abc = [
'value' => '2014-06-15T23:00:00',
'end_value' => '2014-06-16T07:00:00',
'rrule' => 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR',
'infinite' => '1',
'timezone' => 'Australia/Sydney',
];
// No need to save the entity.
$this
->assertTrue($entity
->isNew());
/** @var \Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem $item */
$item = $entity->abc[0];
$occurrences = $item
->getHelper()
->getOccurrences(NULL, NULL, 2);
$this
->assertEquals('Mon, 16 Jun 2014 09:00:00 +1000', $occurrences[0]
->getStart()
->format('r'));
$this
->assertEquals('Mon, 16 Jun 2014 17:00:00 +1000', $occurrences[0]
->getEnd()
->format('r'));
$this
->assertEquals('Tue, 17 Jun 2014 09:00:00 +1000', $occurrences[1]
->getStart()
->format('r'));
$this
->assertEquals('Tue, 17 Jun 2014 17:00:00 +1000', $occurrences[1]
->getEnd()
->format('r'));
}