MediaWiki  REL1_22
CollationTest.php
Go to the documentation of this file.
00001 <?php
00002 class CollationTest extends MediaWikiLangTestCase {
00003     protected function setUp() {
00004         parent::setUp();
00005         if ( !extension_loaded( 'intl' ) ) {
00006             $this->markTestSkipped( 'These tests require intl extension' );
00007         }
00008     }
00009 
00023     public function testIsPrefix( $lang, $base, $extended ) {
00024         $cp = Collator::create( $lang );
00025         $cp->setStrength( Collator::PRIMARY );
00026         $baseBin = $cp->getSortKey( $base );
00027         // Remove sortkey terminator
00028         $baseBin = rtrim( $baseBin, "\0" );
00029         $extendedBin = $cp->getSortKey( $extended );
00030         $this->assertStringStartsWith( $baseBin, $extendedBin, "$base is not a prefix of $extended" );
00031     }
00032 
00033     function prefixDataProvider() {
00034         return array(
00035             array( 'en', 'A', 'AA' ),
00036             array( 'en', 'A', 'AAA' ),
00037             array( 'en', 'Д', 'ДЂ' ),
00038             array( 'en', 'Д', 'ДA' ),
00039             // 'Ʒ' should expand to 'Z ' (note space).
00040             array( 'fi', 'Z', 'Ʒ' ),
00041             // 'Þ' should expand to 'th'
00042             array( 'sv', 't', 'Þ' ),
00043             // Javanese is a limited use alphabet, so should have 3 bytes
00044             // per character, so do some tests with it.
00045             array( 'en', 'ꦲ', 'ꦲꦤ' ),
00046             array( 'en', 'ꦲ', 'ꦲД' ),
00047             array( 'en', 'A', 'Aꦲ' ),
00048         );
00049     }
00050 
00056     public function testNotIsPrefix( $lang, $base, $extended ) {
00057         $cp = Collator::create( $lang );
00058         $cp->setStrength( Collator::PRIMARY );
00059         $baseBin = $cp->getSortKey( $base );
00060         // Remove sortkey terminator
00061         $baseBin = rtrim( $baseBin, "\0" );
00062         $extendedBin = $cp->getSortKey( $extended );
00063         $this->assertStringStartsNotWith( $baseBin, $extendedBin, "$base is a prefix of $extended" );
00064     }
00065 
00066     function notPrefixDataProvider() {
00067         return array(
00068             array( 'en', 'A', 'B' ),
00069             array( 'en', 'AC', 'ABC' ),
00070             array( 'en', 'Z', 'Ʒ' ),
00071             array( 'en', 'A', 'ꦲ' ),
00072         );
00073     }
00074 
00084     public function testGetFirstLetter( $collation, $string, $firstLetter ) {
00085         $col = Collation::factory( $collation );
00086         $this->assertEquals( $firstLetter, $col->getFirstLetter( $string ) );
00087     }
00088 
00089     function firstLetterProvider() {
00090         return array(
00091             array( 'uppercase', 'Abc', 'A' ),
00092             array( 'uppercase', 'abc', 'A' ),
00093             array( 'identity', 'abc', 'a' ),
00094             array( 'uca-en', 'abc', 'A' ),
00095             array( 'uca-en', ' ', ' ' ),
00096             array( 'uca-en', 'Êveryone', 'E' ),
00097             array( 'uca-vi', 'Êveryone', 'Ê' ),
00098             // Make sure thorn is not a first letter.
00099             array( 'uca-sv', 'The', 'T' ),
00100             array( 'uca-sv', 'Å', 'Å' ),
00101             array( 'uca-hu', 'dzsdo', 'Dzs' ),
00102             array( 'uca-hu', 'dzdso', 'Dz' ),
00103             array( 'uca-hu', 'CSD', 'Cs' ),
00104             array( 'uca-root', 'CSD', 'C' ),
00105             array( 'uca-fi', 'Ǥ', 'G' ),
00106             array( 'uca-fi', 'Ŧ', 'T' ),
00107             array( 'uca-fi', 'Ʒ', 'Z' ),
00108             array( 'uca-fi', 'Ŋ', 'N' ),
00109         );
00110     }
00111 }