You are here

public function FormatDateTest::datesDataProvider in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Unit/process/FormatDateTest.php \Drupal\Tests\migrate\Unit\process\FormatDateTest::datesDataProvider()
  2. 9 core/modules/migrate/tests/src/Unit/process/FormatDateTest.php \Drupal\Tests\migrate\Unit\process\FormatDateTest::datesDataProvider()

Data provider of test dates.

Return value

array Array of date formats and actual/expected values.

File

core/modules/migrate/tests/src/Unit/process/FormatDateTest.php, line 104

Class

FormatDateTest
Tests the format date process plugin.

Namespace

Drupal\Tests\migrate\Unit\process

Code

public function datesDataProvider() {
  return [
    'datetime_date' => [
      'configuration' => [
        'from_format' => 'm/d/Y',
        'to_format' => 'Y-m-d',
      ],
      'value' => '01/05/1955',
      'expected' => '1955-01-05',
    ],
    'datetime_datetime' => [
      'configuration' => [
        'from_format' => 'm/d/Y H:i:s',
        'to_format' => 'Y-m-d\\TH:i:s e',
      ],
      'value' => '01/05/1955 10:43:22',
      'expected' => '1955-01-05T10:43:22 Australia/Sydney',
    ],
    'empty_values' => [
      'configuration' => [
        'from_format' => 'm/d/Y',
        'to_format' => 'Y-m-d',
      ],
      'value' => '',
      'expected' => '',
    ],
    'timezone_from_to' => [
      'configuration' => [
        'from_format' => 'Y-m-d H:i:s',
        'to_format' => 'Y-m-d H:i:s e',
        'from_timezone' => 'America/Managua',
        'to_timezone' => 'UTC',
      ],
      'value' => '2004-12-19 10:19:42',
      'expected' => '2004-12-19 16:19:42 UTC',
    ],
    'timezone_from' => [
      'configuration' => [
        'from_format' => 'Y-m-d h:i:s',
        'to_format' => 'Y-m-d h:i:s e',
        'from_timezone' => 'America/Managua',
      ],
      'value' => '2004-11-19 10:25:33',
      // Unit tests use Australia/Sydney timezone, so date value will be
      // converted from America/Managua to Australia/Sydney timezone.
      'expected' => '2004-11-20 03:25:33 Australia/Sydney',
    ],
    'timezone_to' => [
      'configuration' => [
        'from_format' => 'Y-m-d H:i:s',
        'to_format' => 'Y-m-d H:i:s e',
        'to_timezone' => 'America/Managua',
      ],
      'value' => '2004-12-19 10:19:42',
      // Unit tests use Australia/Sydney timezone, so date value will be
      // converted from Australia/Sydney to America/Managua timezone.
      'expected' => '2004-12-18 17:19:42 America/Managua',
    ],
    'integer_0' => [
      'configuration' => [
        'from_format' => 'U',
        'to_format' => 'Y-m-d',
      ],
      'value' => 0,
      'expected' => '1970-01-01',
    ],
    'string_0' => [
      'configuration' => [
        'from_format' => 'U',
        'to_format' => 'Y-m-d',
      ],
      'value' => '0',
      'expected' => '1970-01-01',
    ],
    'zeros' => [
      'configuration' => [
        'from_format' => 'Y-m-d H:i:s',
        'to_format' => 'Y-m-d H:i:s e',
        'settings' => [
          'validate_format' => FALSE,
        ],
      ],
      'value' => '0000-00-00 00:00:00',
      'expected' => '-0001-11-30 00:00:00 Australia/Sydney',
    ],
    'zeros_same_timezone' => [
      'configuration' => [
        'from_format' => 'Y-m-d H:i:s',
        'to_format' => 'Y-m-d H:i:s',
        'settings' => [
          'validate_format' => FALSE,
        ],
        'from_timezone' => 'UTC',
        'to_timezone' => 'UTC',
      ],
      'value' => '0000-00-00 00:00:00',
      'expected' => '-0001-11-30 00:00:00',
    ],
    'collected_date_attributes_day' => [
      'configuration' => [
        'from_format' => 'Y-m-d\\TH:i:s',
        'to_format' => 'Y-m-d\\TH:i:s',
      ],
      'value' => '2012-01-00T00:00:00',
      'expected' => '2012-01-01T00:00:00',
    ],
    'collected_date_attributes_month' => [
      'configuration' => [
        'from_format' => 'Y-m-d\\TH:i:s',
        'to_format' => 'Y-m-d\\TH:i:s',
      ],
      'value' => '2012-00-00T00:00:00',
      'expected' => '2012-01-01T00:00:00',
    ],
  ];
}