Commit 40af1480 authored by catch's avatar catch

Issue #2917584 by kristiaanvandeneynde, Spokje, catch, xjm, daffie, larowlan:...

Issue #2917584 by kristiaanvandeneynde, Spokje, catch, xjm, daffie, larowlan: Some tests only go green because they happen to run as UID1

(cherry picked from commit fbabffd4)
parent b999b138
......@@ -34,6 +34,14 @@ class CommentDefaultFormatterCacheTagsTest extends EntityKernelTestBase {
protected function setUp(): void {
parent::setUp();
// 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->createUser(['uid' => 1, 'name' => 'user1'])->save();
$this->container->get('module_handler')->loadInclude('comment', 'install');
comment_install();
$session = new Session();
$request = Request::create('/');
......@@ -48,7 +56,7 @@ protected function setUp(): void {
// user does not have access to the 'administer comments' permission, to
// ensure only published comments are visible to the end user.
$current_user = $this->container->get('current_user');
$current_user->setAccount($this->createUser([], ['access comments']));
$current_user->setAccount($this->createUser([], ['access comments', 'post comments']));
// Install tables and config needed to render comments.
$this->installSchema('comment', ['comment_entity_statistics']);
......@@ -125,7 +133,7 @@ public function testCacheTags() {
'comment:' . $comment->id(),
'config:filter.format.plain_text',
'user_view',
'user:2',
'user:' . $user->id(),
'config:core.entity_form_display.comment.comment.default',
'config:field.field.comment.comment.comment_body',
'config:field.field.entity_test.entity_test.comment',
......
......@@ -54,6 +54,11 @@ protected function setUp($import_test_views = TRUE): void {
// Create the anonymous role.
$this->installConfig(['user']);
// 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.
User::create(['uid' => 1, 'name' => 'user1'])->save();
// Enable another language.
ConfigurableLanguage::createFromLangcode('ur')->save();
// Rebuild the container to update the default language container variable.
......@@ -72,7 +77,7 @@ protected function setUp($import_test_views = TRUE): void {
// Created admin role.
$admin_role = Role::create([
'id' => 'admin',
'permissions' => ['administer comments'],
'permissions' => ['administer comments', 'skip comment approval'],
]);
$admin_role->save();
// Create the admin user.
......
......@@ -61,8 +61,16 @@ protected function setUp($import_test_views = TRUE) {
])
->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']);
$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 */
......
......@@ -44,12 +44,20 @@ protected function setUp(): void {
$this->installEntitySchema('user');
$this->installSchema('system', ['sequences']);
$this->installConfig(['filter', 'filter_test']);
// 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.
User::create(['uid' => 1, 'name' => 'user1'])->save();
/* @var \Drupal\Core\Render\ElementInfoManager $manager */
$manager = \Drupal::service('plugin.manager.element_info');
$manager->clearCachedDefinitions();
$manager->getDefinitions();
/* @var \Drupal\filter\FilterFormatInterface $filter_test_format */
$filter_test_format = FilterFormat::load('filter_test');
$full_html_format = FilterFormat::load('full_html');
$filtered_html_format = FilterFormat::load('filtered_html');
/* @var \Drupal\user\RoleInterface $role */
$role = Role::create([
......@@ -57,6 +65,8 @@ protected function setUp(): void {
'label' => 'admin',
]);
$role->grantPermission($filter_test_format->getPermissionName());
$role->grantPermission($full_html_format->getPermissionName());
$role->grantPermission($filtered_html_format->getPermissionName());
$role->save();
$this->testUser = User::create([
'name' => 'foobar',
......
......@@ -6,6 +6,7 @@
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
use Drupal\views\Entity\View;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
......@@ -48,6 +49,11 @@ protected function setUpFixtures() {
$this->installEntitySchema('entity_test');
$this->installConfig(['entity_test']);
// 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.
User::create(['uid' => 1, 'name' => 'user1'])->save();
EntityViewMode::create([
'id' => 'entity_test.foobar',
'targetEntityType' => 'entity_test',
......@@ -87,8 +93,15 @@ protected function setUpFixtures() {
])->save();
}
Role::create([
'id' => 'test_role',
'label' => 'Can view test entities',
'permissions' => ['view test entity'],
])->save();
$this->user = User::create([
'name' => 'test user',
'roles' => ['test_role'],
]);
$this->user->save();
......
......@@ -10,6 +10,7 @@
use Drupal\entity_test\Entity\EntityTest;
use Drupal\entity_test\Entity\EntityTestStringId;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
/**
......@@ -48,9 +49,21 @@ protected function setUp(): void {
$this->installEntitySchema('entity_test_string_id');
// 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.
User::create(['uid' => 1, 'name' => 'user1'])->save();
Role::create([
'id' => 'test_role',
'label' => 'Can view test entities',
'permissions' => ['view test entity'],
])->save();
$this->testUser = User::create([
'name' => 'foobar1',
'mail' => 'foobar1@example.com',
'roles' => ['test_role'],
]);
$this->testUser->save();
\Drupal::service('current_user')->setAccount($this->testUser);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment