public function CivicrmStorageGetTest::testDatetimeTimezone in CiviCRM Entity 8.3
Tests datetime fields and timezone conversions.
CiviCRM stores times in the user's timezone. However Drupal assumes all times are in UTC. When loading a date time, CiviEntityStorage converts the time into UTC so that Drupal handles the timezone correctly.
@dataProvider datetimeTimezoneDataProvider
Parameters
array $original_datetimes:
array $expected_utc_datetime:
$timezone:
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- tests/
src/ Kernel/ CivicrmStorageGetTest.php, line 77
Class
- CivicrmStorageGetTest
- Tests the storage.
Namespace
Drupal\Tests\civicrm_entity\KernelCode
public function testDatetimeTimezone(array $original_datetimes, array $expected_utc_datetime, $timezone) {
date_default_timezone_set($timezone);
$civicrm_api_mock = $this
->prophesize(CiviCrmApiInterface::class);
$civicrm_api_mock
->get('event', [
'id' => 1,
'return' => array_keys($this
->sampleEventsGetFields()),
])
->willReturn([
$original_datetimes,
]);
$storage = $this->container
->get('entity_type.manager')
->getStorage('civicrm_event');
$entity = $storage
->load(1);
foreach ($expected_utc_datetime as $field_name => $field_data) {
$this
->assertEquals($field_data, $entity
->get($field_name)->date
->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT));
}
}