Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / migrate / tests / src / Unit / process / FormatDateTest.php
index c1e0c631bd2eb886381205986407a9326799b77e..7038c23868f1f6552f6a3cdd8d9f03dad9c8b091 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,37 @@ 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',
       ],
     ];
   }