MediaWiki  1.33.0
FormSpecialPageTestCase.php
Go to the documentation of this file.
1 <?php
23 
28  $special = $this->newSpecialPage();
29  $checkExecutePermissions = $this->getMethod( $special, 'checkExecutePermissions' );
30 
31  $user = clone $this->getTestUser()->getUser();
32  $user->mBlockedby = $user->getName();
33  $user->mBlock = new Block( [
34  'address' => '127.0.8.1',
35  'by' => $user->getId(),
36  'reason' => 'sitewide block',
37  'timestamp' => time(),
38  'sitewide' => true,
39  'expiry' => 10,
40  ] );
41 
42  $this->expectException( UserBlockedError::class );
43  $checkExecutePermissions( $user );
44  }
45 
50  $special = $this->newSpecialPage();
51  $checkExecutePermissions = $this->getMethod( $special, 'checkExecutePermissions' );
52 
53  $user = clone $this->getTestUser()->getUser();
54  $user->mBlockedby = $user->getName();
55  $user->mBlock = new Block( [
56  'address' => '127.0.8.1',
57  'by' => $user->getId(),
58  'reason' => 'partial block',
59  'timestamp' => time(),
60  'sitewide' => false,
61  'expiry' => 10,
62  ] );
63 
64  $this->assertNull( $checkExecutePermissions( $user ) );
65  }
66 
74  protected function getMethod( $obj, $name ) {
75  $method = new ReflectionMethod( $obj, $name );
76  $method->setAccessible( true );
77  return $method->getClosure( $obj );
78  }
79 }
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:180
FormSpecialPageTestCase
Factory for handling the special page list and generating SpecialPage objects.
Definition: FormSpecialPageTestCase.php:22
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
SpecialPageTestBase
Base class for testing special pages.
Definition: SpecialPageTestBase.php:14
FormSpecialPageTestCase\testCheckExecutePermissionsPartialBlock
testCheckExecutePermissionsPartialBlock()
FormSpecialPage::checkExecutePermissions.
Definition: FormSpecialPageTestCase.php:49
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
FormSpecialPageTestCase\getMethod
getMethod( $obj, $name)
Get a protected/private method.
Definition: FormSpecialPageTestCase.php:74
SpecialPageTestBase\newSpecialPage
newSpecialPage()
Returns a new instance of the special page under test.
Block
Definition: Block.php:31
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
FormSpecialPageTestCase\testCheckExecutePermissionsSitewideBlock
testCheckExecutePermissionsSitewideBlock()
FormSpecialPage::checkExecutePermissions.
Definition: FormSpecialPageTestCase.php:27