* Store prefixes and infixes separately in the data * First match language code, then prefixes, then infixes * Try to use suggestion either in user language or autonym first * use formatversion=2 to avoid escaping Unicode Using Language::fetchLanguageName might can have a small performance impact. On the other hand there is now check to skip languages we already found, avoiding some fuzzy matching. This is in a preparation for a change in jquery.uls to use the search API more, while trying to reduce the amount of weird autocompletion suggestions we show to the user. Bug: T73891 Change-Id: Id94c5352d9a591969bf90144d1d2d5e758d08301
104 lines
2.9 KiB
PHP
104 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* PHPUnit tests for UniversalLanguageSelector extension.
|
|
*
|
|
* Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
|
|
* Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
|
|
* contributors. See CREDITS for a list.
|
|
*
|
|
* UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't
|
|
* have to do anything special to choose one license or the other and you don't
|
|
* have to notify anyone which license you are using. You are free to use
|
|
* UniversalLanguageSelector in commercial projects as long as the copyright
|
|
* header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
|
|
*
|
|
* @file
|
|
* @ingroup Extensions
|
|
* @licence GNU General Public Licence 2.0 or later
|
|
* @licence MIT License
|
|
*/
|
|
require_once __DIR__ . '/../../data/LanguageNameSearch.php';
|
|
class LanguageSearchTest extends PHPUnit_Framework_TestCase {
|
|
/**
|
|
* @dataProvider searchDataProvider
|
|
*/
|
|
public function testSearch( $searchKey, $expected ) {
|
|
$actual = LanguageNameSearch::search( $searchKey, 1, 'en' );
|
|
// This is for better error messages
|
|
$this->assertEquals( $expected, $actual );
|
|
// This is for identical order
|
|
$this->assertSame( $expected, $actual );
|
|
}
|
|
|
|
public function searchDataProvider() {
|
|
return [
|
|
[ 'ഹിന്ദി', [
|
|
'hi' => 'ഹിന്ദി'
|
|
]
|
|
],
|
|
[ 'മല', [
|
|
'mg' => 'മലഗാസി',
|
|
'ml' => 'മലയാളം',
|
|
'ms' => 'മലെയ്',
|
|
]
|
|
],
|
|
[ 'Φινλαν', [
|
|
'fi' => 'φινλανδικά',
|
|
]
|
|
],
|
|
[ 'blargh', []
|
|
],
|
|
[ 'الفرنسية', [
|
|
'fr' => 'الفرنسية',
|
|
'fr-ch' => 'الفرنسية السويسرية',
|
|
'fro' => 'الفرنسية القديمة',
|
|
'frc' => 'الفرنسية الكاجونية',
|
|
'crs' => 'الفرنسية الكريولية السيشيلية',
|
|
'fr-ca' => 'الفرنسية الكندية',
|
|
'frm' => 'الفرنسية الوسطى',
|
|
]
|
|
],
|
|
[ 'മലയളം', [
|
|
'ml' => 'മലയാളം',
|
|
]
|
|
],
|
|
[ 'punja', [
|
|
'pa' => class_exists( 'LanguageNames' ) ? 'punjabi' : 'punjaabi sennii',
|
|
'pnb' => 'punjabi western',
|
|
]
|
|
],
|
|
[ 'kartuli', [
|
|
'ka' => 'kartuli',
|
|
]
|
|
],
|
|
[ 'valencia', [
|
|
'ca' => 'valencia',
|
|
]
|
|
],
|
|
[ 'chinese', [
|
|
'zh' => 'chinese',
|
|
'zh-cn' => 'chinese (china)',
|
|
'zh-hk' => 'chinese (hong kong)',
|
|
'zh-min-nan' => 'chinese (min nan)',
|
|
'zh-sg' => 'chinese (singapore)',
|
|
'zh-tw' => 'chinese (taiwan)',
|
|
'zh-hans' => 'chinese simplified',
|
|
'zh-hant' => 'chinese traditional',
|
|
'zh-classical' => 'chinese <classical chinese>',
|
|
'gan' => 'chinese <gan chinese>',
|
|
'hak' => 'chinese <hakka chinese>',
|
|
'nan' => 'chinese <isi-min nan chinese>',
|
|
'wuu' => 'chinese <isi-wu chinese>',
|
|
'hsn' => 'chinese <isi-xiang chinese>',
|
|
'lzh' => 'chinese <literary chinese>',
|
|
'cdo' => 'chinese <min dong chinese>',
|
|
]
|
|
],
|
|
[ 'finish', [
|
|
'fi' => 'finnish'
|
|
]
|
|
],
|
|
];
|
|
}
|
|
}
|