6use Wikimedia\TestingAccessWrapper;
41 $this->context->setTitle( Title::newFromText( self::class ) );
43 $services = MediaWikiServices::getInstance();
46 $this->config =
$services->getMainConfig();
57 AuthManager::singleton(),
58 MediaWikiServices::getInstance()->getLinkRenderer()
70 $this->assertInstanceOf( PreferencesFormLegacy::class, $form );
71 $this->assertCount( 5, $form->getPreferenceSections() );
82 $this->assertArrayHasKey(
'cssclass', $prefs[
'emailauthentication'] );
83 $this->assertEquals( $cssClass, $prefs[
'emailauthentication'][
'cssclass'] );
87 $userNoEmail =
new User;
88 $userEmailUnauthed =
new User;
89 $userEmailUnauthed->
setEmail(
'noauth@example.org' );
90 $userEmailAuthed =
new User;
91 $userEmailAuthed->
setEmail(
'noauth@example.org' );
92 $userEmailAuthed->setEmailAuthenticationTimestamp(
wfTimestamp() );
94 [ $userNoEmail,
'mw-email-none' ],
95 [ $userEmailUnauthed,
'mw-email-not-authenticated' ],
96 [ $userEmailAuthed,
'mw-email-authenticated' ],
121 $form = $this->getMockBuilder( PreferencesFormLegacy::class )
122 ->disableOriginalConstructor()
125 $userMock = $this->getMockBuilder( User::class )
126 ->disableOriginalConstructor()
128 $userMock->method(
'getOptions' )
129 ->willReturn( $oldOptions );
130 $userMock->method(
'isAllowedAny' )
131 ->willReturn(
true );
132 $userMock->method(
'isAllowed' )
133 ->willReturn(
true );
135 $userMock->expects( $this->exactly( 2 ) )
136 ->method(
'setOption' )
138 [ $this->equalTo(
'test' ), $this->equalTo( $newOptions[
'test' ] ) ],
139 [ $this->equalTo(
'option' ), $this->equalTo( $newOptions[
'option' ] ) ]
142 $form->expects( $this->
any() )
143 ->method(
'getModifiedUser' )
144 ->willReturn( $userMock );
146 $form->expects( $this->
any() )
147 ->method(
'getContext' )
148 ->willReturn( $this->context );
150 $form->expects( $this->
any() )
151 ->method(
'getConfig' )
152 ->willReturn( $configMock );
155 function ( $formData, $form, $user, &$result, $oldUserOptions )
156 use ( $newOptions, $oldOptions, $userMock ) {
157 $this->assertSame( $userMock, $user );
158 foreach ( $newOptions as $option =>
$value ) {
159 $this->assertSame(
$value, $formData[ $option ] );
161 foreach ( $oldOptions as $option =>
$value ) {
162 $this->assertSame(
$value, $oldUserOptions[ $option ] );
164 $this->assertEquals(
true, $result );
170 $factory->saveFormData( $newOptions, $form, [] );
180 $this->context->getRequest()->setVal(
'wprclimit',
' 0012 ' );
185 $this->assertEquals( 12, $user->getOption(
'rclimit' ) );
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
testGetForm()
MediaWiki\Preferences\DefaultPreferencesFactory::getForm()
testPreferencesFormPreSaveHookHasCorrectData()
Test that PreferencesFormPreSave hook has correct data:
emailAuthenticationProvider()
getPreferencesFactory()
Get a basic PreferencesFactory for testing with.
testEmailAuthentication( $user, $cssClass)
CSS classes for emailauthentication preference field when there's no email.
testIntvalFilter()
The rclimit preference should accept non-integer input and filter it to become an integer.
A Config instance which stores all settings as a member variable.
Internationalisation code.
Group all the pieces relevant to the context of a request into one instance.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
setEmail( $str)
Set the user's e-mail address.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Interface for configuration instances.
Interface for objects which can provide a MediaWiki context on request.