You are here

public function EntitySerializationTest::testUserNormalize in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::testUserNormalize()
  2. 9 core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::testUserNormalize()

Tests user normalization, using the entity_serialization_test module to override some default access controls.

File

core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php, line 193

Class

EntitySerializationTest
Tests that entities can be serialized to supported core formats.

Namespace

Drupal\Tests\serialization\Kernel

Code

public function testUserNormalize() {

  // 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]');
}