public function ContentEntityNormalizerTest::testNormalizeWithAccountContext in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest::testNormalizeWithAccountContext()
Tests the normalize() method with account context passed.
@covers ::normalize
File
- core/
modules/ serialization/ tests/ src/ Unit/ Normalizer/ ContentEntityNormalizerTest.php, line 92 - Contains \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest.
Class
- ContentEntityNormalizerTest
- @coversDefaultClass \Drupal\serialization\Normalizer\ContentEntityNormalizer @group serialization
Namespace
Drupal\Tests\serialization\Unit\NormalizerCode
public function testNormalizeWithAccountContext() {
$mock_account = $this
->getMock('Drupal\\Core\\Session\\AccountInterface');
$context = [
'account' => $mock_account,
];
$this->serializer
->expects($this
->any())
->method('normalize')
->with($this
->containsOnlyInstancesOf('Drupal\\Core\\Field\\FieldItemListInterface'), 'test_format', $context)
->will($this
->returnValue('test'));
// The mock account should get passed directly into the access() method on
// field items from $context['account'].
$definitions = array(
'field_1' => $this
->createMockFieldListItem(TRUE, $mock_account),
'field_2' => $this
->createMockFieldListItem(FALSE, $mock_account),
);
$content_entity_mock = $this
->createMockForContentEntity($definitions);
$normalized = $this->contentEntityNormalizer
->normalize($content_entity_mock, 'test_format', $context);
$this
->assertArrayHasKey('field_1', $normalized);
$this
->assertEquals('test', $normalized['field_1']);
$this
->assertArrayNotHasKey('field_2', $normalized);
}