ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
UTFNormalTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 use ilLanguage;
30 
31 class UTFNormalTest extends TestCase
32 {
37 
38  public function setUp(): void
39  {
40  $language = $this->getMockBuilder(ilLanguage::class)
41  ->disableOriginalConstructor()
42  ->getMock();
43  $group = new Group(new Factory(), $language);
44 
45  $this->form_d = $group->utfnormal()->formD();
46  $this->form_c = $group->utfnormal()->formC();
47  $this->form_kc = $group->utfnormal()->formKC();
48  $this->form_kd = $group->utfnormal()->formKD();
49  }
50 
51  public function stringProvider(): array
52  {
53  // Never ever try to change something on this array :-) e.g. a 'ä' isn't a 'ä' but a 'ä' ;-)
54  return [
55  ["Ä\uFB03n", "Ä\uFB03n", 'Ä\uFB03n', 'Ä\uFB03n', 'Ä\uFB03n'],
56  ["\xC3\x85", 'Å', 'Å', 'Å', 'Å'],
57  ["\xCC\x8A", '̊', '̊', '̊', '̊'],
58  ["\u{FFDA}", 'ᅳ', 'ᅳ', 'ᅳ', 'ᅳ'],
59  ["\u{FDFA}", 'ﷺ', 'ﷺ', 'صلى الله عليه وسلم', 'صلى الله عليه وسلم'],
60  ["\xF5", '', '', '', ''],
61  ["ä", 'ä', 'ä', 'ä', 'ä'],
62  ["🤔", "🤔", "🤔", "🤔", "🤔"],
63  ["你好", "你好", "你好", "你好", "你好"],
64  ];
65  }
66 
70  public function testNormalization(
71  string $string,
72  string $expected_form_c,
73  string $expected_form_d,
74  string $expected_form_kc,
75  string $expected_form_kd
76  ): void {
77  // FORM C
78  $this->assertEquals($expected_form_c, $this->form_c->transform($string));
79 
80  // FORM D
81  $this->assertEquals($expected_form_d, $this->form_d->transform($string));
82 
83  // FORM KC
84  $this->assertEquals($expected_form_kc, $this->form_kc->transform($string));
85 
86  // FORM KD
87  $this->assertEquals($expected_form_kd, $this->form_kd->transform($string));
88  }
89 
90  public function testUmlaut(): void
91  {
92  $char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
93  $char_combining_ring_above = 'A' . "\xCC\x8A"; // 'COMBINING RING ABOVE' (U+030A)
94 
95  $this->assertNotEquals($char_A_ring, $char_combining_ring_above);
96  $this->assertNotEquals(bin2hex($char_A_ring), bin2hex($char_combining_ring_above));
97  $tranformation = $this->form_d;
98  $this->assertEquals('Å', $tranformation->transform($char_A_ring));
99  $this->assertEquals(bin2hex('Å'), bin2hex($tranformation->transform($char_A_ring)));
100  $this->assertEquals('Å', $tranformation->transform($char_combining_ring_above));
101  $this->assertEquals(bin2hex('Å'), bin2hex($tranformation->transform($char_combining_ring_above)));
102  $this->assertEquals(
103  $tranformation->transform($char_A_ring),
104  $this->form_kd->transform($char_combining_ring_above)
105  );
106  $this->assertEquals(
107  bin2hex($tranformation->transform($char_A_ring)),
108  bin2hex($this->form_kd->transform($char_combining_ring_above))
109  );
110  }
111 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testNormalization(string $string, string $expected_form_c, string $expected_form_d, string $expected_form_kc, string $expected_form_kd)
stringProvider
A transformation is a function from one datatype to another.