Fix Comments tests that rely on UID1's super user behavior

Created on 10 April 2024, 8 months ago
Updated 30 April 2024, 8 months ago

Problem/Motivation

In ๐Ÿ“Œ Add a container parameter that can remove the special behavior of UID#1 Fixed an approach was taken where we can simply flag tests that are failing if we turn off user 1's super user powers, so that they can be taken care of in a followup. This issue is to collect all of these followups.

The goal is to have no tests in Drupal core that rely on UID1's special privileges so that we:

  1. Know these tests are correctly assigning the necessary permissions to run
  2. Can turn off the super user access policy in D11, knowing it won't break core
  3. Can remove the super user access policy in D12, providing an admin account recovery tool to replace it

Steps to reproduce

Go into any of the tests flagged with:

  /**
   * {@inheritdoc}
   *
   * @todo Remove and fix test to not rely on super user.
   * @see https://www.drupal.org/project/drupal/issues/3437620
   */

And:

  1. Remove the code below that sets the usesSuperUserAccessPolicy to TRUE.
  2. Run the test to see which test methods are failing

Proposed resolution

Assign the right permissions to make the test go green without the super user access policy. Those few tests that specifically test said policy can obviously stay, but will be removed along with the policy in D12.

Remaining tasks

  • core/modules/comment/tests/src/
    • Functional/CommentStatisticsTest.php
๐Ÿ“Œ Task
Status

Fixed

Version

11.0 ๐Ÿ”ฅ

Component
Commentย  โ†’

Last updated 8 days ago

Created by

๐Ÿ‡ฌ๐Ÿ‡ทGreece vensires

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @vensires
  • ๐Ÿ‡ฌ๐Ÿ‡ทGreece vensires
  • First commit to issue fork.
  • Merge request !7423Issue #3439830: Fix comments tests โ†’ (Open) created by thebumik
  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฒ๐Ÿ‡ฉMoldova thebumik

    Would greatly appreciate it if someone could review my pull request for this. Any feedback would be invaluable!

  • Pipeline finished with Failed
    8 months ago
    Total: 1139s
    #143074
  • Pipeline finished with Failed
    8 months ago
    Total: 961s
    #143254
  • Pipeline finished with Success
    8 months ago
    Total: 992s
    #143273
  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States nicxvan

    Webuser2 has a duplicate permission, can you clean that up please?

  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฒ๐Ÿ‡ฉMoldova thebumik
  • Pipeline finished with Success
    8 months ago
    Total: 986s
    #143505
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium kristiaanvandeneynde Antwerp, Belgium

    Small nitpick: I would keep the order of the user properties like it was. Now you have $webUser2 first with a comment calling it "a secondary user" before you even configured your primary user. It's a bit confusing in this order.

    Suggestion: $adminUser above $webUser2.

  • Pipeline finished with Success
    8 months ago
    Total: 987s
    #143751
  • Status changed to RTBC 8 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Seems feedback has been addressed and think these permissions should be good

  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    Left a minor comment on the MR, fine to self RTBC once fixed

  • Pipeline finished with Failed
    8 months ago
    #144680
  • Pipeline finished with Failed
    8 months ago
    #144688
  • Pipeline finished with Failed
    8 months ago
    #144701
  • Status changed to RTBC 8 months ago
  • ๐Ÿ‡ฒ๐Ÿ‡ฉMoldova thebumik

    Applied required changes. Should be fine now.

  • Pipeline finished with Success
    8 months ago
    #144704
  • First commit to issue fork.
  • Pipeline finished with Canceled
    8 months ago
    Total: 32s
    #145200
  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexpott ๐Ÿ‡ช๐Ÿ‡บ๐ŸŒ

    I've added some comments to the MR... I don't think we should be overwriting the adminUser with a new user.

  • Pipeline finished with Success
    8 months ago
    Total: 1081s
    #145201
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia pradhumanjainOSL

    pradhumanjain2311 โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Failed
    8 months ago
    Total: 178s
    #145617
  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฒ๐Ÿ‡ฉMoldova thebumik

    MR comments were addressed.

  • Pipeline finished with Success
    8 months ago
    Total: 988s
    #147141
  • Status changed to RTBC 8 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Not a huge fan of "more_admin_role" but it's a test so not a big deal to me.

  • Status changed to Fixed 8 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexpott ๐Ÿ‡ช๐Ÿ‡บ๐ŸŒ

    Committed and pushed 2b0321c170 to 11.x and d35edb34b2 to 10.3.x. Thanks!

    Made the following changes on commit

    diff --git a/core/modules/comment/tests/src/Functional/CommentStatisticsTest.php b/core/modules/comment/tests/src/Functional/CommentStatisticsTest.php
    index a8d5909e68..9a309f16e0 100644
    --- a/core/modules/comment/tests/src/Functional/CommentStatisticsTest.php
    +++ b/core/modules/comment/tests/src/Functional/CommentStatisticsTest.php
    @@ -7,7 +7,6 @@
     use Drupal\comment\CommentInterface;
     use Drupal\comment\CommentManagerInterface;
     use Drupal\comment\Entity\Comment;
    -use Drupal\user\UserInterface;
     
     /**
      * Tests comment statistics on nodes.
    @@ -21,7 +20,7 @@ class CommentStatisticsTest extends CommentTestBase {
        *
        * @var \Drupal\user\UserInterface
        */
    -  protected UserInterface $webUser2;
    +  protected $webUser2;
     
       /**
        * {@inheritdoc}
    @@ -35,12 +34,11 @@ protected function setUp(): void {
         parent::setUp();
     
         // Add more permissions the admin user.
    -    $more_admin_role = $this->drupalCreateRole([
    +    $this->adminUser->addRole($this->drupalCreateRole([
           'administer permissions',
           'access administration pages',
           'administer site configuration',
    -    ]);
    -    $this->adminUser->addRole($more_admin_role)->save();
    +    ]))->save();
         // Create a second user to post comments.
         $this->webUser2 = $this->drupalCreateUser([
           'post comments',
    

    Removed the unnecessary variable and reverted out of scope changes.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024