From 8f85b859dc97de8eba00fe8e0dab1ea580024379 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Mon, 1 Apr 2019 21:56:12 +0100 Subject: [PATCH] Issue #2079647 by claudiu.cristea: Convert UserSaveTest to a kernel test. Remove useless test (cherry picked from commit f2aeaaa1b8b6886c74d8e469f3da8007504d3b43) --- .../tests/src/Functional/UserSaveTest.php | 61 ------------------- .../user/tests/src/Kernel/UserSaveTest.php | 39 ++++++++++++ 2 files changed, 39 insertions(+), 61 deletions(-) delete mode 100644 core/modules/user/tests/src/Functional/UserSaveTest.php create mode 100644 core/modules/user/tests/src/Kernel/UserSaveTest.php diff --git a/core/modules/user/tests/src/Functional/UserSaveTest.php b/core/modules/user/tests/src/Functional/UserSaveTest.php deleted file mode 100644 index c693b39cefee..000000000000 --- a/core/modules/user/tests/src/Functional/UserSaveTest.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -namespace Drupal\Tests\user\Functional; - -use Drupal\Tests\BrowserTestBase; -use Drupal\user\Entity\User; - -/** - * Tests account saving for arbitrary new uid. - * - * @group user - */ -class UserSaveTest extends BrowserTestBase { - - /** - * Test creating a user with arbitrary uid. - */ - public function testUserImport() { - // User ID must be a number that is not in the database. - - $uids = \Drupal::entityManager()->getStorage('user')->getQuery() - ->sort('uid', 'DESC') - ->range(0, 1) - ->execute(); - $max_uid = reset($uids); - $test_uid = $max_uid + mt_rand(1000, 1000000); - $test_name = $this->randomMachineName(); - - // Create the base user, based on drupalCreateUser(). - $user = User::create([ - 'name' => $test_name, - 'uid' => $test_uid, - 'mail' => $test_name . '@example.com', - 'pass' => user_password(), - 'status' => 1, - ]); - $user->enforceIsNew(); - $user->save(); - - // Test if created user exists. - $user_by_uid = User::load($test_uid); - $this->assertTrue($user_by_uid, 'Loading user by uid.'); - - $user_by_name = user_load_by_name($test_name); - $this->assertTrue($user_by_name, 'Loading user by name.'); - } - - /** - * Ensures that an existing password is unset after the user was saved. - */ - public function testExistingPasswordRemoval() { - /** @var \Drupal\user\Entity\User $user */ - $user = User::create(['name' => $this->randomMachineName()]); - $user->save(); - $user->setExistingPassword('existing password'); - $this->assertNotNull($user->pass->existing); - $user->save(); - $this->assertNull($user->pass->existing); - } - -} diff --git a/core/modules/user/tests/src/Kernel/UserSaveTest.php b/core/modules/user/tests/src/Kernel/UserSaveTest.php new file mode 100644 index 000000000000..dfdd13a5bea0 --- /dev/null +++ b/core/modules/user/tests/src/Kernel/UserSaveTest.php @@ -0,0 +1,39 @@ +<?php + +namespace Drupal\Tests\user\Kernel; + +use Drupal\KernelTests\KernelTestBase; +use Drupal\user\Entity\User; + +/** + * Tests account saving for arbitrary new uid. + * + * @group user + */ +class UserSaveTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'system', + 'user', + ]; + + /** + * Ensures that an existing password is unset after the user was saved. + */ + public function testExistingPasswordRemoval() { + $this->installSchema('system', ['sequences']); + $this->installEntitySchema('user'); + + /** @var \Drupal\user\Entity\User $user */ + $user = User::create(['name' => $this->randomMachineName()]); + $user->save(); + $user->setExistingPassword('existing password'); + $this->assertNotNull($user->pass->existing); + $user->save(); + $this->assertNull($user->pass->existing); + } + +} -- GitLab