MediaWiki  1.28.3
CollationTest.php
Go to the documentation of this file.
1 <?php
2 
11  protected function setUp() {
12  parent::setUp();
13  $this->checkPHPExtension( 'intl' );
14  }
15 
29  public function testIsPrefix( $lang, $base, $extended ) {
30  $cp = Collator::create( $lang );
31  $cp->setStrength( Collator::PRIMARY );
32  $baseBin = $cp->getSortKey( $base );
33  // Remove sortkey terminator
34  $baseBin = rtrim( $baseBin, "\0" );
35  $extendedBin = $cp->getSortKey( $extended );
36  $this->assertStringStartsWith( $baseBin, $extendedBin, "$base is not a prefix of $extended" );
37  }
38 
39  public static function prefixDataProvider() {
40  return [
41  [ 'en', 'A', 'AA' ],
42  [ 'en', 'A', 'AAA' ],
43  [ 'en', 'Д', 'ДЂ' ],
44  [ 'en', 'Д', 'ДA' ],
45  // 'Ʒ' should expand to 'Z ' (note space).
46  [ 'fi', 'Z', 'Ʒ' ],
47  // 'Þ' should expand to 'th'
48  [ 'sv', 't', 'Þ' ],
49  // Javanese is a limited use alphabet, so should have 3 bytes
50  // per character, so do some tests with it.
51  [ 'en', 'ꦲ', 'ꦲꦤ' ],
52  [ 'en', 'ꦲ', 'ꦲД' ],
53  [ 'en', 'A', 'Aꦲ' ],
54  ];
55  }
56 
62  public function testNotIsPrefix( $lang, $base, $extended ) {
63  $cp = Collator::create( $lang );
64  $cp->setStrength( Collator::PRIMARY );
65  $baseBin = $cp->getSortKey( $base );
66  // Remove sortkey terminator
67  $baseBin = rtrim( $baseBin, "\0" );
68  $extendedBin = $cp->getSortKey( $extended );
69  $this->assertStringStartsNotWith( $baseBin, $extendedBin, "$base is a prefix of $extended" );
70  }
71 
72  public static function notPrefixDataProvider() {
73  return [
74  [ 'en', 'A', 'B' ],
75  [ 'en', 'AC', 'ABC' ],
76  [ 'en', 'Z', 'Ʒ' ],
77  [ 'en', 'A', 'ꦲ' ],
78  ];
79  }
80 
90  public function testGetFirstLetter( $collation, $string, $firstLetter ) {
91  $col = Collation::factory( $collation );
92  $this->assertEquals( $firstLetter, $col->getFirstLetter( $string ) );
93  }
94 
95  function firstLetterProvider() {
96  return [
97  [ 'uppercase', 'Abc', 'A' ],
98  [ 'uppercase', 'abc', 'A' ],
99  [ 'identity', 'abc', 'a' ],
100  [ 'uca-en', 'abc', 'A' ],
101  [ 'uca-en', ' ', ' ' ],
102  [ 'uca-en', 'Êveryone', 'E' ],
103  [ 'uca-vi', 'Êveryone', 'Ê' ],
104  // Make sure thorn is not a first letter.
105  [ 'uca-sv', 'The', 'T' ],
106  [ 'uca-sv', 'Å', 'Å' ],
107  [ 'uca-hu', 'dzsdo', 'Dzs' ],
108  [ 'uca-hu', 'dzdso', 'Dz' ],
109  [ 'uca-hu', 'CSD', 'Cs' ],
110  [ 'uca-root', 'CSD', 'C' ],
111  [ 'uca-fi', 'Ǥ', 'G' ],
112  [ 'uca-fi', 'Ŧ', 'T' ],
113  [ 'uca-fi', 'Ʒ', 'Z' ],
114  [ 'uca-fi', 'Ŋ', 'N' ],
115  ];
116  }
117 }
checkPHPExtension($extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded...
static factory($collationName)
Definition: Collation.php:48
testNotIsPrefix($lang, $base, $extended)
Opposite of testIsPrefix.
Class CollationTest Collation IcuCollation IdentityCollation UppercaseCollation.
if(!isset($args[0])) $lang
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of create
Definition: hooks.txt:2495
testIsPrefix($lang, $base, $extended)
Test to make sure, that if you have "X" and "XY", the binary sortkey also has "X" being a prefix of "...
Base class that store and restore the Language objects.
static notPrefixDataProvider()
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
testGetFirstLetter($collation, $string, $firstLetter)
Test correct first letter is fetched.
static prefixDataProvider()