ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UTFNormalTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use PHPUnit\Framework\TestCase;
26use ILIAS\Refinery\String\Transformation\UTFNormalTransformation;
28use PHPUnit\Framework\Attributes\DataProvider;
29
30class UTFNormalTest extends TestCase
31{
36
37 public function setUp(): void
38 {
39 $language = $this->getMockBuilder(\ILIAS\Language\Language::class)
40 ->disableOriginalConstructor()
41 ->getMock();
42 $group = new Group(new Factory(), $language);
43
44 $this->form_d = $group->utfnormal()->formD();
45 $this->form_c = $group->utfnormal()->formC();
46 $this->form_kc = $group->utfnormal()->formKC();
47 $this->form_kd = $group->utfnormal()->formKD();
48 }
49
50 public static function stringProvider(): array
51 {
52 // Never ever try to change something on this array :-) e.g. a 'ä' isn't a 'ä' but a 'ä' ;-)
53 return [
54 ["Ä\uFB03n", "Ä\uFB03n", 'Ä\uFB03n', 'Ä\uFB03n', 'Ä\uFB03n'],
55 ["\xC3\x85", 'Å', 'Å', 'Å', 'Å'],
56 ["\xCC\x8A", '̊', '̊', '̊', '̊'],
57 ["\u{FFDA}", 'ᅳ', 'ᅳ', 'ᅳ', 'ᅳ'],
58 ["\u{FDFA}", 'ﷺ', 'ﷺ', 'صلى الله عليه وسلم', 'صلى الله عليه وسلم'],
59 ["\xF5", '', '', '', ''],
60 ["ä", 'ä', 'ä', 'ä', 'ä'],
61 ["🤔", "🤔", "🤔", "🤔", "🤔"],
62 ["你好", "你好", "你好", "你好", "你好"],
63 ];
64 }
65
66 #[DataProvider('stringProvider')]
67 public function testNormalization(
68 string $string,
69 string $expected_form_c,
70 string $expected_form_d,
71 string $expected_form_kc,
72 string $expected_form_kd
73 ): void {
74 // FORM C
75 $this->assertEquals($expected_form_c, $this->form_c->transform($string));
76
77 // FORM D
78 $this->assertEquals($expected_form_d, $this->form_d->transform($string));
79
80 // FORM KC
81 $this->assertEquals($expected_form_kc, $this->form_kc->transform($string));
82
83 // FORM KD
84 $this->assertEquals($expected_form_kd, $this->form_kd->transform($string));
85 }
86
87 public function testUmlaut(): void
88 {
89 $char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
90 $char_combining_ring_above = 'A' . "\xCC\x8A"; // 'COMBINING RING ABOVE' (U+030A)
91
92 $this->assertNotEquals($char_A_ring, $char_combining_ring_above);
93 $this->assertNotEquals(bin2hex($char_A_ring), bin2hex($char_combining_ring_above));
94 $tranformation = $this->form_d;
95 $this->assertEquals('Å', $tranformation->transform($char_A_ring));
96 $this->assertEquals(bin2hex('Å'), bin2hex($tranformation->transform($char_A_ring)));
97 $this->assertEquals('Å', $tranformation->transform($char_combining_ring_above));
98 $this->assertEquals(bin2hex('Å'), bin2hex($tranformation->transform($char_combining_ring_above)));
99 $this->assertEquals(
100 $tranformation->transform($char_A_ring),
101 $this->form_kd->transform($char_combining_ring_above)
102 );
103 $this->assertEquals(
104 bin2hex($tranformation->transform($char_A_ring)),
105 bin2hex($this->form_kd->transform($char_combining_ring_above))
106 );
107 }
108}
Builds data types.
Definition: Factory.php:36
testNormalization(string $string, string $expected_form_c, string $expected_form_d, string $expected_form_kc, string $expected_form_kd)
A transformation is a function from one datatype to another.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.