Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / tests / phpunit / includes / CollationTest.php
blob74b129676626bf688a64824da353467d8ae9327d
1 <?php
3 /**
4 * Class CollationTest
5 * @covers Collation
6 * @covers IcuCollation
7 * @covers IdentityCollation
8 * @covers UppercaseCollation
9 */
10 class CollationTest extends MediaWikiLangTestCase {
11 protected function setUp() {
12 parent::setUp();
13 $this->checkPHPExtension( 'intl' );
16 /**
17 * Test to make sure, that if you
18 * have "X" and "XY", the binary
19 * sortkey also has "X" being a
20 * prefix of "XY". Our collation
21 * code makes this assumption.
23 * @param string $lang Language code for collator
24 * @param string $base Base string
25 * @param string $extended String containing base as a prefix.
27 * @dataProvider prefixDataProvider
29 public function testIsPrefix( $lang, $base, $extended ) {
30 $cp = Collator::create( $lang );
31 $cp->setStrength( Collator::PRIMARY );
32 $baseBin = $cp->getSortKey( $base );
33 // Remove sortkey terminator
34 $baseBin = rtrim( $baseBin, "\0" );
35 $extendedBin = $cp->getSortKey( $extended );
36 $this->assertStringStartsWith( $baseBin, $extendedBin, "$base is not a prefix of $extended" );
39 public static function prefixDataProvider() {
40 return array(
41 array( 'en', 'A', 'AA' ),
42 array( 'en', 'A', 'AAA' ),
43 array( 'en', 'Д', 'ДЂ' ),
44 array( 'en', 'Д', 'ДA' ),
45 // 'Ʒ' should expand to 'Z ' (note space).
46 array( 'fi', 'Z', 'Ʒ' ),
47 // 'Þ' should expand to 'th'
48 array( 'sv', 't', 'Þ' ),
49 // Javanese is a limited use alphabet, so should have 3 bytes
50 // per character, so do some tests with it.
51 array( 'en', 'ꦲ', 'ꦲꦤ' ),
52 array( 'en', 'ꦲ', 'ꦲД' ),
53 array( 'en', 'A', 'Aꦲ' ),
57 /**
58 * Opposite of testIsPrefix
60 * @dataProvider notPrefixDataProvider
62 public function testNotIsPrefix( $lang, $base, $extended ) {
63 $cp = Collator::create( $lang );
64 $cp->setStrength( Collator::PRIMARY );
65 $baseBin = $cp->getSortKey( $base );
66 // Remove sortkey terminator
67 $baseBin = rtrim( $baseBin, "\0" );
68 $extendedBin = $cp->getSortKey( $extended );
69 $this->assertStringStartsNotWith( $baseBin, $extendedBin, "$base is a prefix of $extended" );
72 public static function notPrefixDataProvider() {
73 return array(
74 array( 'en', 'A', 'B' ),
75 array( 'en', 'AC', 'ABC' ),
76 array( 'en', 'Z', 'Ʒ' ),
77 array( 'en', 'A', 'ꦲ' ),
81 /**
82 * Test correct first letter is fetched.
84 * @param string $collation Collation name (aka uca-en)
85 * @param string $string String to get first letter of
86 * @param string $firstLetter Expected first letter.
88 * @dataProvider firstLetterProvider
90 public function testGetFirstLetter( $collation, $string, $firstLetter ) {
91 $col = Collation::factory( $collation );
92 $this->assertEquals( $firstLetter, $col->getFirstLetter( $string ) );
95 function firstLetterProvider() {
96 return array(
97 array( 'uppercase', 'Abc', 'A' ),
98 array( 'uppercase', 'abc', 'A' ),
99 array( 'identity', 'abc', 'a' ),
100 array( 'uca-en', 'abc', 'A' ),
101 array( 'uca-en', ' ', ' ' ),
102 array( 'uca-en', 'Êveryone', 'E' ),
103 array( 'uca-vi', 'Êveryone', 'Ê' ),
104 // Make sure thorn is not a first letter.
105 array( 'uca-sv', 'The', 'T' ),
106 array( 'uca-sv', 'Å', 'Å' ),
107 array( 'uca-hu', 'dzsdo', 'Dzs' ),
108 array( 'uca-hu', 'dzdso', 'Dz' ),
109 array( 'uca-hu', 'CSD', 'Cs' ),
110 array( 'uca-root', 'CSD', 'C' ),
111 array( 'uca-fi', 'Ǥ', 'G' ),
112 array( 'uca-fi', 'Ŧ', 'T' ),
113 array( 'uca-fi', 'Ʒ', 'Z' ),
114 array( 'uca-fi', 'Ŋ', 'N' ),