You are here

function OutputRulesTest::testSerializeWithNamespaces in Zircon Profile 8

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

File

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

Class

OutputRulesTest

Namespace

Masterminds\HTML5\Tests\Serializer

Code

function testSerializeWithNamespaces() {
  $this->html5 = $this
    ->getInstance(array(
    'xmlNamespaces' => true,
  ));
  $source = '
            <!DOCTYPE html>
            <html><body id="body" xmlns:x="http://www.prefixed.com">
                    <a id="bar1" xmlns="http://www.prefixed.com/bar1">
                        <b id="bar4" xmlns="http://www.prefixed.com/bar4"><x:prefixed id="prefixed">xy</x:prefixed></b>
                    </a>
                    <svg id="svg">svg</svg>
                    <c id="bar2" xmlns="http://www.prefixed.com/bar2"></c>
                    <div id="div"></div>
                    <d id="bar3"></d>
                    <xn:d id="bar5" xmlns:xn="http://www.prefixed.com/xn" xmlns="http://www.prefixed.com/bar5_x"><x id="bar5_x">y</x></xn:d>
                </body>
            </html>';
  $dom = $this->html5
    ->loadHTML($source, array(
    'xmlNamespaces' => true,
  ));
  $this
    ->assertFalse($this->html5
    ->hasErrors(), print_r($this->html5
    ->getErrors(), 1));
  $stream = fopen('php://temp', 'w');
  $r = new OutputRules($stream, $this->html5
    ->getOptions());
  $t = new Traverser($dom, $stream, $r, $this->html5
    ->getOptions());
  $t
    ->walk();
  $rendered = stream_get_contents($stream, -1, 0);
  $clear = function ($s) {
    return trim(preg_replace('/[\\s]+/', " ", $s));
  };
  $this
    ->assertEquals($clear($source), $clear($rendered));
}