Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -1,8 +1,8 @@
name: 'Datetime Range'
type: module
description: 'Provides the ability to store end dates.'
package: Core (Experimental)
package: Field types
version: VERSION
core: 8.x
dependencies:
- datetime
- drupal:datetime

View file

@ -6,6 +6,8 @@
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\views\Views;
use Drupal\views\ViewEntityInterface;
/**
* Implements hook_help().
@ -26,3 +28,141 @@ function datetime_range_help($route_name, RouteMatchInterface $route_match) {
return $output;
}
}
/**
* Implements hook_view_presave().
*
* When a view is saved using the old string or standard plugin format for
* Datetime Range filters or sorts, they will automatically be updated to
* Datetime filters or sorts. Old plugins usage must to be considered
* deprecated and must be converted before 9.0.0, when this updating layer will
* be removed.
*
* @deprecated in Drupal 8.5.x and will be removed before 9.0.0.
*
* @see https://www.drupal.org/node/2857691
*/
function datetime_range_view_presave(ViewEntityInterface $view) {
$config_factory = \Drupal::configFactory();
$displays = $view->get('display');
$changed = FALSE;
foreach ($displays as $display_name => &$display) {
// Update datetime_range filters.
if (isset($display['display_options']['filters'])) {
foreach ($display['display_options']['filters'] as $field_name => &$filter) {
if ($filter['plugin_id'] === 'string') {
$table_data = Views::viewsData()->get($filter['table']);
if (!$table_data) {
continue;
}
// Get field config.
$filter_views_data = $table_data[$filter['field']]['filter'];
if (!isset($filter_views_data['entity_type']) || !isset($filter_views_data['field_name'])) {
continue;
}
$field_storage_name = 'field.storage.' . $filter_views_data['entity_type'] . '.' . $filter_views_data['field_name'];
$field_configuration = $config_factory->get($field_storage_name);
if ($field_configuration->get('type') === 'daterange') {
// Set entity_type if missing.
if (!isset($filter['entity_type'])) {
$filter['entity_type'] = $filter_views_data['entity_type'];
}
// Set datetime plugin_id.
$filter['plugin_id'] = 'datetime';
// Create datetime value array.
$datetime_value = [
'min' => '',
'max' => '',
'value' => $filter['value'],
'type' => 'date',
];
// Map string operator/value to numeric equivalent.
switch ($filter['operator']) {
case '=':
case 'empty':
case 'not empty':
$operator = $filter['operator'];
break;
case '!=':
case 'not':
$operator = '!=';
break;
case 'starts':
$operator = 'regular_expression';
$datetime_value['value'] = '^' . preg_quote($datetime_value['value']);
break;
case 'ends':
$operator = 'regular_expression';
$datetime_value['value'] = preg_quote($datetime_value['value']) . '$';
break;
default:
$operator = 'regular_expression';
// Add .* to prevent blank regexes.
if (empty($datetime_value['value'])) {
$datetime_value['value'] = '.*';
}
else {
$datetime_value['value'] = preg_quote($datetime_value['value']);
}
}
// Set value and operator.
$filter['value'] = $datetime_value;
$filter['operator'] = $operator;
$changed = TRUE;
@trigger_error('Use of string filters for datetime_range fields is deprecated. Use the datetime filters instead. See https://www.drupal.org/node/2857691', E_USER_DEPRECATED);
}
}
}
}
// Update datetime_range sort handlers.
if (isset($display['display_options']['sorts'])) {
foreach ($display['display_options']['sorts'] as $field_name => &$sort) {
if ($sort['plugin_id'] === 'standard') {
$table_data = Views::viewsData()->get($sort['table']);
if (!$table_data) {
continue;
}
// Get field config.
$sort_views_data = $table_data[$sort['field']]['sort'];
if (!isset($sort_views_data['entity_type']) || !isset($sort_views_data['field_name'])) {
continue;
}
$field_storage_name = 'field.storage.' . $sort_views_data['entity_type'] . '.' . $sort_views_data['field_name'];
$field_configuration = $config_factory->get($field_storage_name);
if ($field_configuration->get('type') === 'daterange') {
// Set entity_type if missing.
if (!isset($sort['entity_type'])) {
$sort['entity_type'] = $sort_views_data['entity_type'];
}
// Set datetime plugin_id.
$sort['plugin_id'] = 'datetime';
$changed = TRUE;
@trigger_error('Use of standard sort handlers for datetime_range fields is deprecated. Use the datetime sort handlers instead. See https://www.drupal.org/node/2857691', E_USER_DEPRECATED);
}
}
}
}
}
if ($changed) {
$view->set('display', $displays);
}
}

View file

@ -5,9 +5,88 @@
* Post-update functions for Datetime Range module.
*/
use Drupal\views\Views;
/**
* Clear caches to ensure schema changes are read.
*/
function datetime_range_post_update_translatable_separator() {
// Empty post-update hook to cause a cache rebuild.
}
/**
* Update existing views using datetime_range fields.
*/
function datetime_range_post_update_views_string_plugin_id() {
/* @var \Drupal\views\Entity\View[] $views */
$views = \Drupal::entityTypeManager()->getStorage('view')->loadMultiple();
$config_factory = \Drupal::configFactory();
$message = NULL;
$ids = [];
foreach ($views as $view) {
$displays = $view->get('display');
$needs_bc_layer_update = FALSE;
foreach ($displays as $display_name => $display) {
// Check if datetime_range filters need updates.
if (!$needs_bc_layer_update && isset($display['display_options']['filters'])) {
foreach ($display['display_options']['filters'] as $field_name => $filter) {
if ($filter['plugin_id'] == 'string') {
// Get field config.
$filter_views_data = Views::viewsData()->get($filter['table'])[$filter['field']]['filter'];
if (!isset($filter_views_data['entity_type']) || !isset($filter_views_data['field_name'])) {
continue;
}
$field_storage_name = 'field.storage.' . $filter_views_data['entity_type'] . '.' . $filter_views_data['field_name'];
$field_configuration = $config_factory->get($field_storage_name);
if ($field_configuration->get('type') == 'daterange') {
// Trigger the BC layer control.
$needs_bc_layer_update = TRUE;
continue 2;
}
}
}
}
// Check if datetime_range sort handlers need updates.
if (!$needs_bc_layer_update && isset($display['display_options']['sorts'])) {
foreach ($display['display_options']['sorts'] as $field_name => $sort) {
if ($sort['plugin_id'] == 'standard') {
// Get field config.
$sort_views_data = Views::viewsData()->get($sort['table'])[$sort['field']]['sort'];
if (!isset($sort_views_data['entity_type']) || !isset($sort_views_data['field_name'])) {
continue;
}
$field_storage_name = 'field.storage.' . $sort_views_data['entity_type'] . '.' . $sort_views_data['field_name'];
$field_configuration = $config_factory->get($field_storage_name);
if ($field_configuration->get('type') == 'daterange') {
// Trigger the BC layer control.
$needs_bc_layer_update = TRUE;
continue 2;
}
}
}
}
}
// If current view needs BC layer updates save it and the hook view_presave
// will do the rest.
if ($needs_bc_layer_update) {
$view->save();
$ids[] = $view->id();
}
}
if (!empty($ids)) {
$message = \Drupal::translation()->translate('Updated datetime_range filter/sort plugins for views: @ids', ['@ids' => implode(', ', array_unique($ids))]);
}
return $message;
}

