function UserEntityTest::testUserValidation

Same name and namespace in other branches
  1. 9 core/modules/user/tests/src/Kernel/UserEntityTest.php \Drupal\Tests\user\Kernel\UserEntityTest::testUserValidation()
  2. 10 core/modules/user/tests/src/Kernel/UserEntityTest.php \Drupal\Tests\user\Kernel\UserEntityTest::testUserValidation()
  3. 11.x 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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.