function 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 85  
Class
- UserEntityTest
 - Tests the user entity class.
 
Namespace
Drupal\Tests\user\KernelCode
public function testUserValidation() : void {
  $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());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.