. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Tests\Encodings; use Fisharebest\Webtrees\Encodings\ISO88591; use Fisharebest\Webtrees\Encodings\UTF8; use PHPUnit\Framework\TestCase; use function chr; use function dechex; use function iconv; use function range; /** * Tests for class ISO88591. */ class ISO88591Test extends TestCase { /** * @covers \Fisharebest\Webtrees\Encodings\AbstractEncoding * @covers \Fisharebest\Webtrees\Encodings\ISO88591 */ public function testToUtf8(): void { $encoding = new ISO88591(); // iconv uses CP1252, and therefore adds chacaters to 0x80 - 0x9F $ranges = [ range(0, 0x7F), range(0xA0, 0xFF), ]; foreach (range(0x80, 0x9F) as $code_point) { $character = chr($code_point); $actual = $encoding->toUtf8($character); static::assertSame(UTF8::REPLACEMENT_CHARACTER, $actual, dechex($code_point) . '=>' . $actual); } foreach ($ranges as $range) { foreach ($range as $code_point) { $character = chr($code_point); $actual = $encoding->toUtf8($character); $expected = iconv(ISO88591::NAME, UTF8::NAME, $character); $expected = $expected === '' ? UTF8::REPLACEMENT_CHARACTER : $expected; static::assertSame($expected, $actual, dechex($code_point) . '=>' . $actual . ' ' . $expected); } } } }