Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / datetime / tests / src / Functional / DateTimeFieldTest.php
index f4606d49686c10397499012d2599b8b2e90e7185..5acd6fcae1fae38016bc587b37803525afb0f429 100644 (file)
@@ -7,6 +7,7 @@ use Drupal\Component\Utility\SafeMarkup;
 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\entity_test\Entity\EntityTest;
 use Drupal\field\Entity\FieldConfig;
 use Drupal\field\Entity\FieldStorageConfig;
@@ -58,7 +59,7 @@ class DateTimeFieldTest extends DateTestBase {
       // mimic the user in a different timezone simply entering '2012-12-31' via
       // the UI.
       $value = '2012-12-31 00:00:00';
-      $date = new DrupalDateTime($value, DATETIME_STORAGE_TIMEZONE);
+      $date = new DrupalDateTime($value, DateTimeItemInterface::STORAGE_TIMEZONE);
 
       // Submit a valid date and ensure it is accepted.
       $date_format = DateFormat::load('html_date')->getPattern();
@@ -100,7 +101,7 @@ class DateTimeFieldTest 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($date);
+      $this->massageTestDate($date);
       foreach ($options as $setting => $values) {
         foreach ($values as $new_value) {
           // Update the entity display settings.
@@ -114,8 +115,8 @@ class DateTimeFieldTest extends DateTestBase {
             case 'format_type':
               // Verify that a date is displayed. Since this is a date-only
               // field, it is expected to display the time as 00:00:00.
-              $expected = format_date($date->getTimestamp(), $new_value, '', DATETIME_STORAGE_TIMEZONE);
-              $expected_iso = format_date($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE);
+              $expected = format_date($date->getTimestamp(), $new_value, '', DateTimeItemInterface::STORAGE_TIMEZONE);
+              $expected_iso = format_date($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DateTimeItemInterface::STORAGE_TIMEZONE);
               $output = $this->renderTestEntity($id);
               $expected_markup = '<time datetime="' . $expected_iso . '" class="datetime">' . $expected . '</time>';
               $this->assertContains($expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
@@ -135,7 +136,7 @@ class DateTimeFieldTest extends DateTestBase {
       entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
         ->setComponent($field_name, $this->displayOptions)
         ->save();
-      $expected = $date->format(DATETIME_DATE_STORAGE_FORMAT);
+      $expected = $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 in %timezone.', [
         '%expected' => $expected,
@@ -296,7 +297,7 @@ class DateTimeFieldTest extends DateTestBase {
     entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
       ->setComponent($field_name, $this->displayOptions)
       ->save();
-    $expected = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
+    $expected = $date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
     $output = $this->renderTestEntity($id);
     $this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
 
@@ -329,7 +330,7 @@ class DateTimeFieldTest extends DateTestBase {
     $entity = EntityTest::load($id);
     $field_name = $this->fieldStorage->getName();
     $date = DrupalDateTime::createFromTimestamp($timestamp, 'UTC');
-    $entity->{$field_name}->value = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
+    $entity->{$field_name}->value = $date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
     $entity->save();
 
     $this->displayOptions['type'] = 'datetime_time_ago';
@@ -356,7 +357,7 @@ class DateTimeFieldTest extends DateTestBase {
     $entity = EntityTest::load($id);
     $field_name = $this->fieldStorage->getName();
     $date = DrupalDateTime::createFromTimestamp($timestamp, 'UTC');
-    $entity->{$field_name}->value = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
+    $entity->{$field_name}->value = $date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
     $entity->save();
 
     entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
@@ -695,7 +696,7 @@ class DateTimeFieldTest extends DateTestBase {
       $new_node = Node::create(['type' => 'date_content']);
       $expected_date = new DrupalDateTime('now', drupal_get_user_timezone());
       $this->assertEqual($new_node->get($field_name)
-        ->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
+        ->offsetGet(0)->value, $expected_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT));
 
       // Set an invalid relative default_value to test validation.
       $field_edit = [
@@ -734,7 +735,7 @@ class DateTimeFieldTest extends DateTestBase {
       $new_node = Node::create(['type' => 'date_content']);
       $expected_date = new DrupalDateTime('+90 days', drupal_get_user_timezone());
       $this->assertEqual($new_node->get($field_name)
-        ->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
+        ->offsetGet(0)->value, $expected_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT));
 
       // Remove default value.
       $field_edit = [