function DateRangeFieldTest::fromToSettingDataProvider

Same name in other branches
  1. 10 core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php \Drupal\Tests\datetime_range\Functional\DateRangeFieldTest::fromToSettingDataProvider()

Provides data for testing the 'from_to' setting.

Return value

array An array of date settings to test the behavior of the 'from_to' setting.

1 call to DateRangeFieldTest::fromToSettingDataProvider()
DateRangeFieldTest::testFromSetting in core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php
Tests displaying dates with the 'from_to' setting.

File

core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php, line 1501

Class

DateRangeFieldTest
Tests Daterange field functionality.

Namespace

Drupal\Tests\datetime_range\Functional

Code

public static function fromToSettingDataProvider() : array {
    $datetime_types = [
        DateRangeItem::DATETIME_TYPE_DATE => [
            'daterange_default' => [
                DateTimeRangeConstantsInterface::START_DATE => '31 Dec 2012',
                DateTimeRangeConstantsInterface::END_DATE => '6 Jun 2013',
            ],
            'daterange_plain' => [
                DateTimeRangeConstantsInterface::START_DATE => '2012-12-31',
                DateTimeRangeConstantsInterface::END_DATE => '2013-06-06',
            ],
            'daterange_custom' => [
                DateTimeRangeConstantsInterface::START_DATE => '2012-12-31',
                DateTimeRangeConstantsInterface::END_DATE => '2013-06-06',
            ],
        ],
        DateRangeItem::DATETIME_TYPE_DATETIME => [
            'daterange_default' => [
                DateTimeRangeConstantsInterface::START_DATE => '31 Dec 2012 - 00:00',
                DateTimeRangeConstantsInterface::END_DATE => '6 Jun 2013 - 00:00',
            ],
            'daterange_plain' => [
                DateTimeRangeConstantsInterface::START_DATE => '2012-12-31T00:00:00',
                DateTimeRangeConstantsInterface::END_DATE => '2013-06-06T00:00:00',
            ],
            'daterange_custom' => [
                DateTimeRangeConstantsInterface::START_DATE => '2012-12-31T00:00:00',
                DateTimeRangeConstantsInterface::END_DATE => '2013-06-06T00:00:00',
            ],
        ],
        DateRangeItem::DATETIME_TYPE_ALLDAY => [
            'daterange_default' => [
                DateTimeRangeConstantsInterface::START_DATE => '31 Dec 2012',
                DateTimeRangeConstantsInterface::END_DATE => '6 Jun 2013',
            ],
            'daterange_plain' => [
                DateTimeRangeConstantsInterface::START_DATE => '2012-12-31',
                DateTimeRangeConstantsInterface::END_DATE => '2013-06-06',
            ],
            'daterange_custom' => [
                DateTimeRangeConstantsInterface::START_DATE => '2012-12-31',
                DateTimeRangeConstantsInterface::END_DATE => '2013-06-06',
            ],
        ],
    ];
    $return = [];
    $separator = ' THE_SEPARATOR ';
    foreach ($datetime_types as $datetime_type => $field_formatters) {
        foreach ($field_formatters as $field_formatter_type => $dates) {
            // Both start and end date.
            $return[$datetime_type . '-' . $field_formatter_type . '-both'] = [
                'expected' => [
                    $dates[DateTimeRangeConstantsInterface::START_DATE] => TRUE,
                    $separator => TRUE,
                    $dates[DateTimeRangeConstantsInterface::END_DATE] => TRUE,
                ],
                'datetime_type' => $datetime_type,
                'field_formatter_type' => $field_formatter_type,
            ];
            // Only start date.
            $return[$datetime_type . '-' . $field_formatter_type . '-start_date'] = [
                'expected' => [
                    $dates[DateTimeRangeConstantsInterface::START_DATE] => TRUE,
                    $separator => FALSE,
                    $dates[DateTimeRangeConstantsInterface::END_DATE] => FALSE,
                ],
                'datetime_type' => $datetime_type,
                'field_formatter_type' => $field_formatter_type,
                [
                    'from_to' => DateTimeRangeConstantsInterface::START_DATE,
                ],
            ];
            // Only end date.
            $return[$datetime_type . '-' . $field_formatter_type . '-end_date'] = [
                'expected' => [
                    $dates[DateTimeRangeConstantsInterface::START_DATE] => FALSE,
                    $separator => FALSE,
                    $dates[DateTimeRangeConstantsInterface::END_DATE] => TRUE,
                ],
                'datetime_type' => $datetime_type,
                'field_formatter_type' => $field_formatter_type,
                [
                    'from_to' => DateTimeRangeConstantsInterface::END_DATE,
                ],
            ];
        }
    }
    return $return;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.