View file

@ -0,0 +1,24 @@
<?php
/**
* @file
* Provides views data for the datetime_range module.
*/
use Drupal\field\FieldStorageConfigInterface;
/**
* Implements hook_field_views_data().
*/
function datetime_range_field_views_data(FieldStorageConfigInterface $field_storage) {
// Include datetime.views.inc file in order for helper function
// datetime_type_field_views_data_helper() to be available.
\Drupal::moduleHandler()->loadInclude('datetime', 'inc', 'datetime.views');
// Get datetime field data for value and end_value.
$data = datetime_type_field_views_data_helper($field_storage, [], 'value');
$data = datetime_type_field_views_data_helper($field_storage, $data, 'end_value');
return $data;
}

View file

@ -2,8 +2,7 @@
namespace Drupal\datetime_range;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Provides friendly methods for datetime range.
@ -11,68 +10,40 @@ use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
trait DateTimeRangeTrait {
/**
* Creates a render array from a date object.
*
* @param \Drupal\Core\Datetime\DrupalDateTime $date
* A date object.
*
* @return array
* A render array.
* {@inheritdoc}
*/
protected function buildDate(DrupalDateTime $date) {
if ($this->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) {
// A date without time will pick up the current time, use the default.
datetime_date_default_time($date);
}
$this->setTimeZone($date);
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$separator = $this->getSetting('separator');
$build = [
'#plain_text' => $this->formatDate($date),
'#cache' => [
'contexts' => [
'timezone',
],
],
];
foreach ($items as $delta => $item) {
if (!empty($item->start_date) && !empty($item->end_date)) {
/** @var \Drupal\Core\Datetime\DrupalDateTime $start_date */
$start_date = $item->start_date;
/** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */
$end_date = $item->end_date;
return $build;
}
if ($start_date->getTimestamp() !== $end_date->getTimestamp()) {
$elements[$delta] = [
'start_date' => $this->buildDateWithIsoAttribute($start_date),
'separator' => ['#plain_text' => ' ' . $separator . ' '],
'end_date' => $this->buildDateWithIsoAttribute($end_date),
];
}
else {
$elements[$delta] = $this->buildDateWithIsoAttribute($start_date);
/**
* Creates a render array from a date object with ISO date attribute.
*
* @param \Drupal\Core\Datetime\DrupalDateTime $date
* A date object.
*
* @return array
* A render array.
*/
protected function buildDateWithIsoAttribute(DrupalDateTime $date) {
if ($this->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) {
// A date without time will pick up the current time, use the default.
datetime_date_default_time($date);
if (!empty($item->_attributes)) {
$elements[$delta]['#attributes'] += $item->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and should not be rendered in the field template.
unset($item->_attributes);
}
}
}
}
// Create the ISO date in Universal Time.
$iso_date = $date->format("Y-m-d\TH:i:s") . 'Z';
$this->setTimeZone($date);
$build = [
'#theme' => 'time',
'#text' => $this->formatDate($date),
'#html' => FALSE,
'#attributes' => [
'datetime' => $iso_date,
],
'#cache' => [
'contexts' => [
'timezone',
],
],
];
return $build;
return $elements;
}
}

View file

@ -38,6 +38,9 @@ class DateRangeCustomFormatter extends DateTimeCustomFormatter {
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
// @todo Evaluate removing this method in
// https://www.drupal.org/node/2793143 to determine if the behavior and
// markup in the base class implementation can be used instead.
$elements = [];
$separator = $this->getSetting('separator');

View file

@ -2,7 +2,6 @@
namespace Drupal\datetime_range\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeDefaultFormatter;
use Drupal\datetime_range\DateTimeRangeTrait;
@ -35,42 +34,6 @@ class DateRangeDefaultFormatter extends DateTimeDefaultFormatter {
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$separator = $this->getSetting('separator');
foreach ($items as $delta => $item) {
if (!empty($item->start_date) && !empty($item->end_date)) {
/** @var \Drupal\Core\Datetime\DrupalDateTime $start_date */
$start_date = $item->start_date;
/** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */
$end_date = $item->end_date;
if ($start_date->getTimestamp() !== $end_date->getTimestamp()) {
$elements[$delta] = [
'start_date' => $this->buildDateWithIsoAttribute($start_date),
'separator' => ['#plain_text' => ' ' . $separator . ' '],
'end_date' => $this->buildDateWithIsoAttribute($end_date),
];
}
else {
$elements[$delta] = $this->buildDateWithIsoAttribute($start_date);
if (!empty($item->_attributes)) {
$elements[$delta]['#attributes'] += $item->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and should not be rendered in the field template.
unset($item->_attributes);
}
}
}
}
return $elements;
}
/**
* {@inheritdoc}
*/

View file

@ -57,6 +57,13 @@ class DateRangePlainFormatter extends DateTimePlainFormatter {
}
else {
$elements[$delta] = $this->buildDate($start_date);
if (!empty($item->_attributes)) {
$elements[$delta]['#attributes'] += $item->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and should not be rendered in the field template.
unset($item->_attributes);
}
}
}
}

View file

