From 0226e0ca0dc70f9a0310b3eef045ee1c1e0ca3ac Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Dec 2022 20:00:46 +0300 Subject: split into a separate repo --- .../html5/test/HTML5/Serializer/TraverserTest.php | 136 +++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 vendor/masterminds/html5/test/HTML5/Serializer/TraverserTest.php (limited to 'vendor/masterminds/html5/test/HTML5/Serializer/TraverserTest.php') diff --git a/vendor/masterminds/html5/test/HTML5/Serializer/TraverserTest.php b/vendor/masterminds/html5/test/HTML5/Serializer/TraverserTest.php new file mode 100644 index 0000000..d4ae7b3 --- /dev/null +++ b/vendor/masterminds/html5/test/HTML5/Serializer/TraverserTest.php @@ -0,0 +1,136 @@ + + + + + Test + + +

This is a test.

+ + '; + + 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 + */ + public function getProtectedMethod($name) + { + $class = new \ReflectionClass('\Masterminds\HTML5\Serializer\Traverser'); + $method = $class->getMethod($name); + $method->setAccessible(true); + + return $method; + } + + public function getTraverser() + { + $stream = fopen('php://temp', 'w'); + + $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, + ); + } + + 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(); + + $r = new OutputRules($stream, $this->html5->getOptions()); + $dom = $this->html5->loadHTML($this->markup); + + $t = new Traverser($dom, $stream, $r, $html5->getOptions()); + + $this->assertInstanceOf('\Masterminds\HTML5\Serializer\Traverser', $t); + } + + public function testFragmentDeprecated() + { + $html = 'foo
bar
'; + $input = new \Masterminds\HTML5\Parser\StringInputStream($html); + $dom = $this->html5->parseFragment($input); + + $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()); + $t->walk(); + + $this->assertEquals($html, stream_get_contents($stream, -1, 0)); + } + + public function testFragment() + { + $html = 'foo
bar
'; + $dom = $this->html5->parseFragment($html); + + $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()); + $t->walk(); + + $this->assertEquals($html, stream_get_contents($stream, -1, 0)); + } + + public function testProcessorInstructionDeprecated() + { + $html = ''; + $input = new \Masterminds\HTML5\Parser\StringInputStream($html); + $dom = $this->html5->parseFragment($input); + + $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()); + $t->walk(); + + $this->assertEquals($html, stream_get_contents($stream, -1, 0)); + } + + public function testProcessorInstruction() + { + $html = ''; + $dom = $this->html5->parseFragment($html); + + $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()); + $t->walk(); + + $this->assertEquals($html, stream_get_contents($stream, -1, 0)); + } +} -- cgit v1.2.3