Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5980221
LanguageClassesTestCase.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
LanguageClassesTestCase.php
View Options
<?php
use
MediaWiki\Language\Language
;
/**
* Helping class to run tests using a clean language instance.
*
* This is intended for the MediaWiki language class tests under
* tests/phpunit/includes/languages.
*
* Before each tests, a new language object is built which you
* can retrieve in your test using the $this->getLang() method:
*
* @par Using the crafted language object:
* @code
* function testHasLanguageObject() {
* $langObject = $this->getLang();
* $this->assertInstanceOf( 'LanguageFoo',
* $langObject
* );
* }
* @endcode
*/
abstract
class
LanguageClassesTestCase
extends
MediaWikiIntegrationTestCase
{
/**
* @var Language
*
* A new object is created before each tests thanks to PHPUnit
* setUp() method, it is deleted after each test too. To get
* this object you simply use the getLang method.
*
* You must have setup a language code first. See $LanguageClassCode
* @code
* function testWeAreTheChampions() {
* $this->getLang(); # language object
* }
* @endcode
*/
private
$languageObject
;
/**
* @return Language
*/
protected
function
getLang
()
{
return
$this
->
languageObject
;
}
/**
* Create a new language object before each test.
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
$lang
=
false
;
if
(
preg_match
(
'/Language(.+)Test/'
,
static
::
class
,
$m
)
)
{
# Normalize language code since classes uses underscores
$lang
=
strtolower
(
str_replace
(
'_'
,
'-'
,
$m
[
1
]
)
);
}
if
(
$lang
===
false
||
!
$this
->
getServiceContainer
()->
getLanguageNameUtils
()->
isSupportedLanguage
(
$lang
)
)
{
# Fallback to english language
$lang
=
'en'
;
wfDebug
(
__METHOD__
.
' could not extract a language name '
.
'out of '
.
static
::
class
.
", falling back to 'en'"
);
}
$this
->
languageObject
=
$this
->
getServiceContainer
()->
getLanguageFactory
()
->
getLanguage
(
$lang
);
}
/**
* Delete the internal language object so each test starts
* out with a fresh language instance.
*/
protected
function
tearDown
():
void
{
unset
(
$this
->
languageObject
);
parent
::
tearDown
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 21:17 (1 w, 17 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
2e/71/db13b4c9485002a2d0e0f95cf411
Default Alt Text
LanguageClassesTestCase.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment