CommentViewsKernelTestBase.php in Drupal 10
File
core/modules/comment/tests/src/Kernel/Views/CommentViewsKernelTestBase.php
View source
<?php
namespace Drupal\Tests\comment\Kernel\Views;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\views\Tests\ViewTestData;
abstract class CommentViewsKernelTestBase extends ViewsKernelTestBase {
protected static $modules = [
'comment_test_views',
'user',
'comment',
];
protected $adminUser;
protected $commentStorage;
protected $userStorage;
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
ViewTestData::createTestViews(static::class, [
'comment_test_views',
]);
$this
->installEntitySchema('user');
$this
->installEntitySchema('comment');
$this
->installConfig([
'user',
]);
$entity_type_manager = $this->container
->get('entity_type.manager');
$this->commentStorage = $entity_type_manager
->getStorage('comment');
$this->userStorage = $entity_type_manager
->getStorage('user');
$this->userStorage
->create([
'uid' => 0,
'name' => '',
'status' => 0,
])
->save();
$this->userStorage
->create([
'uid' => 1,
'name' => 'user1',
])
->save();
$admin_role = Role::create([
'id' => 'admin',
'label' => 'Admin',
]);
$admin_role
->grantPermission('administer comments');
$admin_role
->grantPermission('access comments');
$admin_role
->grantPermission('post comments');
$admin_role
->grantPermission('view test entity');
$admin_role
->save();
$anonymous_role = Role::load(Role::ANONYMOUS_ID);
$anonymous_role
->grantPermission('access comments');
$anonymous_role
->save();
$this->adminUser = $this->userStorage
->create([
'name' => $this
->randomMachineName(),
]);
$this->adminUser
->addRole('admin');
$this->adminUser
->save();
}
}