Commit 53068d07 authored by catch's avatar catch

Issue #2191903 by damiankloip: Provide a ConfigEntityNormalizer.

parent a60a5b87
<?php
/**
* @file
* Contains \Drupal\serialization\Normalizer\ConfigEntityNormalizer.
*/
namespace Drupal\serialization\Normalizer;
/**
* Normalizes/denormalizes Drupal config entity objects into an array structure.
*/
class ConfigEntityNormalizer extends EntityNormalizer {
/**
* The interface or class that this Normalizer supports.
*
* @var array
*/
protected $supportedInterfaceOrClass = array('Drupal\Core\Config\Entity\ConfigEntityInterface');
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = array()) {
return $object->getExportProperties();
}
}
......@@ -2,6 +2,11 @@ services:
serializer:
class: Symfony\Component\Serializer\Serializer
arguments: [{ }, { }]
serializer.normalizer.config_entity:
class: Drupal\serialization\Normalizer\ConfigEntityNormalizer
tags:
- { name: normalizer }
arguments: ['@entity.manager']
serializer.normalizer.entity:
class: Drupal\serialization\Normalizer\EntityNormalizer
tags:
......
<?php
/**
* @file
* Contains \Drupal\serialization\Tests\Normalizer\ConfigNormalizerTest.
*/
namespace Drupal\serialization\Tests\Normalizer;
use Drupal\serialization\Normalizer\ConfigEntityNormalizer;
use Drupal\Tests\UnitTestCase;
/**
* Tests the ConfigEntityNormalizer class.
*
* @group Serialization
*
* @coversDefaultClass \Drupal\serialization\Normalizer\ConfigEntityNormalizer
*/
class ConfigEntityNormalizerTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'ConfigEntityNormalizer',
'description' => 'Tests the ConfigEntityNormalizer class.',
'group' => 'Serialization',
);
}
/**
* Tests the normalize() method.
*
* @covers ::normalize
*/
public function testNormalize() {
$test_export_properties = array('test' => 'test');
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$normalizer = new ConfigEntityNormalizer($entity_manager);
$config_entity = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
$config_entity->expects($this->once())
->method('getExportProperties')
->will($this->returnValue($test_export_properties));
$this->assertSame($test_export_properties, $normalizer->normalize($config_entity));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment