Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4088866
ApiGlobalPreferencesTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ApiGlobalPreferencesTest.php
View Options
<?php
namespace
GlobalPreferences\Tests\Integration
;
use
Generator
;
use
GlobalPreferences\Storage
;
use
MediaWiki\MainConfigNames
;
use
MediaWiki\Tests\Api\ApiTestCase
;
use
MediaWiki\Title\Title
;
/**
* @group GlobalPreferences
* @group API
* @group Database
* @covers \GlobalPreferences\ApiGlobalPreferences
*/
class
ApiGlobalPreferencesTest
extends
ApiTestCase
{
/**
* @inheritDoc
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
overrideConfigValues
(
[
MainConfigNames
::
CentralIdLookupProvider
=>
'local'
,
'GlobalPreferencesDB'
=>
false
,
]
);
}
/**
* @dataProvider provideExecute
*/
public
function
testExecute
(
array
$params
,
array
$initialPrefs
,
array
$expectedPrefs
):
void
{
$performer
=
$this
->
getTestUser
()->
getAuthority
();
$params
=
array_merge
(
[
'action'
=>
'globalpreferences'
,
'format'
=>
'json'
,
],
$params
);
// Necessary despite the API request not actually needing a title.
$this
->
apiContext
->
setTitle
(
Title
::
makeTitle
(
0
,
'GlobalPreferences'
)
);
// Save the initial preferences to the database.
$storage
=
new
Storage
(
$performer
->
getUser
()->
getId
()
);
$storage
->
save
(
$initialPrefs
,
array_keys
(
$initialPrefs
)
);
// Verify that the initial preferences are as expected.
$this
->
assertArrayEquals
(
$initialPrefs
,
$storage
->
load
(
true
)
);
// Make the API request, then check that the preferences have been updated.
$this
->
doApiRequestWithToken
(
$params
,
null
,
$performer
);
$this
->
assertArrayEquals
(
$expectedPrefs
,
$storage
->
load
(
true
)
);
}
public
static
function
provideExecute
():
Generator
{
yield
'set userjs'
=>
[
[
'change'
=>
'userjs-foo=bar'
],
[],
[
'userjs-foo'
=>
'bar'
]
];
yield
'unset userjs'
=>
[
[
'change'
=>
'userjs-foo'
],
[
'userjs-foo'
=>
'bar'
],
[]
];
yield
'set multiple'
=>
[
[
'change'
=>
'userjs-foo=bar|userjs-baz=qux'
],
[],
[
'userjs-foo'
=>
'bar'
,
'userjs-baz'
=>
'qux'
]
];
yield
'set and unset multiple'
=>
[
[
'change'
=>
'userjs-foo=bar|userjs-baz'
],
[
'userjs-baz'
=>
'qux'
],
[
'userjs-foo'
=>
'bar'
]
];
yield
'reset all'
=>
[
[
'reset'
=>
'1'
],
[
'userjs-foo'
=>
'bar'
,
'examplepref'
=>
'bar'
],
[]
];
yield
'reset kind userjs'
=>
[
[
'reset'
=>
'1'
,
'resetkinds'
=>
'userjs'
],
[
'userjs-foo'
=>
'bar'
,
'examplepref'
=>
'baz'
],
[
'examplepref'
=>
'baz'
]
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 18 2026, 10:15 (6 w, 12 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
7b/f4/f1dfe820b9c37dfc6e6818e84c6b
Default Alt Text
ApiGlobalPreferencesTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment