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 c693b39cefeee886351f99f8e45ca45cb387a04e..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..dfdd13a5bea0f08ed8d00b4a84b6a5c2a3b912fd --- /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); + } + +}