@ -8,6 +8,7 @@ use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\Form\FormStateInterface;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
/**
* Represents a configurable entity daterange field.
@ -105,18 +106,18 @@ class DateRangeFieldItemList extends DateTimeFieldItemList {
// only provide a default value for the first item, as do all fields.
// Otherwise, there is no way to clear out unwanted values on multiple
// value fields.
$storage_format = $definition->getSetting('datetime_type') == DateRangeItem::DATETIME_TYPE_DATE ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT;
$storage_format = $definition->getSetting('datetime_type') == DateRangeItem::DATETIME_TYPE_DATE ? DateTimeItemInterface::DATE_STORAGE_FORMAT : DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
$default_values = [[]];
if (!empty($default_value[0]['default_date_type'])) {
$start_date = new DrupalDateTime($default_value[0]['default_date'], DATETIME_STORAGE_TIMEZONE);
$start_date = new DrupalDateTime($default_value[0]['default_date'], DateTimeItemInterface::STORAGE_TIMEZONE);
$start_value = $start_date->format($storage_format);
$default_values[0]['value'] = $start_value;
$default_values[0]['start_date'] = $start_date;
}
if (!empty($default_value[0]['default_end_date_type'])) {
$end_date = new DrupalDateTime($default_value[0]['default_end_date'], DATETIME_STORAGE_TIMEZONE);
$end_date = new DrupalDateTime($default_value[0]['default_end_date'], DateTimeItemInterface::STORAGE_TIMEZONE);
$end_value = $end_date->format($storage_format);
$default_values[0]['end_value'] = $end_value;
$default_values[0]['end_date'] = $end_date;

View file

@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\datetime\DateTimeComputed;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
/**
* Plugin implementation of the 'daterange' field type.
@ -96,12 +97,12 @@ class DateRangeItem extends DateTimeItem {
$start = REQUEST_TIME - mt_rand(0, 86400 * 365) - 86400;
$end = $start + 86400;
if ($type == static::DATETIME_TYPE_DATETIME) {
$values['value'] = gmdate(DATETIME_DATETIME_STORAGE_FORMAT, $start);
$values['end_value'] = gmdate(DATETIME_DATETIME_STORAGE_FORMAT, $end);
$values['value'] = gmdate(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $start);
$values['end_value'] = gmdate(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $end);
}
else {
$values['value'] = gmdate(DATETIME_DATE_STORAGE_FORMAT, $start);
$values['end_value'] = gmdate(DATETIME_DATE_STORAGE_FORMAT, $end);
$values['value'] = gmdate(DateTimeItemInterface::DATE_STORAGE_FORMAT, $start);
$values['end_value'] = gmdate(DateTimeItemInterface::DATE_STORAGE_FORMAT, $end);
}
return $values;
}

View file

@ -5,7 +5,7 @@ namespace Drupal\datetime_range\Plugin\Field\FieldWidget;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\datetime\Plugin\Field\FieldWidget\DateTimeWidgetBase;
use Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem;
@ -58,10 +58,7 @@ class DateRangeWidgetBase extends DateTimeWidgetBase {
$start_date = $item['value'];
switch ($this->getFieldSetting('datetime_type')) {
case DateRangeItem::DATETIME_TYPE_DATE:
// If this is a date-only field, set it to the default time so the
// timezone conversion can be reversed.
datetime_date_default_time($start_date);
$format = DATETIME_DATE_STORAGE_FORMAT;
$format = DateTimeItemInterface::DATE_STORAGE_FORMAT;
break;
case DateRangeItem::DATETIME_TYPE_ALLDAY:
@ -71,15 +68,15 @@ class DateRangeWidgetBase extends DateTimeWidgetBase {
// we need to explicitly set the timezone.
$start_date->setTimeZone(timezone_open(drupal_get_user_timezone()));
$start_date->setTime(0, 0, 0);
$format = DATETIME_DATETIME_STORAGE_FORMAT;
$format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
break;
default:
$format = DATETIME_DATETIME_STORAGE_FORMAT;
$format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
break;
}
// Adjust the date for storage.
$start_date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));
$start_date->setTimezone(new \DateTimezone(DateTimeItemInterface::STORAGE_TIMEZONE));
$item['value'] = $start_date->format($format);
}
@ -88,10 +85,7 @@ class DateRangeWidgetBase extends DateTimeWidgetBase {
$end_date = $item['end_value'];
switch ($this->getFieldSetting('datetime_type')) {
case DateRangeItem::DATETIME_TYPE_DATE:
// If this is a date-only field, set it to the default time so the
// timezone conversion can be reversed.
datetime_date_default_time($end_date);
$format = DATETIME_DATE_STORAGE_FORMAT;
$format = DateTimeItemInterface::DATE_STORAGE_FORMAT;
break;
case DateRangeItem::DATETIME_TYPE_ALLDAY:
@ -101,15 +95,15 @@ class DateRangeWidgetBase extends DateTimeWidgetBase {
// we need to explicitly set the timezone.
$end_date->setTimeZone(timezone_open(drupal_get_user_timezone()));
$end_date->setTime(23, 59, 59);
$format = DATETIME_DATETIME_STORAGE_FORMAT;
$format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
break;
default:
$format = DATETIME_DATETIME_STORAGE_FORMAT;
$format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
break;
}
// Adjust the date for storage.
$end_date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));
$end_date->setTimezone(new \DateTimezone(DateTimeItemInterface::STORAGE_TIMEZONE));
$item['end_value'] = $end_date->format($format);
}
}
@ -142,30 +136,4 @@ class DateRangeWidgetBase extends DateTimeWidgetBase {
}
}
/**
* Creates a date object for use as a default value.
*
* This will take a default value, apply the proper timezone for display in
* a widget, and set the default time for date-only fields.
*
* @param \Drupal\Core\Datetime\DrupalDateTime $date
* The UTC default date.
* @param string $timezone
* The timezone to apply.
*
* @return \Drupal\Core\Datetime\DrupalDateTime
* A date object for use as a default value in a field widget.
*/
protected function createDefaultValue($date, $timezone) {
// The date was created and verified during field_load(), so it is safe to
// use without further inspection.
if ($this->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) {
// A date without time will pick up the current time, use the default
// time.
datetime_date_default_time($date);
}
$date->setTimezone(new \DateTimeZone($timezone));
return $date;
}
}

View file

