Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/user/tests/src/Kernel/UserDeleteTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\user\Kernel; | |
4 | |
5 use Drupal\Core\Database\Database; | |
6 use Drupal\KernelTests\KernelTestBase; | |
7 use Drupal\Tests\user\Traits\UserCreationTrait; | |
8 use Drupal\user\Entity\User; | |
9 | |
10 /** | |
11 * Tests deleting of user accounts. | |
12 * | |
13 * @group user | |
14 */ | |
15 class UserDeleteTest extends KernelTestBase { | |
16 | |
17 use UserCreationTrait; | |
18 | |
19 /** | |
20 * {@inheritdoc} | |
21 */ | |
22 protected static $modules = [ | |
23 'system', | |
24 'user', | |
25 ]; | |
26 | |
27 /** | |
28 * Test deleting multiple users. | |
29 */ | |
30 public function testUserDeleteMultiple() { | |
31 $this->installSchema('system', ['sequences']); | |
32 $this->installSchema('user', ['users_data']); | |
33 $this->installEntitySchema('user'); | |
34 | |
35 // Create a few users with permissions, so roles will be created. | |
36 $user_a = $this->createUser(['access user profiles']); | |
37 $user_b = $this->createUser(['access user profiles']); | |
38 $user_c = $this->createUser(['access user profiles']); | |
39 | |
40 $uids = [$user_a->id(), $user_b->id(), $user_c->id()]; | |
41 | |
42 // These users should have a role | |
43 $connection = Database::getConnection(); | |
44 $query = $connection->select('user__roles', 'r'); | |
45 $roles_created = $query | |
46 ->fields('r', ['entity_id']) | |
47 ->condition('entity_id', $uids, 'IN') | |
48 ->countQuery() | |
49 ->execute() | |
50 ->fetchField(); | |
51 | |
52 $this->assertGreaterThan(0, $roles_created); | |
53 // We should be able to load one of the users. | |
54 $this->assertNotNull(User::load($user_a->id())); | |
55 // Delete the users. | |
56 user_delete_multiple($uids); | |
57 // Test if the roles assignments are deleted. | |
58 $query = $connection->select('user__roles', 'r'); | |
59 $roles_after_deletion = $query | |
60 ->fields('r', ['entity_id']) | |
61 ->condition('entity_id', $uids, 'IN') | |
62 ->countQuery() | |
63 ->execute() | |
64 ->fetchField(); | |
65 $this->assertEquals(0, $roles_after_deletion); | |
66 // Test if the users are deleted, User::load() will return NULL. | |
67 $this->assertNull(User::load($user_a->id())); | |
68 $this->assertNull(User::load($user_b->id())); | |
69 $this->assertNull(User::load($user_c->id())); | |
70 } | |
71 | |
72 } |