summaryrefslogtreecommitdiff
path: root/test/HTML5
diff options
context:
space:
mode:
Diffstat (limited to 'test/HTML5')
-rw-r--r--test/HTML5/Html5Test.php102
-rw-r--r--test/HTML5/Parser/DOMTreeBuilderTest.php1
-rw-r--r--test/HTML5/Parser/EventStack.php4
-rw-r--r--test/HTML5/Serializer/OutputRulesTest.php93
-rw-r--r--test/HTML5/Serializer/TraverserTest.php30
-rw-r--r--test/HTML5/TestCase.php5
6 files changed, 132 insertions, 103 deletions
diff --git a/test/HTML5/Html5Test.php b/test/HTML5/Html5Test.php
index 29ce83b..b2d3388 100644
--- a/test/HTML5/Html5Test.php
+++ b/test/HTML5/Html5Test.php
@@ -3,83 +3,98 @@ namespace HTML5\Tests;
class Html5Test extends TestCase {
+ public function setUp()
+ {
+ $this->html5 = $this->getInstance();
+ }
/**
* Parse and serialize a string.
*/
protected function cycle($html) {
- $dom = \HTML5::loadHTML('<!DOCTYPE html><html><body>' . $html . '</body></html>');
- $out = \HTML5::saveHTML($dom);
+
+ $dom = $this->html5->loadHTML('<!DOCTYPE html><html><body>' . $html . '</body></html>');
+ $out = $this->html5->saveHTML($dom);
return $out;
}
protected function cycleFragment($fragment) {
- $dom = \HTML5::loadHTMLFragment($fragment);
- $out = \HTML5::saveHTML($dom);
+
+ $dom = $this->html5->loadHTMLFragment($fragment);
+ $out = $this->html5->saveHTML($dom);
return $out;
}
+ public function testErrors() {
+ $dom = $this->html5->loadHTML('<xx as>');
+ $this->assertInstanceOf('\DOMDocument', $dom);
+
+ $this->assertNotEmpty($this->html5->getErrors());
+ $this->assertTrue($this->html5->hasErrors());
+ }
+
public function testLoad() {
- $dom = \HTML5::load(__DIR__ . '/Html5Test.html');
+ $dom = $this->html5->load(__DIR__ . '/Html5Test.html');
$this->assertInstanceOf('\DOMDocument', $dom);
- $this->assertEmpty($dom->errors);
+ $this->assertEmpty($this->html5->getErrors());
+ $this->assertFalse($this->html5->hasErrors());
$file = fopen(__DIR__ . '/Html5Test.html', 'r');
- $dom = \HTML5::load($file);
+ $dom = $this->html5->load($file);
$this->assertInstanceOf('\DOMDocument', $dom);
- $this->assertEmpty($dom->errors);
+ $this->assertEmpty($this->html5->getErrors());
- $dom = \HTML5::loadHTMLFile(__DIR__ . '/Html5Test.html');
+ $dom = $this->html5->loadHTMLFile(__DIR__ . '/Html5Test.html');
$this->assertInstanceOf('\DOMDocument', $dom);
- $this->assertEmpty($dom->errors);
+ $this->assertEmpty($this->html5->getErrors());
}
public function testLoadHTML() {
$contents = file_get_contents(__DIR__ . '/Html5Test.html');
- $dom = \HTML5::loadHTML($contents);
+ $dom = $this->html5->loadHTML($contents);
$this->assertInstanceOf('\DOMDocument', $dom);
- $this->assertEmpty($dom->errors);
+ $this->assertEmpty($this->html5->getErrors());
}
public function testLoadHTMLFragment() {
$fragment = '<section id="Foo"><div class="Bar">Baz</div></section>';
- $dom = \HTML5::loadHTMLFragment($fragment);
+ $dom = $this->html5->loadHTMLFragment($fragment);
$this->assertInstanceOf('\DOMDocumentFragment', $dom);
- $this->assertEmpty($dom->errors);
+ $this->assertEmpty($this->html5->getErrors());
}
public function testSaveHTML() {
- $dom = \HTML5::load(__DIR__ . '/Html5Test.html');
+ $dom = $this->html5->load(__DIR__ . '/Html5Test.html');
$this->assertInstanceOf('\DOMDocument', $dom);
- $this->assertEmpty($dom->errors);
+ $this->assertEmpty($this->html5->getErrors());
- $saved = \HTML5::saveHTML($dom);
+ $saved = $this->html5->saveHTML($dom);
$this->assertRegExp('|<p>This is a test.</p>|', $saved);
}
public function testSaveHTMLFragment() {
$fragment = '<section id="Foo"><div class="Bar">Baz</div></section>';
- $dom = \HTML5::loadHTMLFragment($fragment);
+ $dom = $this->html5->loadHTMLFragment($fragment);
- $string = \HTML5::saveHTML($dom);
+ $string = $this->html5->saveHTML($dom);
$this->assertEquals($fragment, $string);
}
public function testSave() {
- $dom = \HTML5::load(__DIR__ . '/Html5Test.html');
+ $dom = $this->html5->load(__DIR__ . '/Html5Test.html');
$this->assertInstanceOf('\DOMDocument', $dom);
- $this->assertEmpty($dom->errors);
+ $this->assertEmpty($this->html5->getErrors());
// Test resource
$file = fopen('php://temp', 'w');
- \HTML5::save($dom, $file);
+ $this->html5->save($dom, $file);
$content = stream_get_contents($file, -1, 0);
$this->assertRegExp('|<p>This is a test.</p>|', $content);
// Test file
$tmpfname = tempnam(sys_get_temp_dir(), "html5-php");
- \HTML5::save($dom, $tmpfname);
+ $this->html5->save($dom, $tmpfname);
$content = file_get_contents($tmpfname);
$this->assertRegExp('|<p>This is a test.</p>|', $content);
unlink($tmpfname);
@@ -89,33 +104,35 @@ class Html5Test extends TestCase {
// then tries to read that document again. This makes sure we are reading,
// and generating a document that works at a high level.
public function testItWorks() {
- $dom = \HTML5::load(__DIR__ . '/Html5Test.html');
+ $dom = $this->html5->load(__DIR__ . '/Html5Test.html');
$this->assertInstanceOf('\DOMDocument', $dom);
- $this->assertEmpty($dom->errors);
+ $this->assertEmpty($this->html5->getErrors());
- $saved = \HTML5::saveHTML($dom);
+ $saved = $this->html5->saveHTML($dom);
- $dom2 = \HTML5::loadHTML($saved);
+ $dom2 = $this->html5->loadHTML($saved);
$this->assertInstanceOf('\DOMDocument', $dom2);
- $this->assertEmpty($dom2->errors);
+ $this->assertEmpty($this->html5->getErrors());
}
public function testConfig() {
- $options = \HTML5::options();
+ $html5 = $this->getInstance();
+ $options = $html5->getOptions();
$this->assertEquals(FALSE, $options['encode_entities']);
- \HTML5::setOption('foo', 'bar');
- \HTML5::setOption('encode_entities', TRUE);
- $options = \HTML5::options();
+ $html5 = $this->getInstance(array('foo' => 'bar', 'encode_entities'=> TRUE));
+ $options = $html5->getOptions();
$this->assertEquals('bar', $options['foo']);
$this->assertEquals(TRUE, $options['encode_entities']);
// Need to reset to original so future tests pass as expected.
- \HTML5::setOption('encode_entities', FALSE);
+ //$this->getInstance()->setOption('encode_entities', FALSE);
+
}
public function testSvg() {
- $dom = \HTML5::loadHTML('<!doctype html>
+
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div id="foo" class="bar baz">foo bar baz</div>
@@ -132,7 +149,7 @@ class Html5Test extends TestCase {
</body>
</html>');
- $this->assertEmpty($dom->errors, print_r($dom->errors, TRUE));
+ $this->assertEmpty($this->html5->getErrors());
// Test a mixed case attribute.
$list = $dom->getElementsByTagName('svg');
@@ -149,14 +166,14 @@ class Html5Test extends TestCase {
$this->assertEquals('textPath', $textPath->tagName);
$this->assertNotEquals('textpath', $textPath->tagName);
- $html = \HTML5::saveHTML($dom);
+ $html = $this->html5->saveHTML($dom);
$this->assertRegExp('|<svg width="150" height="100" viewBox="0 0 3 2">|',$html);
$this->assertRegExp('|<rect width="1" height="2" x="0" fill="#008d46" />|',$html);
}
public function testMathMl() {
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div id="foo" class="bar baz" definitionURL="http://example.com">foo bar baz</div>
@@ -170,7 +187,7 @@ class Html5Test extends TestCase {
</body>
</html>');
- $this->assertEmpty($dom->errors);
+ $this->assertEmpty($this->html5->getErrors());
$list = $dom->getElementsByTagName('math');
$this->assertNotEmpty($list->length);
@@ -184,26 +201,25 @@ class Html5Test extends TestCase {
$this->assertEquals('http://www.example.com/mathops/multiops.html#plusminus', $csymbol->getAttribute('definitionURL'));
$this->assertFalse($csymbol->hasAttribute('definitionurl'));
- $html = \HTML5::saveHTML($dom);
+ $html = $this->html5->saveHTML($dom);
$this->assertRegExp('|<csymbol definitionURL="http://www.example.com/mathops/multiops.html#plusminus">|',$html);
$this->assertRegExp('|<mi>y</mi>|',$html);
}
public function testUnknownElements() {
-
// The : should not have special handling accourding to section 2.9 of the
// spec. This is differenant than XML. Since we don't know these elements
// they are handled as normal elements. Note, to do this is really
// an invalid example and you should not embed prefixed xml in html5.
- $dom = \HTML5::loadHTMLFragment("<f:rug>
+ $dom = $this->html5->loadHTMLFragment("<f:rug>
<f:name>Big rectangle thing</f:name>
<f:width>40</f:width>
<f:length>80</f:length>
</f:rug>
<sarcasm>um, yeah</sarcasm>");
- $this->assertEmpty($dom->errors);
- $markup = \HTML5::saveHTML($dom);
+ $this->assertEmpty($this->html5->getErrors());
+ $markup = $this->html5->saveHTML($dom);
$this->assertRegExp('|<f:name>Big rectangle thing</f:name>|',$markup);
$this->assertRegExp('|<sarcasm>um, yeah</sarcasm>|',$markup);
}
diff --git a/test/HTML5/Parser/DOMTreeBuilderTest.php b/test/HTML5/Parser/DOMTreeBuilderTest.php
index dde8393..ab5378a 100644
--- a/test/HTML5/Parser/DOMTreeBuilderTest.php
+++ b/test/HTML5/Parser/DOMTreeBuilderTest.php
@@ -347,3 +347,4 @@ class DOMTreeBuilderTest extends \HTML5\Tests\TestCase {
$this->assertEquals('foo', $div->textContent);
}
}
+
diff --git a/test/HTML5/Parser/EventStack.php b/test/HTML5/Parser/EventStack.php
index ffa4f12..acbe3f5 100644
--- a/test/HTML5/Parser/EventStack.php
+++ b/test/HTML5/Parser/EventStack.php
@@ -87,6 +87,4 @@ class EventStack implements EventHandler {
$this->store('pi', func_get_args());
}
-}
-class EventStackParseError extends \Exception {
-}
+} \ No newline at end of file
diff --git a/test/HTML5/Serializer/OutputRulesTest.php b/test/HTML5/Serializer/OutputRulesTest.php
index 8326ef9..34c530d 100644
--- a/test/HTML5/Serializer/OutputRulesTest.php
+++ b/test/HTML5/Serializer/OutputRulesTest.php
@@ -17,7 +17,10 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
<p>This is a test.</p>
</body>
</html>';
-
+ public function setUp()
+ {
+ $this->html5 = $this->getInstance();
+ }
/**
* Using reflection we make a protected method accessible for testing.
*
@@ -42,9 +45,9 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function getOutputRules($options = array()) {
- $options = $options + \HTML5::options();
+ $options = $options + $this->html5->getOptions();
$stream = fopen('php://temp', 'w');
- $dom = \HTML5::loadHTML($this->markup);
+ $dom = $this->html5->loadHTML($this->markup);
$r = new OutputRules($stream, $options);
$t = new Traverser($dom, $stream, $r, $options);
@@ -52,11 +55,11 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testDocument() {
- $dom = \HTML5::loadHTML('<!doctype html><html lang="en"><body>foo</body></html>');
+ $dom = $this->html5->loadHTML('<!doctype html><html lang="en"><body>foo</body></html>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$r->document($dom);
$expected = '<!DOCTYPE html>' . PHP_EOL . '<html lang="en"><body>foo</body></html>' . PHP_EOL;
@@ -64,11 +67,11 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testDoctype() {
- $dom = \HTML5::loadHTML('<!doctype html><html lang="en"><body>foo</body></html>');
+ $dom = $this->html5->loadHTML('<!doctype html><html lang="en"><body>foo</body></html>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$m = $this->getProtectedMethod('doctype');
$m->invoke($r, 'foo');
@@ -76,7 +79,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testElement() {
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div id="foo" class="bar baz">foo bar baz</div>
@@ -89,8 +92,8 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
</html>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$list = $dom->getElementsByTagName('div');
$r->element($list->item(0));
@@ -98,7 +101,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testOpenTag() {
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div id="foo" class="bar baz">foo bar baz</div>
@@ -106,8 +109,8 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
</html>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$list = $dom->getElementsByTagName('div');
$m = $this->getProtectedMethod('openTag');
@@ -116,7 +119,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testCData() {
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div><![CDATA[bar]]></div>
@@ -124,14 +127,14 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
</html>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$list = $dom->getElementsByTagName('div');
$r->cdata($list->item(0)->childNodes->item(0));
$this->assertEquals('<![CDATA[bar]]>', stream_get_contents($stream, -1, 0));
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div id="foo"></div>
@@ -142,8 +145,8 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
$dom->getElementById('foo')->appendChild(new \DOMCdataSection("]]>Foo<[![CDATA test ]]>"));
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$list = $dom->getElementsByTagName('div');
$r->cdata($list->item(0)->childNodes->item(0));
@@ -151,7 +154,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testComment() {
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div><!-- foo --></div>
@@ -159,15 +162,15 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
</html>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$list = $dom->getElementsByTagName('div');
$r->comment($list->item(0)->childNodes->item(0));
$this->assertEquals('<!-- foo -->', stream_get_contents($stream, -1, 0));
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div id="foo"></div>
@@ -176,8 +179,8 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
$dom->getElementById('foo')->appendChild(new \DOMComment('<!-- --> --> Foo -->'));
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$list = $dom->getElementsByTagName('div');
$r->comment($list->item(0)->childNodes->item(0));
@@ -188,7 +191,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testText() {
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<head>
<script>baz();</script>
@@ -196,22 +199,22 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
</html>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$list = $dom->getElementsByTagName('script');
$r->text($list->item(0)->childNodes->item(0));
$this->assertEquals('baz();', stream_get_contents($stream, -1, 0));
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<head id="foo"></head>
</html>');
$dom->getElementById('foo')->appendChild(new \DOMText('<script>alert("hi");</script>'));
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$item = $dom->getElementById('foo');
$r->text($item->firstChild);
@@ -276,7 +279,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testAttrs() {
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div id="foo" class="bar baz" disabled>foo bar baz</div>
@@ -284,8 +287,8 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
</html>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$list = $dom->getElementsByTagName('div');
@@ -297,7 +300,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testSvg() {
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div id="foo" class="bar baz">foo bar baz</div>
@@ -313,8 +316,8 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
</html>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$list = $dom->getElementsByTagName('svg');
$r->element($list->item(0));
@@ -325,7 +328,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testMath() {
- $dom = \HTML5::loadHTML('<!doctype html>
+ $dom = $this->html5->loadHTML('<!doctype html>
<html lang="en">
<body>
<div id="foo" class="bar baz">foo bar baz</div>
@@ -340,8 +343,8 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
</html>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$list = $dom->getElementsByTagName('math');
$r->element($list->item(0));
@@ -351,11 +354,11 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
}
function testProcessorInstruction() {
- $dom = \HTML5::loadHTMLFragment('<?foo bar ?>');
+ $dom = $this->html5->loadHTMLFragment('<?foo bar ?>');
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$r->processorInstruction($dom->firstChild);
$content = stream_get_contents($stream, -1, 0);
diff --git a/test/HTML5/Serializer/TraverserTest.php b/test/HTML5/Serializer/TraverserTest.php
index 7f5f5ed..c63ea2b 100644
--- a/test/HTML5/Serializer/TraverserTest.php
+++ b/test/HTML5/Serializer/TraverserTest.php
@@ -17,7 +17,10 @@ class TraverserTest extends \HTML5\Tests\TestCase {
<p>This is a test.</p>
</body>
</html>';
-
+ public function setUp()
+ {
+ $this->html5 = $this->getInstance();
+ }
/**
* Using reflection we make a protected method accessible for testing.
*
@@ -36,8 +39,9 @@ class TraverserTest extends \HTML5\Tests\TestCase {
function getTraverser() {
$stream = fopen('php://temp', 'w');
- $dom = \HTML5::loadHTML($this->markup);
- $t = new Traverser($dom, $stream, \HTML5::options());
+
+ $dom = $this->html5->loadHTML($this->markup);
+ $t = new Traverser($dom, $stream, $html5->getOptions());
// We return both the traverser and stream so we can pull from it.
return array($t, $stream);
@@ -49,10 +53,12 @@ class TraverserTest extends \HTML5\Tests\TestCase {
// use a stream in temp space.
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $dom = \HTML5::loadHTML($this->markup);
+ $html5 = $this->getInstance();
+
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $dom = $this->html5->loadHTML($this->markup);
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $t = new Traverser($dom, $stream, $r, $html5->getOptions());
$this->assertInstanceOf('\HTML5\Serializer\Traverser', $t);
}
@@ -60,13 +66,13 @@ class TraverserTest extends \HTML5\Tests\TestCase {
function testFragment() {
$html = '<span class="bar">foo</span><span></span><div>bar</div>';
$input = new \HTML5\Parser\StringInputStream($html);
- $dom = \HTML5::parseFragment($input);
+ $dom = $this->html5->parseFragment($input);
$this->assertInstanceOf('\DOMDocumentFragment', $dom);
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$out = $t->walk();
$this->assertEquals($html, stream_get_contents($stream, -1, 0));
@@ -75,13 +81,13 @@ class TraverserTest extends \HTML5\Tests\TestCase {
function testProcessorInstruction() {
$html = '<?foo bar ?>';
$input = new \HTML5\Parser\StringInputStream($html);
- $dom = \HTML5::parseFragment($input);
+ $dom = $this->html5->parseFragment($input);
$this->assertInstanceOf('\DOMDocumentFragment', $dom);
$stream = fopen('php://temp', 'w');
- $r = new OutputRules($stream, \HTML5::options());
- $t = new Traverser($dom, $stream, $r, \HTML5::options());
+ $r = new OutputRules($stream, $this->html5->getOptions());
+ $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
$out = $t->walk();
$this->assertEquals($html, stream_get_contents($stream, -1, 0));
diff --git a/test/HTML5/TestCase.php b/test/HTML5/TestCase.php
index 836614e..7e98498 100644
--- a/test/HTML5/TestCase.php
+++ b/test/HTML5/TestCase.php
@@ -9,6 +9,11 @@ class TestCase extends \PHPUnit_Framework_TestCase {
// Placeholder. Why is PHPUnit emitting warnings about no tests?
}
+ public function getInstance(array $options = array())
+ {
+ return new \HTML5($options);
+ }
+
protected function wrap($fragment) {
return self::DOC_OPEN . $fragment . self::DOC_CLOSE;
}