@ -0,0 +1,332 @@
<?php
// @codingStandardsIgnoreFile
/**
* @file
* Contains database additions to drupal-8.bare.standard.php.gz for testing the
* upgrade path of https://www.drupal.org/node/2786577.
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
// Configuration for an datetime_range field storage.
$field_storage_datetime_range = Yaml::decode(file_get_contents(__DIR__ . '/field.storage.node.field_range.yml'));
// Configuration for a datetime_range field on 'page' node bundle.
$field_datetime_range = Yaml::decode(file_get_contents(__DIR__ . '/field.field.node.page.field_range.yml'));
// Configuration for a View using datetime_range plugins.
$views_datetime_range = Yaml::decode(file_get_contents(__DIR__ . '/views.view.test_datetime_range_filter_values.yml'));
// Update core.entity_form_display.node.page.default
$data = $connection->select('config')
->fields('config', ['data'])
->condition('collection', '')
->condition('name', 'core.entity_form_display.node.page.default')
->execute()
->fetchField();
$data = unserialize($data);
$data['dependencies']['config'][] = 'field.field.' . $field_datetime_range['id'];
$data['dependencies']['module'][] = 'datetime_range';
$data['content'][$field_datetime_range['field_name']] = array(
"weight"=> 27,
"settings" => array(),
"third_party_settings" => array(),
"type" => "daterange_default",
"region" => "content"
);
$connection->update('config')
->fields([
'data' => serialize($data),
])
->condition('collection', '')
->condition('name', 'core.entity_form_display.node.page.default')
->execute();
// Update core.entity_view_display.node.page.default
$data = $connection->select('config')
->fields('config', ['data'])
->condition('collection', '')
->condition('name', 'core.entity_view_display.node.page.default')
->execute()
->fetchField();
$data = unserialize($data);
$data['dependencies']['config'][] = 'field.field.' . $field_datetime_range['id'];
$data['dependencies']['module'][] = 'datetime_range';
$data['content'][$field_datetime_range['field_name']] = array(
"weight"=> 102,
"label"=> "above",
"settings" => array("separator"=> "-", "format_type" => "medium", "timezone_override" => ""),
"third_party_settings" => array(),
"type" => "daterange_default",
"region" => "content"
);
$connection->update('config')
->fields([
'data' => serialize($data),
])
->condition('collection', '')
->condition('name', 'core.entity_view_display.node.page.default')
->execute();
$connection->insert('config')
->fields(array(
'collection',
'name',
'data',
))
->values(array(
'collection' => '',
'name' => 'field.field.' . $field_datetime_range['id'],
'data' => serialize($field_datetime_range),
))
->values(array(
'collection' => '',
'name' => 'field.storage.' . $field_storage_datetime_range['id'],
'data' => serialize($field_storage_datetime_range),
))
->values(array(
'collection' => '',
'name' => 'views.view.' . $views_datetime_range['id'],
'data' => serialize($views_datetime_range),
))
->execute();
// Update core.extension.
$extensions = $connection->select('config')
->fields('config', ['data'])
->condition('collection', '')
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$extensions['module']['datetime_range'] = 0;
$connection->update('config')
->fields([
'data' => serialize($extensions),
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute();
$connection->insert('key_value')
->fields(array(
'collection',
'name',
'value',
))
->values(array(
'collection' => 'config.entity.key_store.field_config',
'name' => 'uuid:87dc4221-8d56-4112-8a7f-7a855ac35d08',
'value' => 'a:1:{i:0;s:33:"field.field.' . $field_datetime_range['id'] . '";}',
))
->values(array(
'collection' => 'config.entity.key_store.field_storage_config',
'name' => 'uuid:2190ad8c-39dd-4eb1-b189-1bfc0c244a40',
'value' => 'a:1:{i:0;s:30:"field.storage.' . $field_storage_datetime_range['id'] . '";}',
))
->values(array(
'collection' => 'config.entity.key_store.view',
'name' => 'uuid:d20760b6-7cc4-4844-ae04-96da7225a46f',
'value' => 'a:1:{i:0;s:44:"views.view.' . $views_datetime_range['id'] . '";}',
))
->values(array(
'collection' => 'entity.storage_schema.sql',
'name' => 'node.field_schema_data.field_range',
'value' => 'a:2:{s:17:"node__field_range";a:4:{s:11:"description";s:40:"Data storage for node field field_range.";s:6:"fields";a:8:{s:6:"bundle";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:128;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:88:"The field instance bundle to which this row belongs, used when deleting a field instance";}s:7:"deleted";a:5:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:1;s:7:"default";i:0;s:11:"description";s:60:"A boolean indicating whether this data item has been deleted";}s:9:"entity_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:38:"The entity id this data is attached to";}s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:47:"The entity revision id this data is attached to";}s:8:"langcode";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:32;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:37:"The language code for this data item.";}s:5:"delta";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:67:"The sequence number for this data item, used for multi-value fields";}s:17:"field_range_value";a:4:{s:11:"description";s:21:"The start date value.";s:4:"type";s:7:"varchar";s:6:"length";i:20;s:8:"not null";b:1;}s:21:"field_range_end_value";a:4:{s:11:"description";s:19:"The end date value.";s:4:"type";s:7:"varchar";s:6:"length";i:20;s:8:"not null";b:1;}}s:11:"primary key";a:4:{i:0;s:9:"entity_id";i:1;s:7:"deleted";i:2;s:5:"delta";i:3;s:8:"langcode";}s:7:"indexes";a:4:{s:6:"bundle";a:1:{i:0;s:6:"bundle";}s:11:"revision_id";a:1:{i:0;s:11:"revision_id";}s:17:"field_range_value";a:1:{i:0;s:17:"field_range_value";}s:21:"field_range_end_value";a:1:{i:0;s:21:"field_range_end_value";}}}s:26:"node_revision__field_range";a:4:{s:11:"description";s:52:"Revision archive storage for node field field_range.";s:6:"fields";a:8:{s:6:"bundle";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:128;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:88:"The field instance bundle to which this row belongs, used when deleting a field instance";}s:7:"deleted";a:5:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:1;s:7:"default";i:0;s:11:"description";s:60:"A boolean indicating whether this data item has been deleted";}s:9:"entity_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:38:"The entity id this data is attached to";}s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:47:"The entity revision id this data is attached to";}s:8:"langcode";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:32;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:37:"The language code for this data item.";}s:5:"delta";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:67:"The sequence number for this data item, used for multi-value fields";}s:17:"field_range_value";a:4:{s:11:"description";s:21:"The start date value.";s:4:"type";s:7:"varchar";s:6:"length";i:20;s:8:"not null";b:1;}s:21:"field_range_end_value";a:4:{s:11:"description";s:19:"The end date value.";s:4:"type";s:7:"varchar";s:6:"length";i:20;s:8:"not null";b:1;}}s:11:"primary key";a:5:{i:0;s:9:"entity_id";i:1;s:11:"revision_id";i:2;s:7:"deleted";i:3;s:5:"delta";i:4;s:8:"langcode";}s:7:"indexes";a:4:{s:6:"bundle";a:1:{i:0;s:6:"bundle";}s:11:"revision_id";a:1:{i:0;s:11:"revision_id";}s:17:"field_range_value";a:1:{i:0;s:17:"field_range_value";}s:21:"field_range_end_value";a:1:{i:0;s:21:"field_range_end_value";}}}}',
))
->values(array(
'collection' => 'system.schema',
'name' => 'datetime_range',
'value' => 'i:8000;',
))
->execute();
// Update entity.definitions.bundle_field_map
$value = $connection->select('key_value')
->fields('key_value', ['value'])
->condition('collection', 'entity.definitions.bundle_field_map')
->condition('name', 'node')
->execute()
->fetchField();
$value = unserialize($value);
$value["field_range"] = array("type" => "daterange", "bundles" => array("page" => "page"));
$connection->update('key_value')
->fields([
'value' => serialize($value),
])
->condition('collection', 'entity.definitions.bundle_field_map')
->condition('name', 'node')
->execute();
// Update system.module.files
$files = $connection->select('key_value')
->fields('key_value', ['value'])
->condition('collection', 'state')
->condition('name', 'system.module.files')
->execute()
->fetchField();
$files = unserialize($files);
$files["datetime_range"] = "core/modules/datetime_range/datetime_range.info.yml";
$connection->update('key_value')
->fields([
'value' => serialize($files),
])
->condition('collection', 'state')
->condition('name', 'system.module.files')
->execute();
$connection->schema()->createTable('node__field_range', array(
'fields' => array(
'bundle' => array(
'type' => 'varchar_ascii',
'not null' => TRUE,
'length' => '128',
'default' => '',
),
'deleted' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'tiny',
'default' => '0',
),
'entity_id' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'unsigned' => TRUE,
),
'revision_id' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'unsigned' => TRUE,
),
'langcode' => array(
'type' => 'varchar_ascii',
'not null' => TRUE,
'length' => '32',
'default' => '',
),
'delta' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'unsigned' => TRUE,
),
'field_range_value' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '20',
),
'field_range_end_value' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '20',
),
),
'primary key' => array(
'entity_id',
'deleted',
'delta',
'langcode',
),
'indexes' => array(
'bundle' => array(
'bundle',
),
'revision_id' => array(
'revision_id',
),
'field_range_value' => array(
'field_range_value',
),
'field_range_end_value' => array(
'field_range_end_value',
),
),
'mysql_character_set' => 'utf8mb4',
));
$connection->schema()->createTable('node_revision__field_range', array(
'fields' => array(
'bundle' => array(
'type' => 'varchar_ascii',
'not null' => TRUE,
'length' => '128',
'default' => '',
),
'deleted' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'tiny',
'default' => '0',
),
'entity_id' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'unsigned' => TRUE,
),
'revision_id' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'unsigned' => TRUE,
),
'langcode' => array(
'type' => 'varchar_ascii',
'not null' => TRUE,
'length' => '32',
'default' => '',
),
'delta' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'unsigned' => TRUE,
),
'field_range_value' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '20',
),
'field_range_end_value' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '20',
),
),
'primary key' => array(
'entity_id',
'revision_id',
'deleted',
'delta',
'langcode',
),
'indexes' => array(
'bundle' => array(
'bundle',
),
'revision_id' => array(
'revision_id',
),
'field_range_value' => array(
'field_range_value',
),
'field_range_end_value' => array(
'field_range_end_value',
),
),
'mysql_character_set' => 'utf8mb4',
));

View file

@ -0,0 +1,21 @@
uuid: 87dc4221-8d56-4112-8a7f-7a855ac35d08
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_range
- node.type.page
module:
- datetime_range
id: node.page.field_range
field_name: field_range
entity_type: node
bundle: page
label: range
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: daterange

View file

@ -0,0 +1,20 @@
uuid: 2190ad8c-39dd-4eb1-b189-1bfc0c244a40
langcode: en
status: true
dependencies:
module:
- datetime_range
- node
id: node.field_range
field_name: field_range
entity_type: node
type: daterange
settings:
datetime_type: datetime
module: datetime_range
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

View file

@ -0,0 +1,231 @@
uuid: d20760b6-7cc4-4844-ae04-96da7225a46f
langcode: en
status: true
dependencies:
module:
- node
- user
id: test_datetime_range_filter_values
label: test_datetime_range_filter_values
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: mini
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous:
next:
style:
type: default
options:
grouping: { }
row_class: ''
default_row_class: true
uses_fields: false
row:
type: fields
options:
inline: { }
separator: ''
hide_empty: false
default_field_elements: true
fields:
title:
id: title
table: node_field_data
field: title
entity_type: node
entity_field: title
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
settings:
link_to_entity: true
plugin_id: field
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
click_sort_column: value
type: string
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
filters:
field_range_value:
id: field_range_value
table: node__field_range
field: field_range_value
relationship: none
group_type: group
admin_label: ''
operator: '='
value: '2017'
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
field_range_end_value:
id: field_range_end_value
table: node__field_range
field: field_range_end_value
relationship: none
group_type: group
admin_label: ''
operator: contains
value: ''
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
sorts:
field_range_value:
id: field_range_value
table: node__field_range
field: field_range_value
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
plugin_id: standard
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
filter_groups:
operator: AND
groups: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
- user.permissions
tags: { }

View file

@ -0,0 +1,8 @@
name: 'Datetime range test'
type: module
description: 'Provides a testing module for datetime_range.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:taxonomy

View file

@ -0,0 +1,17 @@
<?php
/**
* @file
* Contains datetime_range_test.module
*/
/**
* Implements hook_entity_type_alter().
*/
function datetime_range_test_entity_type_alter(array &$entity_types) {
// Inhibit views data for the 'taxonomy_term' entity type in order to cover
// the case when an entity type provides no views data.
// @see https://www.drupal.org/project/drupal/issues/2995578
// @see \Drupal\Tests\datetime_range\Kernel\Views\EntityTypeWithoutViewsDataTest
$entity_types['taxonomy_term']->setHandlerClass('views_data', NULL);
}

