Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4090786
LeximorphFactoryTest.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
LeximorphFactoryTest.php
View Options
<?php
/**
* @license GPL-2.0-or-later
* @file
*/
namespace
MediaWiki\Tests\Language
;
use
MediaWiki\Config\ServiceOptions
;
use
MediaWiki\Language\LeximorphFactory
;
use
MediaWiki\MainConfigNames
;
use
MediaWikiIntegrationTestCase
;
use
Psr\Log\NullLogger
;
use
Wikimedia\Bcp47Code\Bcp47CodeValue
;
use
Wikimedia\Leximorph\Manager
;
use
Wikimedia\Leximorph\Provider
;
/**
* This test class verifies the behavior of the LeximorphFactory.
*
* @group Language
* @covers \MediaWiki\Language\LeximorphFactory
* @author Doğu Abaris (abaris@null.net)
*/
class
LeximorphFactoryTest
extends
MediaWikiIntegrationTestCase
{
private
LeximorphFactory
$factory
;
protected
function
setUp
():
void
{
parent
::
setUp
();
$options
=
new
ServiceOptions
(
LeximorphFactory
::
CONSTRUCTOR_OPTIONS
,
[
MainConfigNames
::
UseLeximorph
=>
true
]
);
$this
->
factory
=
new
LeximorphFactory
(
$options
,
new
NullLogger
()
);
}
public
function
testGetManagerCachesByCode
():
void
{
$code
=
new
Bcp47CodeValue
(
'en'
);
$m1
=
$this
->
factory
->
getManager
(
$code
);
$m2
=
$this
->
factory
->
getManager
(
$code
);
$this
->
assertSame
(
$m1
,
$m2
);
}
public
function
testGetProviderCachesByCode
():
void
{
$code
=
new
Bcp47CodeValue
(
'en'
);
$p1
=
$this
->
factory
->
getProvider
(
$code
);
$p2
=
$this
->
factory
->
getProvider
(
$code
);
$this
->
assertSame
(
$p1
,
$p2
);
}
public
function
testDifferentCodesYieldDifferentInstances
():
void
{
$mEn
=
$this
->
factory
->
getManager
(
new
Bcp47CodeValue
(
'en'
)
);
$mDe
=
$this
->
factory
->
getManager
(
new
Bcp47CodeValue
(
'tr'
)
);
$this
->
assertNotSame
(
$mEn
,
$mDe
,
'Different codes => different Manager'
);
$pEn
=
$this
->
factory
->
getProvider
(
new
Bcp47CodeValue
(
'en'
)
);
$pDe
=
$this
->
factory
->
getProvider
(
new
Bcp47CodeValue
(
'tr'
)
);
$this
->
assertNotSame
(
$pEn
,
$pDe
,
'Different codes => different Provider'
);
}
public
function
testRepeatedCallsReturnSameInstance
():
void
{
$m1
=
$this
->
factory
->
getManager
(
new
Bcp47CodeValue
(
'tr'
)
);
$m2
=
$this
->
factory
->
getManager
(
new
Bcp47CodeValue
(
'tr'
)
);
$this
->
assertSame
(
$m1
,
$m2
,
'LRU caches Manager instances per code'
);
$p1
=
$this
->
factory
->
getProvider
(
new
Bcp47CodeValue
(
'tr'
)
);
$p2
=
$this
->
factory
->
getProvider
(
new
Bcp47CodeValue
(
'tr'
)
);
$this
->
assertSame
(
$p1
,
$p2
,
'LRU caches Provider instances per code'
);
}
public
function
testDisabledFlagReturnsNull
():
void
{
$options
=
new
ServiceOptions
(
LeximorphFactory
::
CONSTRUCTOR_OPTIONS
,
[
MainConfigNames
::
UseLeximorph
=>
false
]
);
$factory
=
new
LeximorphFactory
(
$options
,
new
NullLogger
()
);
$this
->
assertNull
(
$factory
->
getManager
(
new
Bcp47CodeValue
(
'en'
)
)
);
$this
->
assertNull
(
$factory
->
getProvider
(
new
Bcp47CodeValue
(
'en'
)
)
);
}
public
function
testEnabledFlagCreatesInstances
():
void
{
$this
->
assertInstanceOf
(
Manager
::
class
,
$this
->
factory
->
getManager
(
new
Bcp47CodeValue
(
'en'
)
)
);
$this
->
assertInstanceOf
(
Provider
::
class
,
$this
->
factory
->
getProvider
(
new
Bcp47CodeValue
(
'en'
)
)
);
}
public
function
testCacheEvictionWhenCapacityExceeded
():
void
{
$instances
=
[];
for
(
$i
=
0
;
$i
<
120
;
$i
++
)
{
$instances
[]
=
$this
->
factory
->
getManager
(
new
Bcp47CodeValue
(
'x'
.
$i
)
);
}
$newFirst
=
$this
->
factory
->
getManager
(
new
Bcp47CodeValue
(
'x0'
)
);
$this
->
assertNotSame
(
$instances
[
0
],
$newFirst
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 18 2026, 11:19 (5 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
fe/c5/51c9cd486357d867ea15bfe4320e
Default Alt Text
LeximorphFactoryTest.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment