use MediaWiki\Linker\LinkTarget;
class NamespaceInfoTest extends MediaWikiTestCase {
+ use TestAllServiceOptionsUsed;
+
/**********************************************************************************************
* Shared code
* %{
'ExtraNamespaces' => [],
'ExtraSignatureNamespaces' => [],
'NamespaceContentModels' => [],
- 'NamespaceProtection' => [],
'NamespacesWithSubpages' => [
NS_TALK => true,
NS_USER => true,
NS_USER_TALK => true,
],
'NonincludableNamespaces' => [],
- 'RestrictionLevels' => [ '', 'autoconfirmed', 'sysop' ],
];
private function newObj( array $options = [] ) : NamespaceInfo {
- return new NamespaceInfo( new ServiceOptions( NamespaceInfo::$constructorOptions,
- $options, self::$defaultOptions ) );
+ return new NamespaceInfo( new LoggedServiceOptions(
+ self::$serviceOptionsAccessLog,
+ NamespaceInfo::$constructorOptions,
+ $options, self::$defaultOptions
+ ) );
}
// %} End shared code
*/
/**
- * This mock user can only have isAllowed() called on it.
- *
- * @param array $groups Groups for the mock user to have
- * @return User
- */
- private function getMockUser( array $groups = [] ) : User {
- $groups[] = '*';
-
- $mock = $this->createMock( User::class );
- $mock->method( 'isAllowed' )->will( $this->returnCallback(
- function ( $action ) use ( $groups ) {
- global $wgGroupPermissions, $wgRevokePermissions;
- if ( $action == '' ) {
- return true;
- }
- foreach ( $wgRevokePermissions as $group => $rights ) {
- if ( !in_array( $group, $groups ) ) {
- continue;
- }
- if ( isset( $rights[$action] ) && $rights[$action] ) {
- return false;
- }
- }
- foreach ( $wgGroupPermissions as $group => $rights ) {
- if ( !in_array( $group, $groups ) ) {
- continue;
- }
- if ( isset( $rights[$action] ) && $rights[$action] ) {
- return true;
- }
- }
- return false;
- }
- ) );
- $mock->expects( $this->never() )->method( $this->anythingBut( 'isAllowed' ) );
- return $mock;
- }
-
- /**
+ * TODO: This is superceeded by PermissionManagerTest::testGetNamespaceRestrictionLevels
+ * Remove when deprecated method is removed.
* @dataProvider provideGetRestrictionLevels
- * @covers NamespaceInfo::getRestrictionLevels
+ * @covers NamespaceInfo::getRestrictionLevels
*
* @param array $expected
* @param int $ns
- * @param User|null $user
+ * @param array|null $groups
+ * @throws MWException
*/
- public function testGetRestrictionLevels( array $expected, $ns, User $user = null ) {
+ public function testGetRestrictionLevels( array $expected, $ns, array $groups = null ) {
$this->setMwGlobals( [
'wgGroupPermissions' => [
'*' => [ 'edit' => true ],
'wgRevokePermissions' => [
'noeditsemiprotected' => [ 'editsemiprotected' => true ],
],
- ] );
- $obj = $this->newObj( [
- 'NamespaceProtection' => [
+ 'wgNamespaceProtection' => [
NS_MAIN => 'autoconfirmed',
NS_USER => 'sysop',
101 => [ 'editsemiprotected', 'privileged' ],
],
+ 'wgRestrictionLevels' => [ '', 'autoconfirmed', 'sysop' ],
+ 'wgAutopromote' => []
] );
+ $obj = $this->newObj();
+ $user = is_null( $groups ) ? null : $this->getTestUser( $groups )->getUser();
$this->assertSame( $expected, $obj->getRestrictionLevels( $ns, $user ) );
}
'Restricted to autoconfirmed' => [ [ '', 'sysop' ], NS_MAIN ],
'Restricted to sysop' => [ [ '' ], NS_USER ],
'Restricted to someone in two groups' => [ [ '', 'sysop' ], 101 ],
- 'No special permissions' => [ [ '' ], NS_TALK, $this->getMockUser() ],
+ 'No special permissions' => [ [ '' ], NS_TALK, [] ],
'autoconfirmed' => [
[ '', 'autoconfirmed' ],
NS_TALK,
- $this->getMockUser( [ 'autoconfirmed' ] )
+ [ 'autoconfirmed' ]
],
'autoconfirmed revoked' => [
[ '' ],
NS_TALK,
- $this->getMockUser( [ 'autoconfirmed', 'noeditsemiprotected' ] )
+ [ 'autoconfirmed', 'noeditsemiprotected' ]
],
'sysop' => [
[ '', 'autoconfirmed', 'sysop' ],
NS_TALK,
- $this->getMockUser( [ 'sysop' ] )
+ [ 'sysop' ]
],
'sysop with autoconfirmed revoked (a bit silly)' => [
[ '', 'sysop' ],
NS_TALK,
- $this->getMockUser( [ 'sysop', 'noeditsemiprotected' ] )
+ [ 'sysop', 'noeditsemiprotected' ]
],
];
}
// %} End restriction levels
+
+ /**
+ * @coversNothing
+ */
+ public function testAllServiceOptionsUsed() {
+ $this->assertAllServiceOptionsUsed();
+ }
}
/**