You are here

public function UserEntityTest::testUserValidation in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/tests/src/Kernel/UserEntityTest.php \Drupal\Tests\user\Kernel\UserEntityTest::testUserValidation()

Tests that all user fields validate properly.

See also

\Drupal\Core\Field\FieldItemListInterface::generateSampleItems

\Drupal\Core\Field\FieldItemInterface::generateSampleValue()

\Drupal\Core\Entity\FieldableEntityInterface::validate()

File

core/modules/user/tests/src/Kernel/UserEntityTest.php, line 83

Class

UserEntityTest
Tests the user entity class.

Namespace

Drupal\Tests\user\Kernel

Code

public function testUserValidation() {
  $user = User::create([]);
  foreach ($user as $field_name => $field) {
    if (!in_array($field_name, [
      'uid',
    ])) {
      $user->{$field_name}
        ->generateSampleItems();
    }
  }
  $violations = $user
    ->validate();
  $this
    ->assertFalse((bool) $violations
    ->count());
}