/** * Long test helps test ordering is proper */ public function testHeaders() { $scriptHeader = '<script>alert("hello");</script>'; $this->document->addHeader($scriptHeader); $this->assertEquals($this->normalizeHtml($this->document->getHeaders()), $this->normalizeHtml($scriptHeader)); $metaName = '&dks;<'; $metaContent = "&%/><"; $attr = '$<>&sl'; $attributes = array('attr' => $attr); $metaCompare = '<meta name="' . Html::sanitize($metaName) . '" content="' . Html::sanitize($metaContent) . '" attr="' . Html::sanitize($attr) . '" />'; $this->document->addMeta($metaName, $metaContent, $attributes); $this->assertEquals($this->normalizeHtml($this->document->getHeaders()), $this->normalizeHtml($scriptHeader . ' ' . $metaCompare)); $prepended = '<link rel="test" />'; $this->document->prependHeader($prepended); $this->assertEquals($this->normalizeHtml($this->document->getHeaders()), $this->normalizeHtml($prepended . ' ' . $scriptHeader . ' ' . $metaCompare)); $scriptSrc = '&adsd'; $scriptCompare = '<script type="text/javascript" src="' . Html::sanitize($scriptSrc) . '"></script>'; $this->document->addScript($scriptSrc); $this->document->addScript($scriptSrc, true); $this->assertEquals($this->normalizeHtml($this->document->getHeaders()), $this->normalizeHtml($scriptCompare . ' ' . $prepended . ' ' . $scriptHeader . ' ' . $metaCompare . ' ' . $scriptCompare)); $cssHref = '&?></'; $cssCompare = '<link rel="stylesheet" type="text/css" href="' . Html::sanitize($cssHref) . '" />'; $this->document->addStylesheet($cssHref); $this->document->addStylesheet($cssHref, true); $this->assertEquals($this->normalizeHtml($this->document->getHeaders()), $this->normalizeHtml($cssCompare . ' ' . $scriptCompare . ' ' . $prepended . ' ' . $scriptHeader . ' ' . $metaCompare . ' ' . $scriptCompare . ' ' . $cssCompare)); $title = '<&asdasd&;'; $titleCompare = '<title>' . Html::sanitize($title) . '</title>'; $this->document->setTitle($title); $this->assertEquals($this->normalizeHtml($this->document->getHeaders()), $this->normalizeHtml($cssCompare . ' ' . $scriptCompare . ' ' . $prepended . ' ' . $scriptHeader . ' ' . $metaCompare . ' ' . $scriptCompare . ' ' . $cssCompare . ' ' . $titleCompare)); $this->document->removeHeaders(); $this->assertEquals($this->document->getHeaders(), ''); }
/** * Sanitizes HTML output * * @param string $string */ protected function sanitize($string) { return HtmlOutput::sanitize($string); }
/** * @param $string * @param $characters * @param $expected * * @dataProvider excerptProvider */ public function testExcerpt($string, $characters, $expected) { $this->assertEquals($expected, Html::excerpt($string, $characters)); }
/** * @param $string * * @return string */ protected function e($string) { return Html::sanitize($string); }