class CommentViewsKernelTestBase
Same name and namespace in other branches
- 11.x core/modules/comment/tests/src/Kernel/Views/CommentViewsKernelTestBase.php \Drupal\Tests\comment\Kernel\Views\CommentViewsKernelTestBase
- 10 core/modules/comment/tests/src/Kernel/Views/CommentViewsKernelTestBase.php \Drupal\Tests\comment\Kernel\Views\CommentViewsKernelTestBase
- 8.9.x core/modules/comment/tests/src/Kernel/Views/CommentViewsKernelTestBase.php \Drupal\Tests\comment\Kernel\Views\CommentViewsKernelTestBase
Provides a common test base for comment views tests.
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\comment\Kernel\Views\CommentViewsKernelTestBase extends \Drupal\Tests\views\Kernel\ViewsKernelTestBase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of CommentViewsKernelTestBase
File
-
core/
modules/ comment/ tests/ src/ Kernel/ Views/ CommentViewsKernelTestBase.php, line 12
Namespace
Drupal\Tests\comment\Kernel\ViewsView source
abstract class CommentViewsKernelTestBase extends ViewsKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'comment_test_views',
'user',
'comment',
];
/**
* Admin user.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* The entity storage for comments.
*
* @var \Drupal\comment\CommentStorageInterface
*/
protected $commentStorage;
/**
* The entity storage for users.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
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');
// Insert a row for the anonymous user.
$this->userStorage
->create([
'uid' => 0,
'name' => '',
'status' => 0,
])
->save();
// Create user 1 so that the user created later in the test has a different
// user ID.
// @todo Remove in https://www.drupal.org/node/540008.
$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();
/** @var \Drupal\user\RoleInterface $anonymous_role */
$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();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.