wiki.techinc.nl/tests/phpunit/includes/CollationTest.php
Chad Horohoe d0c8ba037c Remove wfDl() and cleanup everything it touched
wfDl() is a wrapper around dl(), which is an evil function and
basically only works from the command line of Zend. Luckily
no extension has ever used this thing, so let's just remove it
outright.

For comparison, here's a list of places it does not work:
- hhvm
- php as apache module
- php compiled with zts support
- safe_mode
- Basically any shared host that cares about security

Most callers are using it to check for extension support and are
actually failing gracefully when wfDl() returns false. In these
places we're just going to use extension_loaded().

While we're at it, clean up some of the test skip logic in the
media tests so we can bail as early as possible if we know we
can't complete the test.

This also immediately removes $wgLoadFileinfoExtension. It's been
enabled by default since 5.3 and falls back gracefully when the
support isn't available.

Change-Id: Ieb430dfc74483731dde51d6e20fa700d641ba1f4
2013-10-09 10:51:35 -07:00

111 lines
3.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class CollationTest extends MediaWikiLangTestCase {
protected function setUp() {
parent::setUp();
if ( !extension_loaded( 'intl' ) ) {
$this->markTestSkipped( 'These tests require intl extension' );
}
}
/**
* Test to make sure, that if you
* have "X" and "XY", the binary
* sortkey also has "X" being a
* prefix of "XY". Our collation
* code makes this assumption.
*
* @param $lang String Language code for collator
* @param $base String Base string
* @param $extended String String containing base as a prefix.
*
* @dataProvider prefixDataProvider
*/
function testIsPrefix( $lang, $base, $extended ) {
$cp = Collator::create( $lang );
$cp->setStrength( Collator::PRIMARY );
$baseBin = $cp->getSortKey( $base );
// Remove sortkey terminator
$baseBin = rtrim( $baseBin, "\0" );
$extendedBin = $cp->getSortKey( $extended );
$this->assertStringStartsWith( $baseBin, $extendedBin, "$base is not a prefix of $extended" );
}
function prefixDataProvider() {
return array(
array( 'en', 'A', 'AA' ),
array( 'en', 'A', 'AAA' ),
array( 'en', 'Д', 'ДЂ' ),
array( 'en', 'Д', 'ДA' ),
// 'Ʒ' should expand to 'Z ' (note space).
array( 'fi', 'Z', 'Ʒ' ),
// 'Þ' should expand to 'th'
array( 'sv', 't', 'Þ' ),
// Javanese is a limited use alphabet, so should have 3 bytes
// per character, so do some tests with it.
array( 'en', 'ꦲ', 'ꦲꦤ' ),
array( 'en', 'ꦲ', 'ꦲД' ),
array( 'en', 'A', 'Aꦲ' ),
);
}
/**
* Opposite of testIsPrefix
*
* @dataProvider notPrefixDataProvider
*/
function testNotIsPrefix( $lang, $base, $extended ) {
$cp = Collator::create( $lang );
$cp->setStrength( Collator::PRIMARY );
$baseBin = $cp->getSortKey( $base );
// Remove sortkey terminator
$baseBin = rtrim( $baseBin, "\0" );
$extendedBin = $cp->getSortKey( $extended );
$this->assertStringStartsNotWith( $baseBin, $extendedBin, "$base is a prefix of $extended" );
}
function notPrefixDataProvider() {
return array(
array( 'en', 'A', 'B' ),
array( 'en', 'AC', 'ABC' ),
array( 'en', 'Z', 'Ʒ' ),
array( 'en', 'A', 'ꦲ' ),
);
}
/**
* Test correct first letter is fetched.
*
* @param $collation String Collation name (aka uca-en)
* @param $string String String to get first letter of
* @param $firstLetter String Expected first letter.
*
* @dataProvider firstLetterProvider
*/
function testGetFirstLetter( $collation, $string, $firstLetter ) {
$col = Collation::factory( $collation );
$this->assertEquals( $firstLetter, $col->getFirstLetter( $string ) );
}
function firstLetterProvider() {
return array(
array( 'uppercase', 'Abc', 'A' ),
array( 'uppercase', 'abc', 'A' ),
array( 'identity', 'abc', 'a' ),
array( 'uca-en', 'abc', 'A' ),
array( 'uca-en', ' ', ' ' ),
array( 'uca-en', 'Êveryone', 'E' ),
array( 'uca-vi', 'Êveryone', 'Ê' ),
// Make sure thorn is not a first letter.
array( 'uca-sv', 'The', 'T' ),
array( 'uca-sv', 'Å', 'Å' ),
array( 'uca-hu', 'dzsdo', 'Dzs' ),
array( 'uca-hu', 'dzdso', 'Dz' ),
array( 'uca-hu', 'CSD', 'Cs' ),
array( 'uca-root', 'CSD', 'C' ),
array( 'uca-fi', 'Ǥ', 'G' ),
array( 'uca-fi', 'Ŧ', 'T' ),
array( 'uca-fi', 'Ʒ', 'Z' ),
array( 'uca-fi', 'Ŋ', 'N' ),
);
}
}