summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTitouan Galopin <[email protected]>2018-12-29 16:51:06 +0100
committerTitouan Galopin <[email protected]>2018-12-29 16:53:44 +0100
commitab776a0cd0f02a579b8aae6acdd6c3fe6e9d33e2 (patch)
tree5eb981d56a028e891c05476cc9520f7a91e78d13
parent8cacb989a3d98dd6177a3be03b8dc4d610b186dd (diff)
Add encoding tests
-rw-r--r--test/HTML5/Fixtures/encoding/utf-8.html9
-rw-r--r--test/HTML5/Fixtures/encoding/windows-1252.html9
-rw-r--r--test/HTML5/Html5Test.php38
3 files changed, 52 insertions, 4 deletions
diff --git a/test/HTML5/Fixtures/encoding/utf-8.html b/test/HTML5/Fixtures/encoding/utf-8.html
new file mode 100644
index 0000000..fa5a029
--- /dev/null
+++ b/test/HTML5/Fixtures/encoding/utf-8.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8" />
+</head>
+<body>
+ <p>Žťčýů</p>
+</body>
+</html>
diff --git a/test/HTML5/Fixtures/encoding/windows-1252.html b/test/HTML5/Fixtures/encoding/windows-1252.html
new file mode 100644
index 0000000..f0132da
--- /dev/null
+++ b/test/HTML5/Fixtures/encoding/windows-1252.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=windows-1252">
+</head>
+<body>
+ <p>�����</p>
+</body>
+</html>
diff --git a/test/HTML5/Html5Test.php b/test/HTML5/Html5Test.php
index 47bcafd..812d179 100644
--- a/test/HTML5/Html5Test.php
+++ b/test/HTML5/Html5Test.php
@@ -2,8 +2,15 @@
namespace Masterminds\HTML5\Tests;
+use Masterminds\HTML5;
+
class Html5Test extends TestCase
{
+ /**
+ * @var HTML5
+ */
+ private $html5;
+
public function setUp()
{
$this->html5 = $this->getInstance();
@@ -50,8 +57,8 @@ class Html5Test extends TestCase
{
// doc
$dom = $this->html5->loadHTML($this->wrap('<t:tag/>'), array(
- 'implicitNamespaces' => array('t' => 'http://example.com'),
- 'xmlNamespaces' => true,
+ 'implicitNamespaces' => array('t' => 'http://example.com'),
+ 'xmlNamespaces' => true,
));
$this->assertInstanceOf('\DOMDocument', $dom);
$this->assertEmpty($this->html5->getErrors());
@@ -63,8 +70,8 @@ class Html5Test extends TestCase
// doc fragment
$frag = $this->html5->loadHTMLFragment('<t:tag/>', array(
- 'implicitNamespaces' => array('t' => 'http://example.com'),
- 'xmlNamespaces' => true,
+ 'implicitNamespaces' => array('t' => 'http://example.com'),
+ 'xmlNamespaces' => true,
));
$this->assertInstanceOf('\DOMDocumentFragment', $frag);
$this->assertEmpty($this->html5->getErrors());
@@ -76,6 +83,29 @@ class Html5Test extends TestCase
$this->assertEquals(1, $xpath->query('//t:tag', $frag)->length);
}
+ public function testEncodingUtf8()
+ {
+ $dom = $this->html5->load(__DIR__.'/Fixtures/encoding/utf-8.html');
+ $this->assertInstanceOf('\DOMDocument', $dom);
+ $this->assertEmpty($this->html5->getErrors());
+ $this->assertFalse($this->html5->hasErrors());
+
+ $this->assertContains('Žťčýů', $dom->saveHTML());
+ }
+
+ public function testEncodingWindows1252()
+ {
+ $dom = $this->html5->load(__DIR__.'/Fixtures/encoding/windows-1252.html', array(
+ 'encoding' => 'Windows-1252',
+ ));
+
+ $this->assertInstanceOf('\DOMDocument', $dom);
+ $this->assertEmpty($this->html5->getErrors());
+ $this->assertFalse($this->html5->hasErrors());
+
+ $this->assertContains('Ž&#65533;&#232;ý&#249;', mb_convert_encoding($dom->saveHTML(), 'UTF-8', 'Windows-1252'));
+ }
+
public function testErrors()
{
$dom = $this->html5->loadHTML('<xx as>');