/**
* @group Preferences
*/
-class DefaultPreferencesFactoryTest extends MediaWikiTestCase {
+class DefaultPreferencesFactoryTest extends \MediaWikiTestCase {
/** @var IContextSource */
protected $context;
* @covers MediaWiki\Preferences\DefaultPreferencesFactory::getForm()
*/
public function testGetForm() {
+ $this->setTemporaryHook( 'GetPreferences', null );
+
$testUser = $this->getTestUser();
$form = $this->getPreferencesFactory()->getForm( $testUser->getUser(), $this->context );
$this->assertInstanceOf( PreferencesFormLegacy::class, $form );
$this->assertEquals( $cssClass, $prefs['emailauthentication']['cssclass'] );
}
+ /**
+ * @covers MediaWiki\Preferences\DefaultPreferencesFactory::renderingPreferences()
+ */
+ public function testShowRollbackConfIsHiddenForUsersWithoutRollbackRights() {
+ $userMock = $this->getMockBuilder( User::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userMock->method( 'isAllowed' )
+ ->willReturn( false );
+ $userMock->method( 'getEffectiveGroups' )
+ ->willReturn( [] );
+ $userMock->method( 'getGroupMemberships' )
+ ->willReturn( [] );
+ $userMock->method( 'getOptions' )
+ ->willReturn( [ 'test' => 'yes' ] );
+
+ $prefs = $this->getPreferencesFactory()->getFormDescriptor( $userMock, $this->context );
+ $this->assertArrayNotHasKey( 'showrollbackconfirmation', $prefs );
+ }
+
+ /**
+ * @covers MediaWiki\Preferences\DefaultPreferencesFactory::renderingPreferences()
+ */
+ public function testShowRollbackConfIsShownForUsersWithRollbackRights() {
+ $userMock = $this->getMockBuilder( User::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userMock->method( 'isAllowed' )
+ ->willReturn( true );
+ $userMock->method( 'getEffectiveGroups' )
+ ->willReturn( [] );
+ $userMock->method( 'getGroupMemberships' )
+ ->willReturn( [] );
+ $userMock->method( 'getOptions' )
+ ->willReturn( [ 'test' => 'yes' ] );
+
+ $prefs = $this->getPreferencesFactory()->getFormDescriptor( $userMock, $this->context );
+ $this->assertArrayHasKey( 'showrollbackconfirmation', $prefs );
+ $this->assertEquals(
+ 'rendering/advancedrendering',
+ $prefs['showrollbackconfirmation']['section']
+ );
+ }
+
public function emailAuthenticationProvider() {
$userNoEmail = new User;
$userEmailUnauthed = new User;