Skip to content

Commit 2943135

Browse files
committed
Issue #3439917 by sukr_s, smustgrave, adwivedi008, alexpott, vensires, quietone: Fix Views tests that rely on UID1's super user behavior
1 parent a9c47bf commit 2943135

File tree

6 files changed

+12
-55
lines changed

6 files changed

+12
-55
lines changed

modules/views/tests/src/Functional/Handler/FieldEntityLinkBaseTest.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ class FieldEntityLinkBaseTest extends ViewTestBase {
2727
*/
2828
protected static $modules = ['node', 'language'];
2929

30-
/**
31-
* {@inheritdoc}
32-
*
33-
* @todo Remove and fix test to not rely on super user.
34-
* @see https://www.drupal.org/project/drupal/issues/3437620
35-
*/
36-
protected bool $usesSuperUserAccessPolicy = TRUE;
3730

3831
/**
3932
* {@inheritdoc}
@@ -67,7 +60,10 @@ protected function setUp($import_test_views = TRUE, $modules = ['views_test_conf
6760
$translation->save();
6861
}
6962

70-
$this->drupalLogin($this->rootUser);
63+
$this->drupalLogin($this->createUser([
64+
'delete any article content',
65+
'edit any article content',
66+
]));
7167

7268
}
7369

modules/views/tests/src/Functional/Plugin/ContextualFiltersStringTest.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ class ContextualFiltersStringTest extends ViewTestBase {
2323
'views_test_config',
2424
];
2525

26-
/**
27-
* {@inheritdoc}
28-
*
29-
* @todo Remove and fix test to not rely on super user.
30-
* @see https://www.drupal.org/project/drupal/issues/3437620
31-
*/
32-
protected bool $usesSuperUserAccessPolicy = TRUE;
33-
3426
/**
3527
* {@inheritdoc}
3628
*/
@@ -73,7 +65,7 @@ protected function setUp($import_test_views = TRUE, $modules = ['views_test_conf
7365
$this->createUser([], 'user4', FALSE, ['roles' => [$this->role2]]);
7466
$this->createUser([], 'user5', FALSE, ['roles' => [$this->role1, $this->role2]]);
7567

76-
$this->drupalLogin($this->rootUser);
68+
$this->drupalLogin($this->createUser(['administer views']));
7769
}
7870

7971
/**

modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ class DisplayPageWebTest extends ViewTestBase {
3131
*/
3232
protected static $modules = ['block', 'views_ui'];
3333

34-
/**
35-
* {@inheritdoc}
36-
*
37-
* @todo Remove and fix test to not rely on super user.
38-
* @see https://www.drupal.org/project/drupal/issues/3437620
39-
*/
40-
protected bool $usesSuperUserAccessPolicy = TRUE;
41-
4234
/**
4335
* {@inheritdoc}
4436
*/
@@ -151,7 +143,7 @@ public function testTitleOutput() {
151143
* Tests the views page path functionality.
152144
*/
153145
public function testPagePaths() {
154-
$this->drupalLogin($this->rootUser);
146+
$this->drupalLogin($this->createUser(['administer views']));
155147
$this->assertPagePath('0');
156148
$this->assertPagePath('9999');
157149
$this->assertPagePath('');

modules/views/tests/src/Functional/UserBatchActionTest.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ class UserBatchActionTest extends BrowserTestBase {
2525
'views',
2626
];
2727

28-
/**
29-
* {@inheritdoc}
30-
*
31-
* @todo Remove and fix test to not rely on super user.
32-
* @see https://www.drupal.org/project/drupal/issues/3437620
33-
*/
34-
protected bool $usesSuperUserAccessPolicy = TRUE;
3528

3629
/**
3730
* {@inheritdoc}
@@ -45,7 +38,7 @@ public function testUserAction() {
4538
$themes = ['stark', 'olivero', 'claro'];
4639
$this->container->get('theme_installer')->install($themes);
4740

48-
$this->drupalLogin($this->rootUser);
41+
$this->drupalLogin($this->createUser(['administer users']));
4942

5043
foreach ($themes as $theme) {
5144
$this->config('system.theme')->set('default', $theme)->save();

modules/views/tests/src/Kernel/Handler/FieldFieldTest.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Drupal\entity_test\Entity\EntityTestRev;
1010
use Drupal\field\Entity\FieldConfig;
1111
use Drupal\field\Entity\FieldStorageConfig;
12+
use Drupal\Tests\user\Traits\UserCreationTrait;
1213
use Drupal\user\Entity\User;
1314
use Drupal\views\Plugin\views\field\EntityField;
1415
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
@@ -24,6 +25,8 @@
2425
*/
2526
class FieldFieldTest extends ViewsKernelTestBase {
2627

28+
use UserCreationTrait;
29+
2730
/**
2831
* {@inheritdoc}
2932
*/
@@ -35,14 +38,6 @@ class FieldFieldTest extends ViewsKernelTestBase {
3538
'views_entity_test',
3639
];
3740

38-
/**
39-
* {@inheritdoc}
40-
*
41-
* @todo Remove and fix test to not rely on super user.
42-
* @see https://www.drupal.org/project/drupal/issues/3437620
43-
*/
44-
protected bool $usesSuperUserAccessPolicy = TRUE;
45-
4641
/**
4742
* {@inheritdoc}
4843
*/
@@ -90,8 +85,7 @@ protected function setUp($import_test_views = TRUE): void {
9085
ViewTestData::createTestViews(static::class, ['views_test_config']);
9186

9287
// Bypass any field access.
93-
$this->adminUser = User::create(['name' => $this->randomString()]);
94-
$this->adminUser->save();
88+
$this->adminUser = $this->createUser(['administer users'], $this->randomString());
9589
$this->container->get('current_user')->setAccount($this->adminUser);
9690

9791
$this->testUsers = [];

modules/views/tests/src/Kernel/Plugin/RssFieldsTest.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ class RssFieldsTest extends ViewsKernelTestBase {
2525
*/
2626
protected static $modules = ['node', 'field', 'text', 'filter'];
2727

28-
/**
29-
* {@inheritdoc}
30-
*
31-
* @todo Remove and fix test to not rely on super user.
32-
* @see https://www.drupal.org/project/drupal/issues/3437620
33-
*/
34-
protected bool $usesSuperUserAccessPolicy = TRUE;
35-
3628
/**
3729
* {@inheritdoc}
3830
*/
@@ -58,9 +50,7 @@ protected function setUp($import_test_views = TRUE): void {
5850
* subdirectory.
5951
*/
6052
public function testRssFields() {
61-
// Set up the current user as uid 1 so the test doesn't need to deal with
62-
// permission.
63-
$this->setUpCurrentUser(['uid' => 1]);
53+
$this->setUpCurrentUser([], ['access content']);
6454

6555
$date = '1975-05-18';
6656

0 commit comments

Comments
 (0)