3 namespace Drupal\Tests\rest\Functional;
6 * Trait for ResourceTestBase subclasses formatting expected timestamp data.
8 trait BcTimestampNormalizerUnixTestTrait {
11 * Formats a UNIX timestamp.
13 * Depending on the 'bc_timestamp_normalizer_unix' setting. The return will be
14 * an RFC3339 date string or the same timestamp that was passed in.
16 * @param int $timestamp
17 * The timestamp value to format.
20 * The formatted RFC3339 date string or UNIX timestamp.
22 * @see \Drupal\serialization\Normalizer\TimestampItemNormalizer
24 protected function formatExpectedTimestampItemValues($timestamp) {
25 // If the setting is enabled, just return the timestamp as-is now.
26 if ($this->config('serialization.settings')->get('bc_timestamp_normalizer_unix')) {
27 return ['value' => $timestamp];
30 // Otherwise, format the date string to the same that
31 // \Drupal\serialization\Normalizer\TimestampItemNormalizer will produce.
32 $date = new \DateTime();
33 $date->setTimestamp($timestamp);
34 $date->setTimezone(new \DateTimeZone('UTC'));
36 // Format is also added to the expected return values.
38 'value' => $date->format(\DateTime::RFC3339),
39 'format' => \DateTime::RFC3339,