You are here

public function DateTimeIso8601NormalizerTest::testNormalize in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\DateTimeIso8601NormalizerTest::testNormalize()
  2. 9 core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\DateTimeIso8601NormalizerTest::testNormalize()

@covers ::normalize @dataProvider providerTestNormalize

File

core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php, line 86

Class

DateTimeIso8601NormalizerTest
Unit test coverage for the "datetime_iso8601" @DataType.

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testNormalize($parent_field_item_class, $datetime_type, $expected_format) {
  $formatted_string = $this
    ->randomMachineName();
  $field_item = $this
    ->prophesize($parent_field_item_class);
  if ($parent_field_item_class === DateTimeItem::class) {
    $field_storage_definition = $this
      ->prophesize(FieldStorageDefinitionInterface::class);
    $field_storage_definition
      ->getSetting('datetime_type')
      ->willReturn($datetime_type);
    $field_definition = $this
      ->prophesize(FieldDefinitionInterface::class);
    $field_definition
      ->getFieldStorageDefinition()
      ->willReturn($field_storage_definition);
    $field_item
      ->getFieldDefinition()
      ->willReturn($field_definition);
  }
  else {
    $field_item
      ->getFieldDefinition(Argument::any())
      ->shouldNotBeCalled();
  }
  $this->data
    ->getParent()
    ->willReturn($field_item);
  $drupal_date_time = $this
    ->prophesize(DateTimeIso8601NormalizerTestDrupalDateTime::class);
  $drupal_date_time
    ->setTimezone(new \DateTimeZone('Australia/Sydney'))
    ->willReturn($drupal_date_time
    ->reveal());
  $drupal_date_time
    ->format($expected_format)
    ->willReturn($formatted_string);
  $this->data
    ->getDateTime()
    ->willReturn($drupal_date_time
    ->reveal());
  $normalized = $this->normalizer
    ->normalize($this->data
    ->reveal());
  $this
    ->assertSame($formatted_string, $normalized);
}