20 private static $Success = [
'options' =>
'success' ];
26 ->disableOriginalConstructor()
30 $this->mUserMock->expects( $this->
any() )
31 ->method(
'getEffectiveGroups' )->will( $this->
returnValue( [
'*',
'user' ] ) );
32 $this->mUserMock->expects( $this->
any() )
33 ->method(
'isAllowedAny' )->will( $this->
returnValue(
true ) );
36 $this->mUserMock->expects( $this->
any() )
37 ->method(
'getOptionKinds' )->will( $this->
returnCallback( [ $this,
'getOptionKinds' ] ) );
40 $this->mUserMock->expects( $this->
any() )
41 ->method(
'getInstanceForUpdate' )->will( $this->
returnValue( $this->mUserMock ) );
44 $this->mUserMock->method(
'getOptions' )
49 $this->mContext->getContext()->setTitle( Title::newFromText(
'Test' ) );
50 $this->mContext->setUser( $this->mUserMock );
52 $main =
new ApiMain( $this->mContext );
57 $this->mTested =
new ApiOptions( $main,
'options' );
61 [ $this,
'hookGetPreferences' ]
65 'testradio' =>
'option1',
74 foreach ( [
'name',
'willBeNull',
'willBeEmpty',
'willBeHappy' ] as $k ) {
78 'label' =>
"\u{00A0}",
82 $preferences[
'testmultiselect'] = [
83 'type' =>
'multiselect',
86 '<span dir="auto">Some HTML here for option 1</span>' =>
'opt1',
87 '<span dir="auto">Some HTML here for option 2</span>' =>
'opt2',
88 '<span dir="auto">Some HTML here for option 3</span>' =>
'opt3',
89 '<span dir="auto">Some HTML here for option 4</span>' =>
'opt4',
93 'label' =>
"\u{00A0}",
94 'prefix' =>
'testmultiselect-',
98 $preferences[
'testradio'] = [
100 'options' => [
'Option 1' =>
'option1',
'Option 2' =>
'option2' ],
114 'name' =>
'registered',
115 'willBeNull' =>
'registered',
116 'willBeEmpty' =>
'registered',
117 'willBeHappy' =>
'registered',
118 'testradio' =>
'registered',
119 'testmultiselect-opt1' =>
'registered-multiselect',
120 'testmultiselect-opt2' =>
'registered-multiselect',
121 'testmultiselect-opt3' =>
'registered-multiselect',
122 'testmultiselect-opt4' =>
'registered-multiselect',
123 'special' =>
'special',
132 if (
isset( $kinds[$key] ) ) {
133 $mapping[$key] = $kinds[$key];
135 $mapping[$key] =
'userjs';
137 $mapping[$key] =
'unused';
148 'optionname' =>
null,
149 'optionvalue' =>
null,
157 $this->mTested->execute();
159 return $this->mTested->getResult()->getResultData(
null, [
'Strip' =>
'all' ] );
172 $this->mUserMock->expects( $this->
once() )
184 $this->fail(
"ApiUsageException was not thrown" );
196 $this->fail(
"ApiUsageException was not thrown" );
200 $this->mUserMock->expects( $this->never() )
201 ->method(
'resetOptions' );
203 $this->mUserMock->expects( $this->never() )
204 ->method(
'setOption' );
206 $this->mUserMock->expects( $this->never() )
207 ->method(
'saveSettings' );
217 $this->fail(
"ApiUsageException was not thrown" );
221 $this->mUserMock->expects( $this->
once() )
222 ->method(
'resetOptions' )
223 ->with( $this->
equalTo( [
'all' ] ) );
225 $this->mUserMock->expects( $this->never() )
226 ->method(
'setOption' );
228 $this->mUserMock->expects( $this->
once() )
229 ->method(
'saveSettings' );
239 $this->mUserMock->expects( $this->
once() )
240 ->method(
'resetOptions' )
241 ->with( $this->
equalTo( [
'registered' ] ) );
243 $this->mUserMock->expects( $this->never() )
244 ->method(
'setOption' );
246 $this->mUserMock->expects( $this->
once() )
247 ->method(
'saveSettings' );
257 $this->mUserMock->expects( $this->
once() )
258 ->method(
'resetOptions' );
260 $this->mUserMock->expects( $this->
exactly( 2 ) )
261 ->method(
'setOption' )
267 $this->mUserMock->expects( $this->
once() )
268 ->method(
'saveSettings' );
272 'change' =>
'willBeHappy=Happy',
273 'optionname' =>
'name',
274 'optionvalue' =>
'value'
291 $this->mUserMock->expects( $this->never() )
292 ->method(
'resetOptions' );
294 $this->mUserMock->expects( $this->
exactly( count( $setOptions ) ) )
295 ->method(
'setOption' )
296 ->withConsecutive( ...$setOptions );
299 $this->mUserMock->expects( $this->
once() )
300 ->method(
'saveSettings' );
302 $this->mUserMock->expects( $this->never() )
303 ->method(
'saveSettings' );
318 [
'change' =>
'userjs-option=1' ],
319 [ [
'userjs-option',
'1' ] ],
321 'Setting userjs options',
324 [
'change' =>
'willBeNull|willBeEmpty=|willBeHappy=Happy' ],
326 [
'willBeNull',
null ],
327 [
'willBeEmpty',
'' ],
328 [
'willBeHappy',
'Happy' ],
331 'Basic option setting',
334 [
'change' =>
'testradio=option2' ],
335 [ [
'testradio',
'option2' ] ],
337 'Changing radio options',
340 [
'change' =>
'testradio' ],
341 [ [
'testradio',
null ] ],
343 'Resetting radio options',
346 [
'change' =>
'unknownOption=1' ],
349 'options' =>
'success',
352 'warnings' =>
"Validation error for \"unknownOption\": not a valid preference."
356 'Unrecognized options should be rejected',
359 [
'change' =>
'special=1' ],
362 'options' =>
'success',
365 'warnings' =>
"Validation error for \"special\": cannot be set by this module."
369 'Refuse setting special options',
373 'change' =>
'testmultiselect-opt1=1|testmultiselect-opt2|'
374 .
'testmultiselect-opt3=|testmultiselect-opt4=0'
377 [
'testmultiselect-opt1',
true ],
378 [
'testmultiselect-opt2',
null ],
379 [
'testmultiselect-opt3',
false ],
380 [
'testmultiselect-opt4',
false ],
383 'Setting multiselect options',
386 [
'optionname' =>
'name',
'optionvalue' =>
'value' ],
387 [ [
'name',
'value' ] ],
389 'Setting options via optionname/optionvalue'
392 [
'optionname' =>
'name' ],
393 [ [
'name',
null ] ],
395 'Resetting options via optionname without optionvalue',
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
This is the main API class, used for both external and internal processing.
testNoToken()
ApiUsageException.
testOptionManupulation(array $params, array $setOptions, array $result=null, $message='')
provideOptionManupulation
getOptionKinds(IContextSource $context, $options=null)
getSampleRequest( $custom=[])
DerivativeContext $mContext
hookGetPreferences( $user, &$preferences)
PHPUnit_Framework_MockObject_MockObject $mUserMock
provideOptionManupulation()
API module that facilitates the changing of user's preferences.
static apiExceptionHasCode(ApiUsageException $ex, $code)
Exception used to abort API execution with an error.
An IContextSource implementation which will inherit context from another source but allow individual ...
WebRequest clone which takes values from a provided array.
Group all the pieces relevant to the context of a request into one instance.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
this hook is for auditing only $response
processing should stop and the error should be shown to the user * false
returning false will NOT prevent logging $e
Interface for objects which can provide a MediaWiki context on request.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))