Page MenuHomePhabricator

Refactor the GlobalBlocking utility class into services
Closed, ResolvedPublic2 Estimated Story Points

Description

The GlobalBlocking utility class is used to provide several utility methods which are all static. This is useful for re-useability, but making these methods static is a problem for writing tests as there is no way to isolate, mock or stub static methods using PHPUnit. This means that:

  • All tests for methods that use utility methods that call the DB have to be database integration tests, even if the code that called the static method did not otherwise need to be an integration or DB integration test.
  • It is much harder to make the utility methods return unexpected or rare values and as such you need to set-up the DB or configuration values to make these conditions occur.
  • For complicated and time-intensive static methods (such as applying a global block), calling these methods from multiple places makes multiple tests take longer causing the tests to be overall slower.
  • DI cannot be used for the static methods, which means that tests have to override the service in MediaWikiServices and means many of the tests will have to be integration tests to allow access to the service container.

QA Results - Local

Event Timeline

Change 1005490 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/GlobalBlocking@master] Move remaining GlobalBlocking static methods to a service

https://gerrit.wikimedia.org/r/1005490

Change 1005490 merged by jenkins-bot:

[mediawiki/extensions/GlobalBlocking@master] Move remaining GlobalBlocking static methods to a service

https://gerrit.wikimedia.org/r/1005490

Suggested QA steps:

  1. Log into an account with the steward group
  2. Perform some testing global blocks so that Special:GlobalBlockList has entries, and note down the username you used to make the blocks
  3. While logged out load Special:GlobalBlockList
  4. Verify that no subtitle links to other special pages appear under the List of globally blocked IP addresses title
  5. Verify that the username you used to create the global blocks in step 2 appears as the performer of the blocks on the page
  6. Login into an account with the sysop group and load Special:GlobalBlockList.
  7. Verify that the subtitle links only show a link to Change local status for a global block as shown below:

image.png (114×956 px, 19 KB)

  1. Login into an account with the steward group and load Special:GlobalUnblock.
  2. Verify that the subtitle links contain a link to Special:GlobalBlockList and Special:GlobalBlock as shown below:

image.png (112×984 px, 18 KB)

  1. Login into an account with the steward and interface-admin group and load Special:GlobalBlock
  2. Verify that the subtitle links contain a link to Special:GlobalBlockList, Special:GlobalBlock, and a link with the name Edit block reasons as shown below:

image.png (130×960 px, 19 KB)

@Dreamy_Jazz All links showed up correctly for the specified user with the rights described as above. This will be moved to Done. Thanks for all your work and steps!

Status: ✅PASS
Environment: Local: 1.42.0-alpha (0ea2c78) 15:22, 22 February 2024
OS: macOS Sonoma 14.2.1
Browser: Chrome 121, Safari 14.3
Skins. Vector 2022
Device: MBA M2
Emulated Device:: n/a
Test Links:
Special:GlobalBlock
Special:GlobalBlockList
Special:GlobalUnblock

✅AC1: https://phabricator.wikimedia.org/T357385

GlobalBlocking Current- commit c3e8fc039847a80c66d157f46f3296c58bd26c68 Thu Feb 22 13:57:03 2024

Steps 1-5Step 6-7Steps 8-9Steps 10-11