You are here

public function OutputRulesTest::testText in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/masterminds/html5/test/HTML5/Serializer/OutputRulesTest.php \Masterminds\HTML5\Tests\Serializer\OutputRulesTest::testText()

File

vendor/masterminds/html5/test/HTML5/Serializer/OutputRulesTest.php, line 326

Class

OutputRulesTest

Namespace

Masterminds\HTML5\Tests\Serializer

Code

public function testText() {
  $dom = $this->html5
    ->loadHTML('<!doctype html>
    <html lang="en">
      <head>
        <script>baz();</script>
      </head>
    </html>');
  $stream = fopen('php://temp', 'w');
  $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 = $this->html5
    ->loadHTML('<!doctype html>
    <html lang="en">
      <head id="foo"></head>
    </html>');
  $foo = $dom
    ->getElementById('foo');
  $foo
    ->appendChild(new \DOMText('<script>alert("hi");</script>'));
  $stream = fopen('php://temp', 'w');
  $r = new OutputRules($stream, $this->html5
    ->getOptions());
  $t = new Traverser($dom, $stream, $r, $this->html5
    ->getOptions());
  $r
    ->text($foo->firstChild);
  $this
    ->assertEquals('&lt;script&gt;alert("hi");&lt;/script&gt;', stream_get_contents($stream, -1, 0));
}