Debian Codegraph @

tests/phpunit/includes/collation/RemoteIcuCollationTest.php

raw symbols SCIP
1 <?php
2
3 use Wikimedia\TestingAccessWrapper;
4
5 /**
6 * @covers \RemoteIcuCollation
7 */
8 class RemoteIcuCollationTest extends MediaWikiLangTestCase {
9 public static function provideEncode() {
10 return [
11 [
12 [],
13 ''
14 ],
15 [
16 [ 'foo' ],
17 '00000003foo'
18 ],
19 [
20 [ 'foo', 'a somewhat longer string' ],
21 '00000003foo00000018a somewhat longer string'
22 ],
23 ];
24 }
25
26 /** @dataProvider provideEncode */
27 public function testEncode( $input, $expected ) {
28 $coll = TestingAccessWrapper::newFromClass( RemoteIcuCollation::class );
29 $this->assertSame( $expected, $coll->encode( $input ) );
30 }
31
32 public static function provideEncodeDecode() {
33 return [
34 [ [ "\000" ] ],
35 [ [ "a\000b" ] ],
36 [ [ str_repeat( "\001", 100 ) ] ],
37 [ [ 'foo' ] ],
38 [ [ 'foo', 'bar' ] ],
39 [ [ 'foo', 'bar', str_repeat( 'x', 1000 ) ] ]
40 ];
41 }
42
43 /** @dataProvider provideEncodeDecode */
44 public function testEncodeDecode( $input ) {
45 $coll = TestingAccessWrapper::newFromClass( RemoteIcuCollation::class );
46 $this->assertSame( $input, $coll->decode( $coll->encode( $input ) ) );
47 }
48
49 public static function provideGetSortKeys() {
50 $cases = [
51 [],
52 [ '' ],
53 [ 'test1' => 'bar', 'test2' => 'foo' ],
54 [
55 'bar',
56 'foo'
57 ],
58 [
59 'first',
60 'Second'
61 ],
62 [
63 '',
64 'second'
65 ],
66 [
67 'Berić',
68 'Berisha',
69 ],
70 [
71 '2',
72 '10',
73 ]
74 ];
75 foreach ( $cases as $case ) {
76 yield [ $case ];
77 }
78 }
79
80 /** @dataProvider provideGetSortKeys */
81 public function testGetSortKeys( $inputs ) {
82 $coll = new RemoteIcuCollation(
83 $this->getServiceContainer()->getShellboxClientFactory(),
84 'uca-default-u-kn'
85 );
86 $sortKeys = $coll->getSortKeys( $inputs );
87 $prevKey = null;
88 if ( count( $inputs ) ) {
89 foreach ( $inputs as $i => $input ) {
90 $key = $sortKeys[$i];
91 $this->assertIsString( $key );
92 if ( $prevKey ) {
93 $this->assertLessThan( 0, strcmp( $prevKey, $key ) );
94 }
95 $prevKey = $key;
96 }
97 } else {
98 $this->assertSame( [], $sortKeys );
99 }
100 }
101
102 /** @dataProvider provideGetSortKeys */
103 public function testGetSortKey( $inputs ) {
104 if ( !count( $inputs ) ) {
105 // Not risky, it's just handy to reuse the provider
106 $this->assertTrue( true );
107 }
108 $coll = new RemoteIcuCollation(
109 $this->getServiceContainer()->getShellboxClientFactory(),
110 'uca-default-u-kn'
111 );
112 $prevKey = null;
113 foreach ( $inputs as $input ) {
114 $key = $coll->getSortKey( $input );
115 $this->assertIsString( $key );
116 if ( $prevKey ) {
117 $this->assertLessThan( 0, strcmp( $prevKey, $key ) );
118 }
119 $prevKey = $key;
120 }
121 }
122 }