This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
120 lines
3.4 KiB
PHP
120 lines
3.4 KiB
PHP
<?php
|
||
/**
|
||
* PHPUnit tests for the Uzbek language.
|
||
* The language can be represented using two scripts:
|
||
* - Latin (uz-latn)
|
||
* - Cyrillic (uz-cyrl)
|
||
*
|
||
* @author Robin Pepermans
|
||
* @author Antoine Musso <hashar at free dot fr>
|
||
* @copyright Copyright © 2012, Robin Pepermans
|
||
* @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr>
|
||
* @file
|
||
*/
|
||
|
||
require_once dirname( __DIR__ ) . '/bootstrap.php';
|
||
|
||
/** Tests for MediaWiki languages/LanguageUz.php */
|
||
class LanguageUzTest extends MediaWikiTestCase {
|
||
/* Language object. Initialized before each test */
|
||
private $lang;
|
||
|
||
protected function setUp() {
|
||
$this->lang = Language::factory( 'uz' );
|
||
}
|
||
protected function tearDown() {
|
||
unset( $this->lang );
|
||
}
|
||
|
||
/**
|
||
* @author Nikola Smolenski
|
||
*/
|
||
function testConversionToCyrillic() {
|
||
// A convertion of Latin to Cyrillic
|
||
$this->assertEquals( 'абвгғ',
|
||
$this->convertToCyrillic( 'abvggʻ' )
|
||
);
|
||
// Same as above, but assert that -{}-s must be removed and not converted
|
||
$this->assertEquals( 'ljабnjвгўоdb',
|
||
$this->convertToCyrillic( '-{lj}-ab-{nj}-vgoʻo-{db}-' )
|
||
);
|
||
// A simple convertion of Cyrillic to Cyrillic
|
||
$this->assertEquals( 'абвг',
|
||
$this->convertToCyrillic( 'абвг' )
|
||
);
|
||
// Same as above, but assert that -{}-s must be removed and not converted
|
||
$this->assertEquals( 'ljабnjвгdaž',
|
||
$this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{da}-ž' )
|
||
);
|
||
}
|
||
|
||
function testConversionToLatin() {
|
||
// A simple convertion of Latin to Latin
|
||
$this->assertEquals( 'abdef',
|
||
$this->convertToLatin( 'abdef' )
|
||
);
|
||
// A convertion of Cyrillic to Latin
|
||
$this->assertEquals( 'gʻabtsdOʻQyo',
|
||
$this->convertToLatin( 'ғабцдЎҚё' )
|
||
);
|
||
}
|
||
|
||
##### HELPERS #####################################################
|
||
/**
|
||
* Wrapper to verify text stay the same after applying conversion
|
||
* @param $text string Text to convert
|
||
* @param $variant string Language variant 'uz-cyrl' or 'uz-latn'
|
||
* @param $msg string Optional message
|
||
*/
|
||
function assertUnConverted( $text, $variant, $msg = '' ) {
|
||
$this->assertEquals(
|
||
$text,
|
||
$this->convertTo( $text, $variant ),
|
||
$msg
|
||
);
|
||
}
|
||
/**
|
||
* Wrapper to verify a text is different once converted to a variant.
|
||
* @param $text string Text to convert
|
||
* @param $variant string Language variant 'uz-cyrl' or 'uz-latn'
|
||
* @param $msg string Optional message
|
||
*/
|
||
function assertConverted( $text, $variant, $msg = '' ) {
|
||
$this->assertNotEquals(
|
||
$text,
|
||
$this->convertTo( $text, $variant ),
|
||
$msg
|
||
);
|
||
}
|
||
|
||
/**
|
||
* Verifiy the given Cyrillic text is not converted when using
|
||
* using the cyrillic variant and converted to Latin when using
|
||
* the Latin variant.
|
||
*/
|
||
function assertCyrillic( $text, $msg = '' ) {
|
||
$this->assertUnConverted( $text, 'uz-cyrl', $msg );
|
||
$this->assertConverted( $text, 'uz-latn', $msg );
|
||
}
|
||
/**
|
||
* Verifiy the given Latin text is not converted when using
|
||
* using the Latin variant and converted to Cyrillic when using
|
||
* the Cyrillic variant.
|
||
*/
|
||
function assertLatin( $text, $msg = '' ) {
|
||
$this->assertUnConverted( $text, 'uz-latn', $msg );
|
||
$this->assertConverted( $text, 'uz-cyrl', $msg );
|
||
}
|
||
|
||
|
||
/** Wrapper for converter::convertTo() method*/
|
||
function convertTo( $text, $variant ) {
|
||
return $this->lang->mConverter->convertTo( $text, $variant );
|
||
}
|
||
function convertToCyrillic( $text ) {
|
||
return $this->convertTo( $text, 'uz-cyrl' );
|
||
}
|
||
function convertToLatin( $text ) {
|
||
return $this->convertTo( $text, 'uz-latn' );
|
||
}
|
||
}
|