function EntitySerializationTest::testUserNormalize
Tests user normalization with some default access controls overridden.
See also
entity_serialization_test.module
File
- 
              core/
modules/ serialization/ tests/ src/ Kernel/ EntitySerializationTest.php, line 194  
Class
- EntitySerializationTest
 - Tests that entities can be serialized to supported core formats.
 
Namespace
Drupal\Tests\serialization\KernelCode
public function testUserNormalize() : void {
  // Test password isn't available.
  $normalized = $this->serializer
    ->normalize($this->user);
  $this->assertArrayNotHasKey('pass', $normalized);
  $this->assertArrayNotHasKey('mail', $normalized);
  // Test again using our test user, so that our access control override will
  // allow password viewing.
  $normalized = $this->serializer
    ->normalize($this->user, NULL, [
    'account' => $this->user,
  ]);
  // The key 'pass' will now exist, but the password value should be
  // normalized to NULL.
  $this->assertSame([
    NULL,
  ], $normalized['pass'], '"pass" value is normalized to [NULL]');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.