wiki.techinc.nl/tests/phpunit/includes/collation/CustomUppercaseCollationTest.php
Tim Starling 5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00

76 lines
1.7 KiB
PHP

<?php
/**
* TODO convert to a Unit test
*
* @covers CustomUppercaseCollation
*/
class CustomUppercaseCollationTest extends MediaWikiIntegrationTestCase {
/** @var CustomUppercaseCollation */
private $collation;
protected function setUp(): void {
parent::setUp();
$this->collation = new CustomUppercaseCollation(
$this->getServiceContainer()->getLanguageFactory(),
[
'D',
'C',
'Cs',
'B'
],
'en' // digital transformation language
);
}
/**
* @dataProvider providerOrder
*/
public function testOrder( $first, $second, $msg ) {
$sortkey1 = $this->collation->getSortKey( $first );
$sortkey2 = $this->collation->getSortKey( $second );
$this->assertTrue( strcmp( $sortkey1, $sortkey2 ) < 0, $msg );
}
public static function providerOrder() {
return [
[ 'X', 'Z', 'Maintain order of unrearranged' ],
[ 'D', 'C', 'Actually resorts' ],
[ 'D', 'B', 'resort test 2' ],
[ 'Adobe', 'Abode', 'not first letter' ],
[ '💩 ', 'C', 'Test relocated to end' ],
[ 'c', 'b', 'lowercase' ],
[ 'x', 'z', 'lowercase original' ],
[ 'Cz', 'Cs', 'digraphs' ],
[ 'C50D', 'C100', 'Numbers' ]
];
}
/**
* @dataProvider provideGetFirstLetter
*/
public function testGetFirstLetter( $string, $first ) {
$this->assertSame( $this->collation->getFirstLetter( $string ), $first );
}
public static function provideGetFirstLetter() {
return [
[ 'Do', 'D' ],
[ 'do', 'D' ],
[ 'Ao', 'A' ],
[ 'afdsa', 'A' ],
[ "\u{F3000}Foo", 'D' ],
[ "\u{F3001}Foo", 'C' ],
[ "\u{F3002}Foo", 'Cs' ],
[ "\u{F3003}Foo", 'B' ],
[ "\u{F3004}Foo", "\u{F3004}" ],
[ 'C', 'C' ],
[ 'Cz', 'C' ],
[ 'Cs', 'Cs' ],
[ 'CS', 'Cs' ],
[ 'cs', 'Cs' ],
];
}
}