Pull merge.
[yaffs-website] / web / core / modules / migrate / tests / src / Unit / process / FormatDateTest.php
index c1e0c631bd2eb886381205986407a9326799b77e..d11e95e4f11540915058e827f68b17dc0abd7bfd 100644 (file)
@@ -56,6 +56,40 @@ class FormatDateTest extends MigrateProcessTestCase {
     $this->plugin->transform('January 5, 1955', $this->migrateExecutable, $this->row, 'field_date');
   }
 
+  /**
+   * Tests that "timezone" configuration key triggers deprecation error.
+   *
+   * @covers ::transform
+   *
+   * @dataProvider providerTestDeprecatedTimezoneConfigurationKey
+   *
+   * @group legacy
+   * @expectedDeprecation Configuration key "timezone" is deprecated in 8.4.x and will be removed before Drupal 9.0.0, use "from_timezone" and "to_timezone" instead. See https://www.drupal.org/node/2885746
+   */
+  public function testDeprecatedTimezoneConfigurationKey($configuration, $value, $expected) {
+    $this->plugin = new FormatDate($configuration, 'test_format_date', []);
+    $actual = $this->plugin->transform($value, $this->migrateExecutable, $this->row, 'field_date');
+
+    $this->assertEquals($expected, $actual);
+  }
+
+  /**
+   * Data provider for testDeprecatedTimezoneConfigurationKey.
+   */
+  public function providerTestDeprecatedTimezoneConfigurationKey() {
+    return [
+      [
+        'configuration' => [
+          'from_format' => 'Y-m-d\TH:i:sO',
+          'to_format' => 'c e',
+          'timezone' => 'America/Managua',
+        ],
+        'value' => '2004-12-19T10:19:42-0600',
+        'expected' => '2004-12-19T10:19:42-06:00 -06:00',
+      ],
+    ];
+  }
+
   /**
    * Tests transformation.
    *
@@ -96,10 +130,10 @@ class FormatDateTest extends MigrateProcessTestCase {
       'datetime_datetime' => [
         'configuration' => [
           'from_format' => 'm/d/Y H:i:s',
-          'to_format' => 'Y-m-d\TH:i:s',
+          'to_format' => 'Y-m-d\TH:i:s e',
         ],
         'value' => '01/05/1955 10:43:22',
-        'expected' => '1955-01-05T10:43:22',
+        'expected' => '1955-01-05T10:43:22 Australia/Sydney',
       ],
       'empty_values' => [
         'configuration' => [
@@ -109,14 +143,73 @@ class FormatDateTest extends MigrateProcessTestCase {
         'value' => '',
         'expected' => '',
       ],
-      'timezone' => [
+      'timezone_from_to' => [
         'configuration' => [
-          'from_format' => 'Y-m-d\TH:i:sO',
-          'to_format' => 'Y-m-d\TH:i:s',
-          'timezone' => 'America/Managua',
+          '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-19T10:19:42-0600',
-        'expected' => '2004-12-19T10:19:42',
+        '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',
       ],
     ];
   }