protected function setUp() { $this->Document = new Document('1.0', 'utf-8', 'DOMElement'); $this->Document->loadHTML(self::HTML); $this->Serializable = $this->Document; $this->Serializer = new \BLW\Model\Serializer\Mock(); }
/** * Set the inner HTML of an element. * * @link http://www.php.net/manual/en/function.mb-check-encoding.php mb_check_encoding() * * @throws \BLW\Model\DOM\Exception If * * <ul> * <li><code>$HTML</code> is not properly encoded.</li> * <li>Element has no document.</li> * </ul> * * @param string $HTML * Raw HTML. * @param string $Encoding * See mb_check_encoding() * @return \BLW\Type\DOM\IElement $this. <code>FALSE</code> on error. */ public function setInnerHTML($HTML, $Encoding = 'UTF-8') { // Is Node writable? if (!$this->ownerDocument instanceof DOMDocument) { throw new DOMException('Cannot modify readonly element'); // Is $HTML properly encoded? } elseif (!mb_check_encoding($HTML, $Encoding)) { throw new DOMException('Invalid encoding'); } $HTML = @sprintf("<%1\$s>{$HTML}</%1\$s>", $this->tagName); // Parse Elements $Document = new Document('1.0', $Encoding, get_class($this)); if (@$Document->loadHTML(sprintf($HTML))) { $New = $Document->getElementsByTagName($this->tagName)->item(0); // Remove children while ($Node = $this->firstChild) { $this->removeChild($Node); } // Add new children foreach ($New as $Node) { if ($Node = $this->ownerDocument->importNode($Node, true)) { $this->appendChild($Node); } } } // Done return $this; }
/** * Creates a default page for exceptional errors / responses. * * @param \BLW\Type\HTTP\IRequest $Request * [optional] Request that produced timeout. * @return \BLW\Type\HTTP\Browser\IPage Generated Page. */ public function createUnknownPage(IRequest $Request = null) { $Request = $Request ?: new Request(); // Create Document $Document = new Document(); $HTML = "<html>\r\n<head><title>Untitled</title></head>\r\n<body bgcolor=\"white\"></body>\r\n</html>\r\n"; $Document->loadHTML($HTML); // Create Page $Base = $Request->URI ?: new GenericURI('about:none'); $Page = new HTMLPage($Document, $Base, $Request->Header, new RFC2616Head(), $this->_Mediator); // Done return $Page; }