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