View file

@ -3,9 +3,9 @@
namespace Drupal\Tests\datetime_range\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\Tests\datetime\Functional\DateTestBase;
use Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem;
use Drupal\entity_test\Entity\EntityTest;
@ -46,12 +46,14 @@ class DateRangeFieldTest extends DateTestBase {
*/
public function testDateRangeField() {
$field_name = $this->fieldStorage->getName();
$field_label = $this->field->label();
// Loop through defined timezones to test that date-only fields work at the
// extremes.
foreach (static::$timezones as $timezone) {
$this->setSiteTimezone($timezone);
$this->assertEquals($timezone, $this->config('system.date')->get('timezone.default'), 'Time zone set to ' . $timezone);
// Ensure field is set to a date-only field.
$this->fieldStorage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_DATE);
@ -64,7 +66,7 @@ class DateRangeFieldTest extends DateTestBase {
$this->assertFieldByXPath('//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class, "js-form-required")]', TRUE, 'Required markup found');
$this->assertNoFieldByName("{$field_name}[0][value][time]", '', 'Start time element not found.');
$this->assertNoFieldByName("{$field_name}[0][end_value][time]", '', 'End time element not found.');
$this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, 'Fieldset and label found');
$this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
$this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
$this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
@ -108,8 +110,8 @@ class DateRangeFieldTest extends DateTestBase {
// Formats that display a time component for date-only fields will display
// the default time, so that is applied before calculating the expected
// value.
datetime_date_default_time($start_date);
datetime_date_default_time($end_date);
$this->massageTestDate($start_date);
$this->massageTestDate($end_date);
// Reset display options since these get changed below.
$this->displayOptions = [
@ -126,22 +128,24 @@ class DateRangeFieldTest extends DateTestBase {
->setComponent($field_name, $this->displayOptions)
->save();
$start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long', '', DATETIME_STORAGE_TIMEZONE);
$start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE);
$start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long', '', DateTimeItemInterface::STORAGE_TIMEZONE);
$start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DateTimeItemInterface::STORAGE_TIMEZONE);
$start_expected_markup = '<time datetime="' . $start_expected_iso . '" class="datetime">' . $start_expected . '</time>';
$end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long', '', DATETIME_STORAGE_TIMEZONE);
$end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE);
$end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long', '', DateTimeItemInterface::STORAGE_TIMEZONE);
$end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DateTimeItemInterface::STORAGE_TIMEZONE);
$end_expected_markup = '<time datetime="' . $end_expected_iso . '" class="datetime">' . $end_expected . '</time>';
$output = $this->renderTestEntity($id);
$this->assertContains($start_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [
$this->assertContains($start_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
'%value' => 'long',
'%expected' => $start_expected,
'%expected_iso' => $start_expected_iso,
'%timezone' => $timezone,
]));
$this->assertContains($end_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [
$this->assertContains($end_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
'%value' => 'long',
'%expected' => $end_expected,
'%expected_iso' => $end_expected_iso,
'%timezone' => $timezone,
]));
$this->assertContains(' THESEPARATOR ', $output, 'Found proper separator');
@ -156,9 +160,12 @@ class DateRangeFieldTest extends DateTestBase {
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
->setComponent($field_name, $this->displayOptions)
->save();
$expected = $start_date->format(DATETIME_DATE_STORAGE_FORMAT) . ' - ' . $end_date->format(DATETIME_DATE_STORAGE_FORMAT);
$expected = $start_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT) . ' - ' . $end_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected in %timezone.', [
'%expected' => $expected,
'%timezone' => $timezone,
]));
// Verify that the custom formatter works.
$this->displayOptions['type'] = 'daterange_custom';
@ -168,7 +175,23 @@ class DateRangeFieldTest extends DateTestBase {
->save();
$expected = $start_date->format($this->displayOptions['settings']['date_format']) . ' - ' . $end_date->format($this->displayOptions['settings']['date_format']);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected]));
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected in %timezone.', [
'%expected' => $expected,
'%timezone' => $timezone,
]));
// Test that allowed markup in custom format is preserved and XSS is
// removed.
$this->displayOptions['settings']['date_format'] = '\\<\\s\\t\\r\\o\\n\\g\\>m/d/Y\\<\\/\\s\\t\\r\\o\\n\\g\\>\\<\\s\\c\\r\\i\\p\\t\\>\\a\\l\\e\\r\\t\\(\\S\\t\\r\\i\\n\\g\\.\\f\\r\\o\\m\\C\\h\\a\\r\\C\\o\\d\\e\\(\\8\\8\\,\\8\\3\\,\\8\\3\\)\\)\\<\\/\\s\\c\\r\\i\\p\\t\\>';
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
->setComponent($field_name, $this->displayOptions)
->save();
$expected = '<strong>' . $start_date->format('m/d/Y') . '</strong>alert(String.fromCharCode(88,83,83)) - <strong>' . $end_date->format('m/d/Y') . '</strong>alert(String.fromCharCode(88,83,83))';
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected in %timezone.', [
'%expected' => $expected,
'%timezone' => $timezone,
]));
// Test formatters when start date and end date are the same
$this->drupalGet('entity_test/add');
@ -188,7 +211,7 @@ class DateRangeFieldTest extends DateTestBase {
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
datetime_date_default_time($start_date);
$this->massageTestDate($start_date);
$this->displayOptions = [
'type' => 'daterange_default',
@ -203,16 +226,17 @@ class DateRangeFieldTest extends DateTestBase {
->setComponent($field_name, $this->displayOptions)
->save();
$start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long', '', DATETIME_STORAGE_TIMEZONE);
$start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE);
$start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long', '', DateTimeItemInterface::STORAGE_TIMEZONE);
$start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DateTimeItemInterface::STORAGE_TIMEZONE);
$start_expected_markup = '<time datetime="' . $start_expected_iso . '" class="datetime">' . $start_expected . '</time>';
$output = $this->renderTestEntity($id);
$this->assertContains($start_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [
$this->assertContains($start_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
'%value' => 'long',
'%expected' => $start_expected,
'%expected_iso' => $start_expected_iso,
'%timezone' => $timezone,
]));
$this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page');
$this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page in ' . $timezone);
// Verify that hook_entity_prepare_view can add attributes.
// @see entity_test_entity_prepare_view()
@ -224,9 +248,12 @@ class DateRangeFieldTest extends DateTestBase {
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
->setComponent($field_name, $this->displayOptions)
->save();
$expected = $start_date->format(DATETIME_DATE_STORAGE_FORMAT);
$expected = $start_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected in %timezone.', [
'%expected' => $expected,
'%timezone' => $timezone,
]));
$this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page');
$this->displayOptions['type'] = 'daterange_custom';
@ -236,7 +263,10 @@ class DateRangeFieldTest extends DateTestBase {
->save();
$expected = $start_date->format($this->displayOptions['settings']['date_format']);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected]));
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected in %timezone.', [
'%expected' => $expected,
'%timezone' => $timezone,
]));
$this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page');
}
}
@ -246,6 +276,7 @@ class DateRangeFieldTest extends DateTestBase {
*/
public function testDatetimeRangeField() {
$field_name = $this->fieldStorage->getName();
$field_label = $this->field->label();
// Ensure the field to a datetime field.
$this->fieldStorage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_DATETIME);
@ -257,7 +288,7 @@ class DateRangeFieldTest extends DateTestBase {
$this->assertFieldByName("{$field_name}[0][value][time]", '', 'Start time element found.');
$this->assertFieldByName("{$field_name}[0][end_value][date]", '', 'End date element found.');
$this->assertFieldByName("{$field_name}[0][end_value][time]", '', 'End time element found.');
$this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, 'Fieldset and label found');
$this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
$this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
$this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
@ -321,7 +352,7 @@ class DateRangeFieldTest extends DateTestBase {
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
->setComponent($field_name, $this->displayOptions)
->save();
$expected = $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT) . ' - ' . $end_date->format(DATETIME_DATETIME_STORAGE_FORMAT);
$expected = $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT) . ' - ' . $end_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
@ -397,7 +428,7 @@ class DateRangeFieldTest extends DateTestBase {
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
->setComponent($field_name, $this->displayOptions)
->save();
$expected = $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT);
$expected = $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
$this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page');
@ -418,6 +449,7 @@ class DateRangeFieldTest extends DateTestBase {
*/
public function testAlldayRangeField() {
$field_name = $this->fieldStorage->getName();
$field_label = $this->field->label();
// Ensure field is set to a all-day field.
$this->fieldStorage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_ALLDAY);
@ -430,7 +462,7 @@ class DateRangeFieldTest extends DateTestBase {
$this->assertFieldByXPath('//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class, "js-form-required")]', TRUE, 'Required markup found');
$this->assertNoFieldByName("{$field_name}[0][value][time]", '', 'Start time element not found.');
$this->assertNoFieldByName("{$field_name}[0][end_value][time]", '', 'End time element not found.');
$this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, 'Fieldset and label found');
$this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
$this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
$this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
@ -488,7 +520,7 @@ class DateRangeFieldTest extends DateTestBase {
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
->setComponent($field_name, $this->displayOptions)
->save();
$expected = $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT) . ' - ' . $end_date->format(DATETIME_DATETIME_STORAGE_FORMAT);
$expected = $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT) . ' - ' . $end_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
@ -566,7 +598,7 @@ class DateRangeFieldTest extends DateTestBase {
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
->setComponent($field_name, $this->displayOptions)
->save();
$expected = $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT) . ' THESEPARATOR ' . $end_date->format(DATETIME_DATETIME_STORAGE_FORMAT);
$expected = $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT) . ' THESEPARATOR ' . $end_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
$this->assertContains(' THESEPARATOR ', $output, 'Found proper separator');
@ -588,6 +620,7 @@ class DateRangeFieldTest extends DateTestBase {
*/
public function testDatelistWidget() {
$field_name = $this->fieldStorage->getName();
$field_label = $this->field->label();
// Ensure field is set to a date only field.
$this->fieldStorage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_DATE);
@ -606,7 +639,7 @@ class DateRangeFieldTest extends DateTestBase {
// Display creation form.
$this->drupalGet('entity_test/add');
$this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, 'Fieldset and label found');
$this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
$this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
$this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
@ -944,7 +977,7 @@ class DateRangeFieldTest extends DateTestBase {
$this->drupalCreateContentType(['type' => 'date_content']);
// Create a field storage with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
$field_name = mb_strtolower($this->randomMachineName());
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
@ -987,9 +1020,9 @@ class DateRangeFieldTest extends DateTestBase {
// Create a new node to check that datetime field default value is today.
$new_node = Node::create(['type' => 'date_content']);
$expected_date = new DrupalDateTime('now', DATETIME_STORAGE_TIMEZONE);
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->end_value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
$expected_date = new DrupalDateTime('now', DateTimeItemInterface::STORAGE_TIMEZONE);
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->value, $expected_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT));
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->end_value, $expected_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT));
// Set an invalid relative default_value to test validation.
$field_edit = [
@ -1040,10 +1073,10 @@ class DateRangeFieldTest extends DateTestBase {
// Create a new node to check that datetime field default value is +90 days.
$new_node = Node::create(['type' => 'date_content']);
$expected_start_date = new DrupalDateTime('+45 days', DATETIME_STORAGE_TIMEZONE);
$expected_end_date = new DrupalDateTime('+90 days', DATETIME_STORAGE_TIMEZONE);
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->value, $expected_start_date->format(DATETIME_DATE_STORAGE_FORMAT));
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->end_value, $expected_end_date->format(DATETIME_DATE_STORAGE_FORMAT));
$expected_start_date = new DrupalDateTime('+45 days', DateTimeItemInterface::STORAGE_TIMEZONE);
$expected_end_date = new DrupalDateTime('+90 days', DateTimeItemInterface::STORAGE_TIMEZONE);
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->value, $expected_start_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT));
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->end_value, $expected_end_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT));
// Remove default value.
$field_edit = [
@ -1077,7 +1110,7 @@ class DateRangeFieldTest extends DateTestBase {
])
->save();
$expected_date = new DrupalDateTime('now', DATETIME_STORAGE_TIMEZONE);
$expected_date = new DrupalDateTime('now', DateTimeItemInterface::STORAGE_TIMEZONE);
$field_edit = [
'default_value_input[default_date_type]' => 'now',
@ -1087,7 +1120,7 @@ class DateRangeFieldTest extends DateTestBase {
// Make sure only the start value is populated on node add page.
$this->drupalGet('node/add/date_content');
$this->assertFieldByName("{$field_name}[0][value][date]", $expected_date->format(DATETIME_DATE_STORAGE_FORMAT), 'Start date element populated.');
$this->assertFieldByName("{$field_name}[0][value][date]", $expected_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT), 'Start date element populated.');
$this->assertFieldByName("{$field_name}[0][end_value][date]", '', 'End date element empty.');
// Set now as default_value for end date only.
@ -1100,7 +1133,7 @@ class DateRangeFieldTest extends DateTestBase {
// Make sure only the start value is populated on node add page.
$this->drupalGet('node/add/date_content');
$this->assertFieldByName("{$field_name}[0][value][date]", '', 'Start date element empty.');
$this->assertFieldByName("{$field_name}[0][end_value][date]", $expected_date->format(DATETIME_DATE_STORAGE_FORMAT), 'End date element populated.');
$this->assertFieldByName("{$field_name}[0][end_value][date]", $expected_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT), 'End date element populated.');
}
/**
@ -1111,6 +1144,7 @@ class DateRangeFieldTest extends DateTestBase {
$this->fieldStorage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_DATETIME);
$this->fieldStorage->save();
$field_name = $this->fieldStorage->getName();
$field_label = $this->field->label();
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[0][value][date]", '', 'Start date element found.');
@ -1289,7 +1323,7 @@ class DateRangeFieldTest extends DateTestBase {
"{$field_name}[0][end_value][time]" => '12:00:00',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(new FormattableMarkup('The @title end date cannot be before the start date', ['@title' => $field_name]), 'End date before start date has been caught.');
$this->assertText(new FormattableMarkup('The @title end date cannot be before the start date', ['@title' => $field_label]), 'End date before start date has been caught.');
$edit = [
"{$field_name}[0][value][date]" => '2012-12-01',
@ -1298,7 +1332,7 @@ class DateRangeFieldTest extends DateTestBase {
"{$field_name}[0][end_value][time]" => '11:00:00',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(new FormattableMarkup('The @title end date cannot be before the start date', ['@title' => $field_name]), 'End time before start time has been caught.');
$this->assertText(new FormattableMarkup('The @title end date cannot be before the start date', ['@title' => $field_label]), 'End time before start time has been caught.');
}
/**
@ -1309,7 +1343,7 @@ class DateRangeFieldTest extends DateTestBase {
$this->drupalCreateContentType(['type' => 'date_content']);
// Create a field storage with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
$field_name = mb_strtolower($this->randomMachineName());
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',

View file

@ -0,0 +1,75 @@
<?php
namespace Drupal\Tests\datetime_range\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\views\Entity\View;
/**
* Test update of views with datetime_range filters.
*
* @see https://www.drupal.org/node/2786577
* @see datetime_range_post_update_views_string_plugin_id()
*
* @group Update
* @group legacy
*/
class DatetimeRangeViewUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../../tests/fixtures/update/datetime_range-filter-values.php',
];
}
/**
* Tests that datetime_range filter values are updated properly.
*/
public function testViewsPostUpdateDateRangeFilterValues() {
// Load our pre-update test view.
$view = View::load('test_datetime_range_filter_values');
$data = $view->toArray();
// Check pre-update filter values.
$filter1 = $data['display']['default']['display_options']['filters']['field_range_value'];
$this->assertSame('string', $filter1['plugin_id']);
// Check pre-update filter with operator going to be mapped.
$filter2 = $data['display']['default']['display_options']['filters']['field_range_end_value'];
$this->assertSame('string', $filter2['plugin_id']);
$this->assertSame('', $filter2['value']);
$this->assertSame('contains', $filter2['operator']);
// Check pre-update sort values.
$sort = $data['display']['default']['display_options']['sorts']['field_range_value'];
$this->assertSame('standard', $sort['plugin_id']);
$this->runUpdates();
// Reload and initialize our test view.
$view = View::load('test_datetime_range_filter_values');
$data = $view->toArray();
// Check filter values.
$filter1 = $data['display']['default']['display_options']['filters']['field_range_value'];
$this->assertSame('datetime', $filter1['plugin_id']);
$this->assertSame('2017', $filter1['value']['value']);
$this->assertSame('=', $filter1['operator']);
// Check string to datetime operator/value mapping.
$filter2 = $data['display']['default']['display_options']['filters']['field_range_end_value'];
$this->assertSame('datetime', $filter2['plugin_id']);
$this->assertSame('.*', $filter2['value']['value']);
$this->assertSame('regular_expression', $filter2['operator']);
// Check sort values.
$sort = $data['display']['default']['display_options']['sorts']['field_range_value'];
$this->assertSame('datetime', $sort['plugin_id']);
}
}

