Skip to content

Commit ab776a0

Browse files
committed
Add encoding tests
1 parent 8cacb98 commit ab776a0

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
5+
</head>
6+
<body>
7+
<p>Žťčýů</p>
8+
</body>
9+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta http-equiv="content-type" content="text/html;charset=windows-1252">
5+
</head>
6+
<body>
7+
<p>Žèýù</p>
8+
</body>
9+
</html>

test/HTML5/Html5Test.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
namespace Masterminds\HTML5\Tests;
44

5+
use Masterminds\HTML5;
6+
57
class Html5Test extends TestCase
68
{
9+
/**
10+
* @var HTML5
11+
*/
12+
private $html5;
13+
714
public function setUp()
815
{
916
$this->html5 = $this->getInstance();
@@ -50,8 +57,8 @@ public function testLoadOptions()
5057
{
5158
// doc
5259
$dom = $this->html5->loadHTML($this->wrap('<t:tag/>'), array(
53-
'implicitNamespaces' => array('t' => 'http://example.com'),
54-
'xmlNamespaces' => true,
60+
'implicitNamespaces' => array('t' => 'http://example.com'),
61+
'xmlNamespaces' => true,
5562
));
5663
$this->assertInstanceOf('\DOMDocument', $dom);
5764
$this->assertEmpty($this->html5->getErrors());
@@ -63,8 +70,8 @@ public function testLoadOptions()
6370

6471
// doc fragment
6572
$frag = $this->html5->loadHTMLFragment('<t:tag/>', array(
66-
'implicitNamespaces' => array('t' => 'http://example.com'),
67-
'xmlNamespaces' => true,
73+
'implicitNamespaces' => array('t' => 'http://example.com'),
74+
'xmlNamespaces' => true,
6875
));
6976
$this->assertInstanceOf('\DOMDocumentFragment', $frag);
7077
$this->assertEmpty($this->html5->getErrors());
@@ -76,6 +83,29 @@ public function testLoadOptions()
7683
$this->assertEquals(1, $xpath->query('//t:tag', $frag)->length);
7784
}
7885

86+
public function testEncodingUtf8()
87+
{
88+
$dom = $this->html5->load(__DIR__.'/Fixtures/encoding/utf-8.html');
89+
$this->assertInstanceOf('\DOMDocument', $dom);
90+
$this->assertEmpty($this->html5->getErrors());
91+
$this->assertFalse($this->html5->hasErrors());
92+
93+
$this->assertContains('Žťčýů', $dom->saveHTML());
94+
}
95+
96+
public function testEncodingWindows1252()
97+
{
98+
$dom = $this->html5->load(__DIR__.'/Fixtures/encoding/windows-1252.html', array(
99+
'encoding' => 'Windows-1252',
100+
));
101+
102+
$this->assertInstanceOf('\DOMDocument', $dom);
103+
$this->assertEmpty($this->html5->getErrors());
104+
$this->assertFalse($this->html5->hasErrors());
105+
106+
$this->assertContains('Ž&#65533;&#232;ý&#249;', mb_convert_encoding($dom->saveHTML(), 'UTF-8', 'Windows-1252'));
107+
}
108+
79109
public function testErrors()
80110
{
81111
$dom = $this->html5->loadHTML('<xx as>');

0 commit comments

Comments
 (0)