Redefine services before ::newSpecialPage in FormSpecialPageTestCase

Why:
* The FormSpecialPageTestCase is a base test class to test classes
  that extend FormSpecialPage.
* This class defines two common tests that verify permission checks
  for the special page by redefining the necessary services after
  a call to ::newSpecialPage
* However, if the FormSpecialPage instance has one of the redefined
  services as a dependency, then it will not get the redefined
  service and therefore may fail tests, for example for the CheckUser
  extnesion.
* Moving the redefinitions of the services to above the call to
  ::newSpecialPage fixes this issue.

What:
* Move the call to ::newSpecialPage in the two tests to below any
  redefinition of a service.

Bug: T362569
Change-Id: I610bcf4c98f2692510280f4cafc8f4934e94d947
This commit is contained in:
Dreamy Jazz 2024-04-15 19:28:20 +01:00
parent e5f263423b
commit a83470fb4f

View file

@ -44,9 +44,6 @@ abstract class FormSpecialPageTestCase extends SpecialPageTestBase {
* @covers \MediaWiki\SpecialPage\FormSpecialPage::checkExecutePermissions
*/
public function testCheckExecutePermissionsSitewideBlock() {
$special = $this->newSpecialPage();
$checkExecutePermissions = $this->getMethod( $special, 'checkExecutePermissions' );
$blockErrorFormatter = $this->createMock( BlockErrorFormatter::class );
$blockErrorFormatter->method( 'getMessage' )
->willReturn( $this->getMockMessage( 'test' ) );
@ -57,6 +54,9 @@ abstract class FormSpecialPageTestCase extends SpecialPageTestBase {
$permissionManager->method( 'userHasRight' )->willReturn( true );
$this->setService( 'PermissionManager', $permissionManager );
$special = $this->newSpecialPage();
$checkExecutePermissions = $this->getMethod( $special, 'checkExecutePermissions' );
$user = $this->getMockBuilder( User::class )
->onlyMethods( [ 'getBlock', 'getWikiId' ] )
->getMock();
@ -75,9 +75,6 @@ abstract class FormSpecialPageTestCase extends SpecialPageTestBase {
* @covers \MediaWiki\SpecialPage\FormSpecialPage::checkExecutePermissions
*/
public function testCheckExecutePermissionsPartialBlock() {
$special = $this->newSpecialPage();
$checkExecutePermissions = $this->getMethod( $special, 'checkExecutePermissions' );
$blockErrorFormatter = $this->createMock( BlockErrorFormatter::class );
$blockErrorFormatter->method( 'getMessage' )
->willReturn( $this->getMockMessage( 'test' ) );
@ -92,6 +89,9 @@ abstract class FormSpecialPageTestCase extends SpecialPageTestBase {
$permissionManager->method( 'userHasRight' )->willReturn( true );
$this->setService( 'PermissionManager', $permissionManager );
$special = $this->newSpecialPage();
$checkExecutePermissions = $this->getMethod( $special, 'checkExecutePermissions' );
$user = $this->getMockBuilder( User::class )
->onlyMethods( [ 'getBlock', 'getWikiId' ] )
->getMock();