You are here

public function EntitySerializationTest::testUserNormalize in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/serialization/src/Tests/EntitySerializationTest.php \Drupal\serialization\Tests\EntitySerializationTest::testUserNormalize()

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

File

core/modules/serialization/src/Tests/EntitySerializationTest.php, line 147
Contains \Drupal\serialization\Tests\EntitySerializationTest.

Class

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

Namespace

Drupal\serialization\Tests

Code

public function testUserNormalize() {

  // Test password isn't available.
  $normalized = $this->serializer
    ->normalize($this->user);
  $this
    ->assertFalse(array_key_exists('pass', $normalized), '"pass" key does not exist in normalized user');
  $this
    ->assertFalse(array_key_exists('mail', $normalized), '"mail" key does not exist in normalized user');

  // 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
    ->assertIdentical($normalized['pass'], [
    NULL,
  ], '"pass" value is normalized to [NULL]');
}