Skip to content
Snippets Groups Projects
Unverified Commit 1a6a8cf1 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3041036 by claudiu.cristea: Convert UserDeleteTest to kernel test (or get rid of it?)

(cherry picked from commit 48522ffe)
parent d83b2ce4
No related branches found
No related tags found
No related merge requests found
<?php <?php
namespace Drupal\Tests\user\Functional; namespace Drupal\Tests\user\Kernel;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\Tests\BrowserTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
/** /**
* Tests account deleting of users. * Tests deleting of user accounts.
* *
* @group user * @group user
*/ */
class UserDeleteTest extends BrowserTestBase { class UserDeleteTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'user',
];
/** /**
* Test deleting multiple users. * Test deleting multiple users.
*/ */
public function testUserDeleteMultiple() { public function testUserDeleteMultiple() {
$this->installSchema('system', ['sequences']);
$this->installSchema('user', ['users_data']);
$this->installEntitySchema('user');
// Create a few users with permissions, so roles will be created. // Create a few users with permissions, so roles will be created.
$user_a = $this->drupalCreateUser(['access user profiles']); $user_a = $this->createUser(['access user profiles']);
$user_b = $this->drupalCreateUser(['access user profiles']); $user_b = $this->createUser(['access user profiles']);
$user_c = $this->drupalCreateUser(['access user profiles']); $user_c = $this->createUser(['access user profiles']);
$uids = [$user_a->id(), $user_b->id(), $user_c->id()]; $uids = [$user_a->id(), $user_b->id(), $user_c->id()];
...@@ -34,9 +49,9 @@ public function testUserDeleteMultiple() { ...@@ -34,9 +49,9 @@ public function testUserDeleteMultiple() {
->execute() ->execute()
->fetchField(); ->fetchField();
$this->assertTrue($roles_created > 0, 'Role assignments created for new users and deletion of role assignments can be tested'); $this->assertGreaterThan(0, $roles_created);
// We should be able to load one of the users. // We should be able to load one of the users.
$this->assertTrue(User::load($user_a->id()), 'User is created and deletion of user can be tested'); $this->assertNotNull(User::load($user_a->id()));
// Delete the users. // Delete the users.
user_delete_multiple($uids); user_delete_multiple($uids);
// Test if the roles assignments are deleted. // Test if the roles assignments are deleted.
...@@ -47,11 +62,11 @@ public function testUserDeleteMultiple() { ...@@ -47,11 +62,11 @@ public function testUserDeleteMultiple() {
->countQuery() ->countQuery()
->execute() ->execute()
->fetchField(); ->fetchField();
$this->assertTrue($roles_after_deletion == 0, 'Role assignments deleted along with users'); $this->assertEquals(0, $roles_after_deletion);
// Test if the users are deleted, User::load() will return NULL. // Test if the users are deleted, User::load() will return NULL.
$this->assertNull(User::load($user_a->id()), format_string('User with id @uid deleted.', ['@uid' => $user_a->id()])); $this->assertNull(User::load($user_a->id()));
$this->assertNull(User::load($user_b->id()), format_string('User with id @uid deleted.', ['@uid' => $user_b->id()])); $this->assertNull(User::load($user_b->id()));
$this->assertNull(User::load($user_c->id()), format_string('User with id @uid deleted.', ['@uid' => $user_c->id()])); $this->assertNull(User::load($user_c->id()));
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment