function UserEntityTest::testUserValidation
Same name in other branches
- 9 core/modules/user/tests/src/Kernel/UserEntityTest.php \Drupal\Tests\user\Kernel\UserEntityTest::testUserValidation()
- 8.9.x core/modules/user/tests/src/Kernel/UserEntityTest.php \Drupal\Tests\user\Kernel\UserEntityTest::testUserValidation()
- 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 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.