aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/collation/CustomUppercaseCollationTest.php
blob: 5428153294f3a6b5b1d1295819d49c4c9929d4c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?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' ],
		];
	}
}