public function SerializationTest::testSerializerComponentRegistration

Confirms that modules can register normalizers and encoders.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Serialization/SerializationTest.php, line 45
Definition of Drupal\jsonld\Tests\SerializationTest.

Class

SerializationTest

Namespace

Drupal\system\Tests\Serialization

Code

public function testSerializerComponentRegistration() {
  $object = new \stdClass();
  $format = 'serialization_test';
  $expected = 'Normalized by SerializationTestNormalizer, Encoded by SerializationTestEncoder';

  // Ensure the serialization invokes the expected normalizer and encoder.
  $this
    ->assertIdentical($this->serializer
    ->serialize($object, $format), $expected);

  // Ensure the serialization fails for an unsupported format.
  try {
    $this->serializer
      ->serialize($object, 'unsupported_format');
    $this
      ->fail('The serializer was expected to throw an exception for an unsupported format, but did not.');
  } catch (UnexpectedValueException $e) {
  }
}