View file

@ -2,7 +2,6 @@
namespace Drupal\Tests\datetime_range\Kernel;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem;
use Drupal\entity_test\Entity\EntityTest;
@ -47,7 +46,7 @@ class DateRangeItemTest extends FieldKernelTestBase {
// Add a datetime range field.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => Unicode::strtolower($this->randomMachineName()),
'field_name' => mb_strtolower($this->randomMachineName()),
'entity_type' => 'entity_test',
'type' => 'daterange',
'settings' => ['datetime_type' => DateRangeItem::DATETIME_TYPE_DATE],
@ -100,6 +99,8 @@ class DateRangeItemTest extends FieldKernelTestBase {
sleep(1);
$end_date = $entity->{$field_name}->end_date;
$this->assertEquals($start_date->getTimestamp(), $end_date->getTimestamp());
$this->assertEquals('12:00:00', $start_date->format('H:i:s'));
$this->assertEquals('12:00:00', $end_date->format('H:i:s'));
}
}

View file

@ -2,7 +2,6 @@
namespace Drupal\Tests\datetime_range\Kernel;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Language\Language;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
@ -59,7 +58,7 @@ class SeparatorTranslationTest extends KernelTestBase {
// Add a datetime range field.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => Unicode::strtolower($this->randomMachineName()),
'field_name' => mb_strtolower($this->randomMachineName()),
'entity_type' => 'entity_test',
'type' => 'daterange',
'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATE],

View file

@ -0,0 +1,43 @@
<?php
namespace Drupal\Tests\datetime_range\Kernel\Views;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Serialization\Yaml;
use Drupal\KernelTests\KernelTestBase;
use Drupal\views\Entity\View;
/**
* Tests datetime_range.module when an entity type provides no views data.
*
* @group datetime
*/
class EntityTypeWithoutViewsDataTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'datetime_range',
'datetime_range_test',
'node',
'system',
'taxonomy',
'text',
'user',
'views',
];
/**
* Tests the case when an entity type provides no views data.
*
* @see datetime_test_entity_type_alter()
* @see datetime_range_view_presave()
*/
public function testEntityTypeWithoutViewsData() {
$view_yaml = drupal_get_path('module', 'taxonomy') . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY . '/views.view.taxonomy_term.yml';
$values = Yaml::decode(file_get_contents($view_yaml));
$this->assertEquals(SAVED_NEW, View::create($values)->save());
}
}

