3 namespace Drupal\Tests\comment\Kernel\Views;
5 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
6 use Drupal\user\Entity\Role;
7 use Drupal\views\Tests\ViewTestData;
10 * Provides a common test base for comment views tests.
12 abstract class CommentViewsKernelTestBase extends ViewsKernelTestBase {
19 public static $modules = ['comment_test_views', 'user', 'comment'];
24 * @var \Drupal\user\UserInterface
29 * The entity storage for comments.
31 * @var \Drupal\comment\CommentStorageInterface
33 protected $commentStorage;
36 * The entity storage for users.
38 * @var \Drupal\user\UserStorageInterface
40 protected $userStorage;
42 protected function setUp($import_test_views = TRUE) {
43 parent::setUp($import_test_views);
45 ViewTestData::createTestViews(get_class($this), ['comment_test_views']);
47 $this->installEntitySchema('user');
48 $this->installEntitySchema('comment');
49 $this->installConfig(['user']);
51 $entity_manager = $this->container->get('entity.manager');
52 $this->commentStorage = $entity_manager->getStorage('comment');
53 $this->userStorage = $entity_manager->getStorage('user');
55 // Insert a row for the anonymous user.
64 $admin_role = Role::create(['id' => 'admin']);
65 $admin_role->grantPermission('administer comments');
68 /* @var \Drupal\user\RoleInterface $anonymous_role */
69 $anonymous_role = Role::load(Role::ANONYMOUS_ID);
70 $anonymous_role->grantPermission('access comments');
71 $anonymous_role->save();
73 $this->adminUser = $this->userStorage->create(['name' => $this->randomMachineName()]);
74 $this->adminUser->addRole('admin');
75 $this->adminUser->save();