diff options
author | Matt Farina <[email protected]> | 2013-06-03 19:45:43 -0400 |
---|---|---|
committer | Matt Farina <[email protected]> | 2013-06-03 19:45:43 -0400 |
commit | c8718f5c94289e32f58c8c108cffb5b3f06f0d06 (patch) | |
tree | 8c5bc2c87a464fa9dfc83a17177cdec3678abb09 /test/HTML5 | |
parent | b766756c27be53c82268d06a879641ebb1f696aa (diff) |
Added tests to fill out the HTML5 class.
Diffstat (limited to 'test/HTML5')
-rw-r--r-- | test/HTML5/Html5Test.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/HTML5/Html5Test.php b/test/HTML5/Html5Test.php index 2d6e005..12be708 100644 --- a/test/HTML5/Html5Test.php +++ b/test/HTML5/Html5Test.php @@ -18,6 +18,34 @@ class Html5Test extends TestCase { $this->assertEmpty($dom->errors); } + public function testSaveHTML() { + $dom = \HTML5::load(__DIR__ . '/Html5Test.html'); + $this->assertInstanceOf('\DOMDocument', $dom); + $this->assertEmpty($dom->errors); + + $saved = \HTML5::saveHTML($dom); + $this->assertRegExp('|<p>This is a test.</p>|', $saved); + } + + public function testSave() { + $dom = \HTML5::load(__DIR__ . '/Html5Test.html'); + $this->assertInstanceOf('\DOMDocument', $dom); + $this->assertEmpty($dom->errors); + + // Test resource + $file = fopen('php://temp', 'w'); + \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); + $content = file_get_contents($tmpfname); + $this->assertRegExp('|<p>This is a test.</p>|', $content); + unlink($tmpfname); + } + // This test reads a document into a dom, turn the dom into a document, // then tries to read that document again. This makes sure we are reading, // and generating a document that works at a high level. @@ -33,4 +61,19 @@ class Html5Test extends TestCase { $this->assertEmpty($dom2->errors); } + public function testConfig() { + $options = \HTML5::options(); + $this->assertEquals(FALSE, $options['encode_entities']); + $this->assertEquals('\HTML5\Serializer\OutputRules', $options['output_rules']); + + \HTML5::setOption('foo', 'bar'); + \HTML5::setOption('encode_entities', TRUE); + $options = \HTML5::options(); + $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); + } + } |