View file

@ -0,0 +1,158 @@
<?php
namespace Drupal\Tests\datetime_range\Kernel\Views;
use Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\Node;
use Drupal\Tests\datetime\Kernel\Views\DateTimeHandlerTestBase;
use Drupal\views\Views;
/**
* Tests date-only fields.
*
* @group datetime
*/
class FilterDateTest extends DateTimeHandlerTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['datetime_test', 'node', 'datetime_range', 'field'];
/**
* Type of the field.
*
* @var string
*/
protected static $field_type = 'daterange';
/**
* {@inheritdoc}
*/
public static $testViews = ['test_filter_datetime'];
/**
* For offset tests, set to the current time.
*/
protected static $date;
/**
* {@inheritdoc}
*
* Create nodes with relative date range of:
* yesterday - today, today - today, and today - tomorrow.
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Set to 'today'.
static::$date = $this->getUTCEquivalentOfUserNowAsTimestamp();
// Change field storage to date-only.
$storage = FieldStorageConfig::load('node.' . static::$field_name);
$storage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_DATE);
$storage->save();
// Retrieve tomorrow, today and yesterday dates.
$dates = $this->getRelativeDateValuesFromTimestamp(static::$date);
// Node 0: Yesterday - Today.
$node = Node::create([
'title' => $this->randomMachineName(8),
'type' => 'page',
'field_date' => [
'value' => $dates[2],
'end_value' => $dates[1],
],
]);
$node->save();
$this->nodes[] = $node;
// Node 1: Today - Today.
$node = Node::create([
'title' => $this->randomMachineName(8),
'type' => 'page',
'field_date' => [
'value' => $dates[1],
'end_value' => $dates[1],
],
]);
$node->save();
$this->nodes[] = $node;
// Node 2: Today - Tomorrow.
$node = Node::create([
'title' => $this->randomMachineName(8),
'type' => 'page',
'field_date' => [
'value' => $dates[1],
'end_value' => $dates[0],
],
]);
$node->save();
$this->nodes[] = $node;
// Add end date filter to the test_filter_datetime view.
/** @var \Drupal\views\Entity\View $view */
$view = \Drupal::entityTypeManager()->getStorage('view')->load('test_filter_datetime');
$field_end = static::$field_name . '_end_value';
$display = $view->getDisplay('default');
$filter_end_date = $display['display_options']['filters'][static::$field_name . '_value'];
$filter_end_date['id'] = $field_end;
$filter_end_date['field'] = $field_end;
$view->getDisplay('default')['display_options']['filters'][$field_end] = $filter_end_date;
$view->save();
}
/**
* Test offsets with date-only fields.
*/
public function testDateOffsets() {
$view = Views::getView('test_filter_datetime');
$field_start = static::$field_name . '_value';
$field_end = static::$field_name . '_end_value';
// Test simple operations.
$view->initHandlers();
// Search nodes with:
// - start date greater than or equal to 'yesterday'.
// - end date lower than or equal to 'today'.
// Expected results: nodes 0 and 1.
$view->filter[$field_start]->operator = '>=';
$view->filter[$field_start]->value['type'] = 'offset';
$view->filter[$field_start]->value['value'] = '-1 day';
$view->filter[$field_end]->operator = '<=';
$view->filter[$field_end]->value['type'] = 'offset';
$view->filter[$field_end]->value['value'] = 'now';
$view->setDisplay('default');
$this->executeView($view);
$expected_result = [
['nid' => $this->nodes[0]->id()],
['nid' => $this->nodes[1]->id()],
];
$this->assertIdenticalResultset($view, $expected_result, $this->map);
$view->destroy();
// Search nodes with:
// - start date greater than or equal to 'yesterday'.
// - end date greater than 'today'.
// Expected results: node 2.
$view->initHandlers();
$view->filter[$field_start]->operator = '>=';
$view->filter[$field_start]->value['type'] = 'offset';
$view->filter[$field_start]->value['value'] = '-1 day';
$view->filter[$field_end]->operator = '>';
$view->filter[$field_end]->value['type'] = 'offset';
$view->filter[$field_end]->value['value'] = 'now';
$view->setDisplay('default');
$this->executeView($view);
$expected_result = [
['nid' => $this->nodes[2]->id()],
];
$this->assertIdenticalResultset($view, $expected_result, $this->map);
}
}