assertEquals('©', Html5EntityDecoder::decode('©')); $this->assertEquals('©', Html5EntityDecoder::decode('©')); $this->assertEquals('&MadeUpEntity;', Html5EntityDecoder::decode('&MadeUpEntity;')); $this->assertEquals('#', Html5EntityDecoder::decode('#')); $this->assertEquals('Æ', Html5EntityDecoder::decode('Æ')); $this->assertEquals('Ď', Html5EntityDecoder::decode('Ď')); } /** * @dataProvider htmlEntityDataProvider */ public function testAllHtml5EntityReferences(string $entity, string $decoded): void { $this->assertEquals($decoded, \html_entity_decode($entity, ENT_QUOTES | ENT_HTML5, 'UTF-8'), \sprintf('Failed parsing the "%s" entity', $entity)); } /** * @return iterable> */ public function htmlEntityDataProvider(): iterable { // Test data from https://html.spec.whatwg.org/multipage/entities.json $data = \json_decode(\file_get_contents(__DIR__ . '/entities.json'), true); foreach ($data as $entity => $info) { // Per the spec, we only care about entities that have a trailing semi-colon. // See https://spec.commonmark.org/0.29/#entity-references if (\substr($entity, -1, 1) === ';') { yield [$entity, $info['characters']]; } } } }