/** * We test both at once * * @return void */ public function testIsAndSetHtml5() { // Check true $this->object->setHtml5(true); $this->assertThat($this->object->isHtml5(), $this->isTrue(), 'JDocumentHtml::setHtml5(true) did not work'); // Check false $this->object->setHtml5(false); $this->assertThat($this->object->isHtml5(), $this->isFalse(), 'JDocumentHtml::setHtml5(false) did not work'); // Check non-boolean $this->object->setHtml5('non boolean'); $this->assertThat($this->object->isHtml5(), $this->logicalNot($this->equalTo('non boolean')), "JDocumentHtml::setHtml5('non boolean') did not work"); }
/** * @testdox Test the default return for isHtml5 */ public function testTheDefaultReturnForIsHtml5() { $this->assertNull($this->object->isHtml5()); }
/** * Manual head render * @return string */ public function renderHead() { $document = $this->doc; $docData = $document->getHeadData(); $html = array(); $isHtml5 = method_exists($this->doc, 'isHtml5') && $this->doc->isHtml5(); // Generate charset when using HTML5 (should happen first) if ($isHtml5) { $html[] = '<meta charset="' . $document->getCharset() . '" />'; } // Generate base tag (need to happen early) $base = $document->getBase(); if (!empty($base)) { $html[] = '<base href="' . $document->getBase() . '" />'; } // Generate META tags (needs to happen as early as possible in the head) foreach ($docData['metaTags'] as $type => $tag) { foreach ($tag as $name => $content) { if ($type == 'http-equiv' && !($isHtml5 && $name == 'content-type')) { $html[] = '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content) . '" />'; } elseif ($type == 'standard' && !empty($content)) { $html[] = '<meta name="' . $name . '" content="' . htmlspecialchars($content) . '" />'; } } } if ($docData['description']) { $html[] = '<meta name="description" content="' . htmlspecialchars($docData['description']) . '" />'; } if ($generator = $document->getGenerator()) { $html[] = '<meta name="generator" content="' . htmlspecialchars($generator) . '" />'; } $html[] = '<title>' . htmlspecialchars($docData['title'], ENT_COMPAT, 'UTF-8') . '</title>'; // Generate stylesheet links foreach ($docData['styleSheets'] as $strSrc => $strAttr) { $tag = '<link rel="stylesheet" href="' . $strSrc . '"'; if (!is_null($strAttr['mime']) && (!$isHtml5 || $strAttr['mime'] != 'text/css')) { $tag .= ' type="' . $strAttr['mime'] . '"'; } if (!is_null($strAttr['media'])) { $tag .= ' media="' . $strAttr['media'] . '"'; } if ($temp = JArrayHelper::toString($strAttr['attribs'])) { $tag .= ' ' . $temp; } $tag .= ' />'; $html[] = $tag; } // Generate script file links foreach ($docData['scripts'] as $strSrc => $strAttr) { $tag = '<script src="' . $strSrc . '"'; $defaultMimes = array('text/javascript', 'application/javascript', 'text/x-javascript', 'application/x-javascript'); if (!is_null($strAttr['mime']) && (!$isHtml5 || !in_array($strAttr['mime'], $defaultMimes))) { $tag .= ' type="' . $strAttr['mime'] . '"'; } if ($strAttr['defer']) { $tag .= ' defer="defer"'; } if ($strAttr['async']) { $tag .= ' async="async"'; } $tag .= '></script>'; $html[] = $tag; } // add custom foreach ($docData['custom'] as $custom) { $html[] = $custom; } return implode("\n ", $html) . "\n\n"; }