/** * 空要素タグの出力をテストします. * * @covers Peach\Markup\SgmlRenderer::formatEmptyTag * @covers Peach\Markup\SgmlRenderer::formatEmptyTagSuffix * @covers Peach\Markup\AbstractRenderer::formatTagPrefix */ public function testFormatEmptyTag() { $obj = $this->object; $e1 = new EmptyElement("br"); $this->assertSame("<br>", $obj->formatEmptyTag($e1)); $e2 = new EmptyElement("img"); $e2->setAttributes(array("src" => "test.png", "alt" => "TEST")); $this->assertSame('<img src="test.png" alt="TEST">', $obj->formatEmptyTag($e2)); }
/** * @return ContainerElement */ private static function createForm() { $text = new EmptyElement("input"); $text->setAttributes(array("type" => "text", "name" => "param1", "value" => "")); $br = new EmptyElement("br"); $check = new EmptyElement("input"); $check->setAttributes(array("type" => "checkbox", "name" => "flag1", "value" => "1")); $check->setAttribute("checked"); $submit = new EmptyElement("input"); $submit->setAttributes(array("type" => "submit", "name" => "submit", "value" => "Send")); $form = new ContainerElement("form"); $form->setAttributes(array("method" => "post", "action" => "sample.php")); $form->append("Name"); $form->append($text); $form->append($br); $form->append($check); $form->append("Enable something"); $form->append($br); $form->append($submit); return $form; }
/** * EmptyElement ノードのデバッグ文字列を出力します. * 出力内容は以下の通りです. * * <code> * EmptyElement(tagName) * </code> * * @param EmptyElement $node */ public function handleEmptyElement(EmptyElement $node) { $name = $node->getName(); $this->append("EmptyElement({$name})"); }
/** * Context の handleEmptyElement() が呼び出されることを確認します. * @covers Peach\Markup\EmptyElement::accept */ public function testAccept() { $context = new TestContext(); $this->object->accept($context); $this->assertSame("handleEmptyElement", $context->getResult()); }
/** * handleEmptyElement のテストです. 以下を確認します. * * - SGML 形式の場合 "<tagName>" となること * - XML 形式の場合 "<tagName />" となること * * @covers Peach\Markup\DefaultContext::handleEmptyElement * @covers Peach\Markup\DefaultContext::indent */ public function testHandleEmptyElement() { $input = new EmptyElement("input"); $input->setAttributes(array("type" => "checkbox", "name" => "flag", "value" => 1)); $input->setAttribute("checked"); $expected1 = '<input type="checkbox" name="flag" value="1" checked="checked" />'; $obj1 = new DefaultContext(XmlRenderer::getInstance()); $obj1->handleEmptyElement($input); $this->assertSame($expected1, $obj1->getResult()); $expected2 = '<input type="checkbox" name="flag" value="1" checked>'; $obj2 = new DefaultContext(SgmlRenderer::getInstance()); $obj2->handleEmptyElement($input); $this->assertSame($expected2, $obj2->getResult()); }
/** * handleNodeList() のテストです. * * @covers Peach\Markup\DebugContext::handleNodeList * @covers Peach\Markup\DebugContext::startNode * @covers Peach\Markup\DebugContext::handleContainer * @covers Peach\Markup\DebugContext::endNode */ public function testHandleNodeList() { $expected = implode("\r\n", array("NodeList {", " Comment {", " Text", " }", " EmptyElement(img)", " Text", "}")) . "\r\n"; $nodeList = new NodeList(); $comment = new Comment(); $comment->append("This is test comment"); $img = new EmptyElement("img"); $img->setAttributes(array("src" => "test.jpg", "alt" => "")); $nodeList->append($comment); $nodeList->append($img); $nodeList->append("Test image"); $context = $this->object; $this->expectOutputString($expected); $context->handleNodeList($nodeList); $this->assertSame($expected, $context->getResult()); }