diff options
Diffstat (limited to 'test/HTML5/Serializer/TraverserTest.php')
-rw-r--r-- | test/HTML5/Serializer/TraverserTest.php | 122 |
1 files changed, 66 insertions, 56 deletions
diff --git a/test/HTML5/Serializer/TraverserTest.php b/test/HTML5/Serializer/TraverserTest.php index 2fecc9c..c914633 100644 --- a/test/HTML5/Serializer/TraverserTest.php +++ b/test/HTML5/Serializer/TraverserTest.php @@ -5,9 +5,10 @@ use Masterminds\HTML5\Serializer\OutputRules; use Masterminds\HTML5\Serializer\Traverser; use Masterminds\HTML5\Parser; -class TraverserTest extends \Masterminds\HTML5\Tests\TestCase { +class TraverserTest extends \Masterminds\HTML5\Tests\TestCase +{ - protected $markup = '<!doctype html> + protected $markup = '<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> @@ -17,79 +18,88 @@ class TraverserTest extends \Masterminds\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. - * - * @param string $name - * The name of the method on the Traverser class to test. - * - * @return \ReflectionMethod - * \ReflectionMethod for the specified method - */ - function getProtectedMethod($name) { - $class = new \ReflectionClass('\Masterminds\HTML5\Serializer\Traverser'); - $method = $class->getMethod($name); - $method->setAccessible(true); - return $method; - } - function getTraverser() { - $stream = fopen('php://temp', 'w'); + /** + * Using reflection we make a protected method accessible for testing. + * + * @param string $name + * The name of the method on the Traverser class to test. + * + * @return \ReflectionMethod \ReflectionMethod for the specified method + */ + public function getProtectedMethod($name) + { + $class = new \ReflectionClass('\Masterminds\HTML5\Serializer\Traverser'); + $method = $class->getMethod($name); + $method->setAccessible(true); + + return $method; + } - $dom = $this->html5->loadHTML($this->markup); - $t = new Traverser($dom, $stream, $html5->getOptions()); + public function getTraverser() + { + $stream = fopen('php://temp', 'w'); - // We return both the traverser and stream so we can pull from it. - return array($t, $stream); - } + $dom = $this->html5->loadHTML($this->markup); + $t = new Traverser($dom, $stream, $html5->getOptions()); - function testConstruct() { + // We return both the traverser and stream so we can pull from it. + return array( + $t, + $stream + ); + } - // The traverser needs a place to write the output to. In our case we - // use a stream in temp space. - $stream = fopen('php://temp', 'w'); + public function testConstruct() + { + // The traverser needs a place to write the output to. In our case we + // use a stream in temp space. + $stream = fopen('php://temp', 'w'); - $html5 = $this->getInstance(); + $html5 = $this->getInstance(); - $r = new OutputRules($stream, $this->html5->getOptions()); - $dom = $this->html5->loadHTML($this->markup); + $r = new OutputRules($stream, $this->html5->getOptions()); + $dom = $this->html5->loadHTML($this->markup); - $t = new Traverser($dom, $stream, $r, $html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $html5->getOptions()); - $this->assertInstanceOf('\Masterminds\HTML5\Serializer\Traverser', $t); - } + $this->assertInstanceOf('\Masterminds\HTML5\Serializer\Traverser', $t); + } - function testFragment() { - $html = '<span class="bar">foo</span><span></span><div>bar</div>'; - $input = new \Masterminds\HTML5\Parser\StringInputStream($html); - $dom = $this->html5->parseFragment($input); + public function testFragment() + { + $html = '<span class="bar">foo</span><span></span><div>bar</div>'; + $input = new \Masterminds\HTML5\Parser\StringInputStream($html); + $dom = $this->html5->parseFragment($input); - $this->assertInstanceOf('\DOMDocumentFragment', $dom); + $this->assertInstanceOf('\DOMDocumentFragment', $dom); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $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)); - } + $out = $t->walk(); + $this->assertEquals($html, stream_get_contents($stream, - 1, 0)); + } - function testProcessorInstruction() { - $html = '<?foo bar ?>'; - $input = new \Masterminds\HTML5\Parser\StringInputStream($html); - $dom = $this->html5->parseFragment($input); + public function testProcessorInstruction() + { + $html = '<?foo bar ?>'; + $input = new \Masterminds\HTML5\Parser\StringInputStream($html); + $dom = $this->html5->parseFragment($input); - $this->assertInstanceOf('\DOMDocumentFragment', $dom); + $this->assertInstanceOf('\DOMDocumentFragment', $dom); - $stream = fopen('php://temp', 'w'); - $r = new OutputRules($stream, $this->html5->getOptions()); - $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + $stream = fopen('php://temp', 'w'); + $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)); - } + $out = $t->walk(); + $this->assertEquals($html, stream_get_contents($stream, - 1, 0)); + } } |