Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4138161
ApiQueryGlobalPreferencesTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
ApiQueryGlobalPreferencesTest.php
View Options
<?php
namespace
GlobalPreferences\Tests\Integration
;
use
GlobalPreferences\ApiQueryGlobalPreferences
;
use
GlobalPreferences\GlobalPreferencesFactory
;
use
MediaWiki\Api\ApiMain
;
use
MediaWiki\Context\DerivativeContext
;
use
MediaWiki\Context\RequestContext
;
use
MediaWiki\Request\FauxRequest
;
use
MediaWiki\User\Options\UserOptionsLookup
;
use
MediaWiki\User\User
;
use
MediaWikiIntegrationTestCase
;
/**
* @group GlobalPreferences
*/
class
ApiQueryGlobalPreferencesTest
extends
MediaWikiIntegrationTestCase
{
/**
* @param array $requestData
* @param array $globalPrefs
* @param array $localPrefs
* @return ApiQueryGlobalPreferences
*/
private
function
makeApi
(
array
$requestData
,
array
$globalPrefs
,
array
$localPrefs
)
{
$user
=
$this
->
createMock
(
User
::
class
);
$user
->
method
(
'isNamed'
)
->
willReturn
(
true
);
$request
=
new
FauxRequest
(
$requestData
);
$context
=
new
DerivativeContext
(
RequestContext
::
getMain
()
);
/** @var User $user */
$context
->
setUser
(
$user
);
$context
->
setRequest
(
$request
);
$main
=
new
ApiMain
(
$context
);
$query
=
$main
->
getModuleManager
()->
getModule
(
'query'
);
$factory
=
$this
->
getMockBuilder
(
GlobalPreferencesFactory
::
class
)
->
disableOriginalConstructor
()
->
onlyMethods
(
[
'isUserGlobalized'
,
'getGlobalPreferencesValues'
]
)
->
getMock
();
$factory
->
method
(
'getGlobalPreferencesValues'
)
->
willReturn
(
$globalPrefs
);
$factory
->
method
(
'isUserGlobalized'
)
->
willReturn
(
true
);
$userOptionsLookup
=
$this
->
createMock
(
UserOptionsLookup
::
class
);
$userOptionsLookup
->
method
(
'getOptions'
)
->
willReturn
(
$localPrefs
);
/** @var GlobalPreferencesFactory $factory */
return
new
ApiQueryGlobalPreferences
(
$query
,
'globalpreferences'
,
$factory
,
$userOptionsLookup
);
}
/**
* @covers \GlobalPreferences\ApiQueryGlobalPreferences::execute()
*
* @dataProvider provideApi
*/
public
function
testApi
(
array
$requestData
,
array
$globalPrefs
,
array
$localPrefs
,
array
$expected
)
{
$requestData
[
'action'
]
=
'query'
;
$requestData
[
'meta'
]
=
'globalpreferences'
;
/** @var ApiQueryGlobalPreferences $api */
$api
=
$this
->
makeApi
(
$requestData
,
$globalPrefs
,
$localPrefs
);
$api
->
execute
();
$result
=
$api
->
getResult
()->
getResultData
()[
'query'
][
'globalpreferences'
];
self
::
assertEquals
(
$expected
,
self
::
filterApiResult
(
$result
)
);
}
public
static
function
provideApi
()
{
return
[
[
[],
[],
[],
[
'preferences'
=>
[],
'localoverrides'
=>
[],
],
],
[
[
'gprprop'
=>
''
],
[
'skin'
=>
'vector'
],
[
'skin'
=>
'monobook'
],
[],
],
[
[],
[
'skin'
=>
'vector'
],
[
'skin'
=>
'monobook'
,
'skin-local-exception'
=>
1
],
[
'preferences'
=>
[
'skin'
=>
'vector'
],
'localoverrides'
=>
[
'skin'
=>
'monobook'
],
],
],
[
[
'gprprop'
=>
'preferences|localoverrides'
],
[
'skin'
=>
'vector'
],
[
'skin'
=>
'monobook'
,
'skin-local-exception'
=>
1
],
[
'preferences'
=>
[
'skin'
=>
'vector'
],
'localoverrides'
=>
[
'skin'
=>
'monobook'
],
],
],
[
[
'gprprop'
=>
'preferences'
],
[
'skin'
=>
'vector'
],
[
'skin'
=>
'monobook'
,
'skin-local-exception'
=>
1
],
[
'preferences'
=>
[
'skin'
=>
'vector'
],
],
],
[
[
'gprprop'
=>
'localoverrides'
],
[
'skin'
=>
'vector'
],
[
'skin'
=>
'monobook'
,
'skin-local-exception'
=>
1
],
[
'localoverrides'
=>
[
'skin'
=>
'monobook'
],
],
],
];
}
/**
* The internal representation of API results have metadata keys that we don't want to care about
*
* @param array $data
* @return array
*/
private
static
function
filterApiResult
(
array
$data
)
{
$result
=
[];
foreach
(
$data
as
$key
=>
$value
)
{
if
(
$key
[
0
]
===
'_'
)
{
continue
;
}
if
(
is_array
(
$value
)
)
{
$value
=
self
::
filterApiResult
(
$value
);
}
$result
[
$key
]
=
$value
;
}
return
$result
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 14:32 (3 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
79/88/7d876ba171a8c3ffcc32a73407c9
Default Alt Text
ApiQueryGlobalPreferencesTest.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment