UTF8 support for assertMatchesHtmlSnapshot
jacekkarczmarczyk opened this issue · 1 comments
jacekkarczmarczyk commented
Following code replaces utf8 characters with html entities in snapshot:
<?php
use PHPUnit\Framework\TestCase;
use Spatie\Snapshots\MatchesSnapshots;
final class SomeTest extends TestCase
{
use MatchesSnapshots;
public function testUtf(): void
{
$this->assertMatchesHtmlSnapshot('<p>żółć देवनागरी Кириллица</p>');
}
}
Result:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>żółć देवनागरी Кириллица</p></body></html>
Maybe assertMatchesHtmlSnapshot
could accept encoding as a second parameter (it could be passed to new HtmlDriver($encoding)
and then to $domDocument = new DOMDocument('1.0', $encoding);
?
jacekkarczmarczyk commented
Looks it works fine with proper encoding in <meta>
<?php
use PHPUnit\Framework\TestCase;
use Spatie\Snapshots\MatchesSnapshots;
final class SomeTest extends TestCase
{
use MatchesSnapshots;
public function testUtf(): void
{
$this->assertMatchesHtmlSnapshot('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><p>żółć देवनागरी Кириллица</p>');
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body><p>żółć देवनागरी Кириллица</p></body>
</html>