public function EntityNormalizerTest::testNormalize in Drupal 8
Tests the normalize() method.
@covers ::normalize
File
- core/
modules/ serialization/ tests/ src/ Unit/ Normalizer/ EntityNormalizerTest.php, line 75
Class
- EntityNormalizerTest
- @coversDefaultClass \Drupal\serialization\Normalizer\EntityNormalizer @group serialization
Namespace
Drupal\Tests\serialization\Unit\NormalizerCode
public function testNormalize() {
$list_item_1 = $this
->createMock('Drupal\\Core\\TypedData\\TypedDataInterface');
$list_item_2 = $this
->createMock('Drupal\\Core\\TypedData\\TypedDataInterface');
$definitions = [
'field_1' => $list_item_1,
'field_2' => $list_item_2,
];
$content_entity = $this
->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityBase')
->disableOriginalConstructor()
->setMethods([
'getFields',
])
->getMockForAbstractClass();
$content_entity
->expects($this
->once())
->method('getFields')
->will($this
->returnValue($definitions));
$serializer = $this
->getMockBuilder('Symfony\\Component\\Serializer\\Serializer')
->disableOriginalConstructor()
->setMethods([
'normalize',
])
->getMock();
$serializer
->expects($this
->at(0))
->method('normalize')
->with($list_item_1, 'test_format');
$serializer
->expects($this
->at(1))
->method('normalize')
->with($list_item_2, 'test_format');
$this->entityNormalizer
->setSerializer($serializer);
$this->entityNormalizer
->normalize($content_entity, 'test_format');
}