comparison core/modules/user/tests/src/Kernel/UserEntityTest.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
18 * Modules to enable. 18 * Modules to enable.
19 * 19 *
20 * @var array 20 * @var array
21 */ 21 */
22 public static $modules = ['system', 'user', 'field']; 22 public static $modules = ['system', 'user', 'field'];
23
24 /**
25 * {@inheritdoc}
26 */
27 protected function setUp() {
28 parent::setUp();
29 $this->installEntitySchema('user');
30 }
23 31
24 /** 32 /**
25 * Tests some of the methods. 33 * Tests some of the methods.
26 * 34 *
27 * @see \Drupal\user\Entity\User::getRoles() 35 * @see \Drupal\user\Entity\User::getRoles()
63 $this->assertFalse($user->hasRole('test_role_one')); 71 $this->assertFalse($user->hasRole('test_role_one'));
64 $this->assertTrue($user->hasRole('test_role_two')); 72 $this->assertTrue($user->hasRole('test_role_two'));
65 $this->assertEqual([RoleInterface::AUTHENTICATED_ID, 'test_role_two'], $user->getRoles()); 73 $this->assertEqual([RoleInterface::AUTHENTICATED_ID, 'test_role_two'], $user->getRoles());
66 } 74 }
67 75
76 /**
77 * Tests that all user fields validate properly.
78 *
79 * @see \Drupal\Core\Field\FieldItemListInterface::generateSampleItems
80 * @see \Drupal\Core\Field\FieldItemInterface::generateSampleValue()
81 * @see \Drupal\Core\Entity\FieldableEntityInterface::validate()
82 */
83 public function testUserValidation() {
84 $user = User::create([]);
85 foreach ($user as $field_name => $field) {
86 if (!in_array($field_name, ['uid'])) {
87 $user->$field_name->generateSampleItems();
88 }
89 }
90 $violations = $user->validate();
91 $this->assertFalse((bool) $violations->count());
92 }
93
68 } 94 }