class UserSaveStatusTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Kernel/UserSaveStatusTest.php \Drupal\Tests\user\Kernel\UserSaveStatusTest
- 9 core/modules/user/tests/src/Kernel/UserSaveStatusTest.php \Drupal\Tests\user\Kernel\UserSaveStatusTest
Tests user saving status.
@group user
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\Tests\user\Kernel\UserSaveStatusTest
Expanded class hierarchy of UserSaveStatusTest
File
- core/
modules/ user/ tests/ src/ Kernel/ UserSaveStatusTest.php, line 13
Namespace
Drupal\Tests\user\KernelView source
class UserSaveStatusTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'system',
'user',
'field',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('user');
}
/**
* Tests SAVED_NEW and SAVED_UPDATED statuses for user entity type.
*/
public function testUserSaveStatus() {
// Create a new user.
$values = [
'uid' => 1,
'name' => $this
->randomMachineName(),
];
$user = User::create($values);
// Test SAVED_NEW.
$return = $user
->save();
$this
->assertEquals(SAVED_NEW, $return, "User was saved with SAVED_NEW status.");
// Test SAVED_UPDATED.
$user->name = $this
->randomMachineName();
$return = $user
->save();
$this
->assertEquals(SAVED_UPDATED, $return, "User was saved with SAVED_UPDATED status.");
}
}