Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / comment / tests / src / Kernel / Views / CommentViewsKernelTestBase.php
1 <?php
2
3 namespace Drupal\Tests\comment\Kernel\Views;
4
5 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
6 use Drupal\user\Entity\Role;
7 use Drupal\views\Tests\ViewTestData;
8
9 /**
10  * Provides a common test base for comment views tests.
11  */
12 abstract class CommentViewsKernelTestBase extends ViewsKernelTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['comment_test_views', 'user', 'comment'];
20
21   /**
22    * Admin user.
23    *
24    * @var \Drupal\user\UserInterface
25    */
26   protected $adminUser;
27
28   /**
29    * The entity storage for comments.
30    *
31    * @var \Drupal\comment\CommentStorageInterface
32    */
33   protected $commentStorage;
34
35   /**
36    * The entity storage for users.
37    *
38    * @var \Drupal\user\UserStorageInterface
39    */
40   protected $userStorage;
41
42   protected function setUp($import_test_views = TRUE) {
43     parent::setUp($import_test_views);
44
45     ViewTestData::createTestViews(get_class($this), ['comment_test_views']);
46
47     $this->installEntitySchema('user');
48     $this->installEntitySchema('comment');
49     $this->installConfig(['user']);
50
51     $entity_manager = $this->container->get('entity.manager');
52     $this->commentStorage = $entity_manager->getStorage('comment');
53     $this->userStorage = $entity_manager->getStorage('user');
54
55     // Insert a row for the anonymous user.
56     $this->userStorage
57       ->create([
58         'uid' => 0,
59         'name' => '',
60         'status' => 0,
61       ])
62       ->save();
63
64     $admin_role = Role::create(['id' => 'admin']);
65     $admin_role->grantPermission('administer comments');
66     $admin_role->save();
67
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();
72
73     $this->adminUser = $this->userStorage->create(['name' => $this->randomMachineName()]);
74     $this->adminUser->addRole('admin');
75     $this->adminUser->save();
76   }
77
78 }