Skip to content
Snippets Groups Projects
Verified Commit 73af6069 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3039955 by plach, TR: Ensure EntityKernelTestBase can use...

Issue #3039955 by plach, TR: Ensure EntityKernelTestBase can use UserCreationTrait::setUpCurrentUser()
parent e9c89de0
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -4,14 +4,23 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
use Drupal\Tests\user\Traits\UserCreationTrait;
/**
* Defines an abstract test base for entity kernel tests.
*/
abstract class EntityKernelTestBase extends KernelTestBase {
use UserCreationTrait {
checkPermissions as drupalCheckPermissions;
createAdminRole as drupalCreateAdminRole;
createRole as drupalCreateRole;
createUser as drupalCreateUser;
grantPermissions as drupalGrantPermissions;
setCurrentUser as drupalSetCurrentUser;
setUpCurrentUser as drupalSetUpCurrentUser;
}
/**
* Modules to enable.
*
......@@ -102,24 +111,7 @@ protected function setUp() {
* The created user entity.
*/
protected function createUser($values = [], $permissions = []) {
if ($permissions) {
// Create a new role and apply permissions to it.
$role = Role::create([
'id' => strtolower($this->randomMachineName(8)),
'label' => $this->randomMachineName(8),
]);
$role->save();
user_role_grant_permissions($role->id(), $permissions);
$values['roles'][] = $role->id();
}
$account = User::create($values + [
'name' => $this->randomMachineName(),
'status' => 1,
]);
$account->enforceIsNew();
$account->save();
return $account;
return $this->drupalCreateUser($permissions ?: [], NULL, FALSE, $values ?: []);
}
/**
......
<?php
namespace Drupal\KernelTests\Core\Entity;
/**
* @covers \Drupal\KernelTests\Core\Entity\EntityKernelTestBase
*
* @group Entity
*/
class EntityKernelTestBaseTest extends EntityKernelTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->createUser();
}
/**
* Tests that the current user is set up correctly.
*/
public function testSetUpCurrentUser() {
$account = $this->setUpCurrentUser();
$current_user = \Drupal::currentUser();
$this->assertSame($account->id(), $current_user->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