Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4050728
JsonLocalizerTest.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
JsonLocalizerTest.php
View Options
<?php
namespace
MediaWiki\Tests\Rest
;
use
MediaWiki\Rest\JsonLocalizer
;
use
MediaWiki\Rest\ResponseFactory
;
use
MediaWikiUnitTestCase
;
use
Wikimedia\Message\MessageValue
;
/**
* @covers \MediaWiki\Rest\JsonLocalizer
*/
class
JsonLocalizerTest
extends
MediaWikiUnitTestCase
{
private
function
createMockResponseFactory
():
ResponseFactory
{
$responseFactory
=
$this
->
createNoOpMock
(
ResponseFactory
::
class
,
[
'getFormattedMessage'
]
);
$responseFactory
->
method
(
'getFormattedMessage'
)->
willReturn
(
'translated'
);
return
$responseFactory
;
}
public
static
function
providelocalizeJsonObjects
()
{
return
[
'empty object'
=>
[
[],
[]
],
'no matching pair'
=>
[
[
'properties'
=>
[
[
'my-property-name'
=>
[
'type'
=>
'integer'
]
],
],
],
[
'properties'
=>
[
[
'my-property-name'
=>
[
'type'
=>
'integer'
]
],
],
]
],
'nontranslatable pair'
=>
[
[
'description'
=>
'foo'
,
],
[
'description'
=>
'foo'
,
]
],
'translatable pair'
=>
[
[
'x-i18n-description'
=>
'foo'
,
],
[
'description'
=>
'translated'
,
]
],
'pair override'
=>
[
[
'x-i18n-description'
=>
'foo'
,
'description'
=>
'bar'
,
],
[
'description'
=>
'translated'
,
]
],
'nested translatable pair'
=>
[
[
'x-i18n-description'
=>
'foo'
,
'properties'
=>
[
[
'my-property-name'
=>
[
'type'
=>
'integer'
,
'x-i18n-description'
=>
'bar'
]
],
],
],
[
'description'
=>
'translated'
,
'properties'
=>
[
[
'my-property-name'
=>
[
'type'
=>
'integer'
,
'description'
=>
'translated'
]
],
],
]
],
'translatable title, no description'
=>
[
[
'x-i18n-title'
=>
'foo'
,
],
[
'title'
=>
'translated'
,
]
],
'translatable description and title'
=>
[
[
'x-i18n-title'
=>
'foo'
,
'x-i18n-description'
=>
'bar'
,
],
[
'title'
=>
'translated'
,
'description'
=>
'translated'
,
]
],
];
}
/**
* @dataProvider provideLocalizeJsonObjects
*/
public
function
testLocalizeJson
(
$inputObj
,
$expectedObj
)
{
$util
=
new
JsonLocalizer
(
$this
->
createMockResponseFactory
()
);
$adjustedObj
=
$util
->
localizeJson
(
$inputObj
);
$this
->
assertEquals
(
$expectedObj
,
$adjustedObj
);
}
public
static
function
provideGetFormattedMessage
()
{
return
[
'message key'
=>
[
'foo'
,
'translated'
],
'message value'
=>
[
new
MessageValue
(
'foo'
),
'translated'
]
];
}
/**
* @dataProvider provideGetFormattedMessage
*/
public
function
testGetFormattedMessage
(
$message
,
$expectedString
)
{
$util
=
new
JsonLocalizer
(
$this
->
createMockResponseFactory
()
);
$ret
=
$util
->
getFormattedMessage
(
$message
);
$this
->
assertEquals
(
$expectedString
,
$ret
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 15 2026, 17:24 (12 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b6/ac/b9a5086b62564d8292d038db22cb
Default Alt Text
JsonLocalizerTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment