11c6adce8SGreg Roach<?php 21c6adce8SGreg Roach 31c6adce8SGreg Roach/** 41c6adce8SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 61c6adce8SGreg Roach * This program is free software: you can redistribute it and/or modify 71c6adce8SGreg Roach * it under the terms of the GNU General Public License as published by 81c6adce8SGreg Roach * the Free Software Foundation, either version 3 of the License, or 91c6adce8SGreg Roach * (at your option) any later version. 101c6adce8SGreg Roach * This program is distributed in the hope that it will be useful, 111c6adce8SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 121c6adce8SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 131c6adce8SGreg Roach * GNU General Public License for more details. 141c6adce8SGreg Roach * You should have received a copy of the GNU General Public License 151c6adce8SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 161c6adce8SGreg Roach */ 171c6adce8SGreg Roach 181c6adce8SGreg Roachdeclare(strict_types=1); 191c6adce8SGreg Roach 201c6adce8SGreg Roachnamespace Fisharebest\Webtrees\Tests\Encodings; 211c6adce8SGreg Roach 22*202c018bSGreg Roachuse Fisharebest\Webtrees\Encodings\AbstractEncoding; 231c6adce8SGreg Roachuse Fisharebest\Webtrees\Encodings\ISO88592; 241c6adce8SGreg Roachuse Fisharebest\Webtrees\Encodings\UTF8; 25*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 261c6adce8SGreg Roachuse PHPUnit\Framework\TestCase; 271c6adce8SGreg Roach 281c6adce8SGreg Roachuse function chr; 291c6adce8SGreg Roachuse function dechex; 301c6adce8SGreg Roachuse function iconv; 311c6adce8SGreg Roachuse function range; 321c6adce8SGreg Roach 33*202c018bSGreg Roach#[CoversClass(AbstractEncoding::class)] 34*202c018bSGreg Roach#[CoversClass(ISO88592::class)] 351c6adce8SGreg Roachclass ISO88592Test extends TestCase 361c6adce8SGreg Roach{ 371c6adce8SGreg Roach public function testToUtf8(): void 381c6adce8SGreg Roach { 391c6adce8SGreg Roach $encoding = new ISO88592(); 401c6adce8SGreg Roach 411c6adce8SGreg Roach // iconv uses CP1250, and therefore adds characters to 0x80 - 0x9F 421c6adce8SGreg Roach $ranges = [ 431c6adce8SGreg Roach range(0, 0x7F), 441c6adce8SGreg Roach range(0xA0, 0xFF), 451c6adce8SGreg Roach ]; 461c6adce8SGreg Roach 471c6adce8SGreg Roach foreach (range(0x80, 0x9F) as $code_point) { 481c6adce8SGreg Roach $character = chr($code_point); 491c6adce8SGreg Roach $actual = $encoding->toUtf8($character); 501c6adce8SGreg Roach 51f01ab4acSGreg Roach static::assertSame(UTF8::REPLACEMENT_CHARACTER, $actual, dechex($code_point) . '=>' . $actual); 521c6adce8SGreg Roach } 531c6adce8SGreg Roach 541c6adce8SGreg Roach foreach ($ranges as $range) { 551c6adce8SGreg Roach foreach ($range as $code_point) { 561c6adce8SGreg Roach $character = chr($code_point); 571c6adce8SGreg Roach $actual = $encoding->toUtf8($character); 581c6adce8SGreg Roach $expected = iconv(ISO88592::NAME, UTF8::NAME, $character); 591c6adce8SGreg Roach $expected = $expected === '' ? UTF8::REPLACEMENT_CHARACTER : $expected; 601c6adce8SGreg Roach 61f01ab4acSGreg Roach static::assertSame($expected, $actual, dechex($code_point) . '=>' . $actual . ' ' . $expected); 621c6adce8SGreg Roach } 631c6adce8SGreg Roach } 641c6adce8SGreg Roach } 651c6adce8SGreg Roach} 66