Skip to content

Commit

Permalink
Add unit test for all HTML 5 entities that CommonMark parsers must su…
Browse files Browse the repository at this point in the history
…pport
  • Loading branch information
colinodell committed Oct 13, 2019
1 parent 4cd6bac commit 33ddd70
Show file tree
Hide file tree
Showing 3 changed files with 2,255 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -27,6 +27,7 @@
"ext-mbstring": "*"
},
"require-dev": {
"ext-json": "*",
"cebe/markdown": "~1.0",
"commonmark/commonmark.js": "0.29.0",
"erusev/parsedown": "~1.0",
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/Util/Html5EntityDecoderTest.php
Expand Up @@ -16,4 +16,25 @@ public function testEntityToChar()
$this->assertEquals('Æ', Html5EntityDecoder::decode('Æ'));
$this->assertEquals('Ď', Html5EntityDecoder::decode('Ď'));
}

/**
* @dataProvider htmlEntityDataProvider
*/
public function testAllHtml5EntityReferences(string $entity, string $decoded)
{
$this->assertEquals($decoded, html_entity_decode($entity, ENT_QUOTES | ENT_HTML5, 'UTF-8'), sprintf('Failed parsing the "%s" entity', $entity));
}

public function htmlEntityDataProvider()
{
// 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']];
}
}
}
}

0 comments on commit 33ddd70

Please sign in to comment.