/** * false を返すことを確認します. * @covers Peach\Markup\MinimalBreakControl::breaks */ public function testBreaks() { $node = new ContainerElement("span"); $node->append("first text"); $node->append("second test"); $this->assertFalse($this->object->breaks($node)); }
/** * 自分自身を含むノードを append しようとした場合に例外をスローすることを確認します. * * @covers Peach\Markup\NodeList::append * @covers Peach\Markup\NodeList::checkOwner * @expectedException \InvalidArgumentException */ public function testAppendFail() { $a = new ContainerElement("a"); $b = new ContainerElement("b"); $c = new ContainerElement("c"); $nodeList = new NodeList(array($a, $b, $c)); $c->append($nodeList); }
/** * 強制的に改行する (または強制的に改行しない) 要素名のリストをもとに, * 指定された要素を改行するかどうかを決定します. * 改行リスト・非改行リストの両方に含まれている要素名の場合は, * 改行リストのほうが優先されます. (つまり常に改行されます) * * 改行リスト・非改行リストのいずれにも含まれない場合は, * オリジナルの BreakControl の結果を返します. * * @param ContainerElement $node * @return bool */ public function breaks(ContainerElement $node) { $name = $node->getName(); if (in_array($name, $this->breakNames)) { return true; } if (in_array($name, $this->noBreakNames)) { return false; } return parent::breaks($node); }
/** * ラップ対象のオブジェクトと同じ結果を返すことを確認します. * @covers Peach\Markup\BreakControlWrapper::breaks */ public function testBreaks() { $obj = $this->object; $e5 = new ContainerElement("span"); $e5->append("some text"); $this->assertFalse($obj->breaks($e5)); $e6 = new ContainerElement("span"); $e6->append("first text"); $e6->append("second test"); $this->assertTrue($obj->breaks($e6)); }
/** * 開始タグの出力をテストします. * * @covers Peach\Markup\SgmlRenderer::formatStartTag * @covers Peach\Markup\SgmlRenderer::formatAttribute * @covers Peach\Markup\SgmlRenderer::formatBooleanAttribute */ public function testFormatStartTag() { $obj = $this->object; $e1 = new ContainerElement("testTag"); $this->assertSame("<testTag>", $obj->formatStartTag($e1)); $e2 = new ContainerElement("test1"); $e2->setAttributes(array("name" => "hoge", "value" => "123")); $e2->setAttribute("option"); $this->assertSame('<test1 name="hoge" value="123" option>', $obj->formatStartTag($e2)); $e3 = new ContainerElement("test2"); $e3->setAttributes(array("name" => "fuga", "option1" => null, "option2" => null, "value" => 234)); $this->assertSame('<test2 name="fuga" option1 option2 value="234">', $obj->formatStartTag($e3)); }
/** * 指定された要素の開始タグの後ろに改行を付けるかどうかを決定します. * 条件は以下の通りです. * * - もしも指定された要素に子要素がない場合は改行なし * - 子要素を一つだけ含み, それが整形済テキストの場合は改行あり * - 子要素を一つだけ含み, それがコンテナ要素の場合, 再帰的にチェックした結果 * - 子要素を一つだけ含み, 上記以外のノードの場合は改行なし * - 子要素が二つ以上の場合は改行あり * * @param ContainerElement $node * @return bool */ public function breaks(ContainerElement $node) { $size = $node->size(); switch ($size) { case 0: return false; case 1: $childNodes = $node->getChildNodes(); $child = $childNodes[0]; if ($child instanceof Code) { return true; } if ($child instanceof ContainerElement) { return $this->breaks($child); } return false; default: return true; } }
/** * @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; }
/** * breaks() をテストします. * 以下を確認します. * * - 子ノードを持たない要素の場合は false * - 子要素を一つだけ含み, それが整形済テキストの場合は true * - 子要素を一つだけ含み, それがコンテナ要素の場合, 再帰的にチェックした結果 * - 子要素を一つだけ含み, 上記以外のノードの場合は false * - 子要素が二つ以上の場合は true * * @covers Peach\Markup\DefaultBreakControl::breaks */ public function testBreaks() { $obj = $this->object; $e1 = new ContainerElement("empty"); $this->assertFalse($obj->breaks($e1)); $e2 = new ContainerElement("pre"); $e2->append(new Code("some script")); $this->assertTrue($obj->breaks($e2)); $e3 = new ContainerElement("container"); $e3->append($e1); $this->assertFalse($obj->breaks($e3)); $e4 = new ContainerElement("container"); $e4->append($e2); $this->assertTrue($obj->breaks($e4)); $e5 = new ContainerElement("span"); $e5->append("some text"); $this->assertFalse($obj->breaks($e5)); $e6 = new ContainerElement("span"); $e6->append("first text"); $e6->append("second test"); $this->assertTrue($obj->breaks($e6)); }
/** * ContainerElement ノードのデバッグ文字列を出力します. * 出力内容は以下の通りです. * * <code> * ContainerElement(tagName) { * # 子ノードの出力内容 * } * </code> * * @param ContainerElement $node */ public function handleContainerElement(ContainerElement $node) { $name = $node->getName(); $this->startNode("ContainerElement({$name})"); $this->handleContainer($node); $this->endNode(); }
/** * @return ContainerElement */ private function createSampleSelectNode2() { $select = new ContainerElement("select"); $grp1 = new ContainerElement("optgroup"); $grp1->setAttribute("label", "Fruit"); $select->append($grp1); $grp2 = new ContainerElement("optgroup"); $grp2->setAttribute("label", "Dessert"); $select->append($grp2); $other = new ContainerElement("option"); $other->setAttribute("value", "8"); $other->append("Others"); $select->append($other); $opt1 = new ContainerElement("option"); $opt1->setAttribute("value", "1"); $opt1->append("Apple"); $grp1->append($opt1); $opt2 = new ContainerElement("option"); $opt2->setAttribute("value", "2"); $opt2->append("Orange"); $grp1->append($opt2); $opt3 = new ContainerElement("option"); $opt3->setAttribute("value", "3"); $opt3->append("Pear"); $grp1->append($opt3); $opt4 = new ContainerElement("option"); $opt4->setAttribute("value", "4"); $opt4->append("Peach"); $grp1->append($opt4); $opt5 = new ContainerElement("option"); $opt5->setAttribute("value", "5"); $opt5->append("Chocolate"); $grp2->append($opt5); $opt6 = new ContainerElement("option"); $opt6->setAttribute("value", "6"); $opt6->setAttribute("selected"); $opt6->append("Doughnut"); $grp2->append($opt6); $opt7 = new ContainerElement("option"); $opt7->setAttribute("value", "7"); $opt7->append("Ice cream"); $grp2->append($opt7); return $select; }
/** * NodeList に含まれる各子ノードを handle することを確認します. * * @covers Peach\Markup\DefaultContext::handleNodeList * @covers Peach\Markup\DefaultContext::formatChildNodes * @covers Peach\Markup\DefaultContext::breakCode */ public function testHandleNodeList() { $node1 = new EmptyElement("empty"); $node2 = new Text("Sample Text"); $node3 = new ContainerElement("container"); $node3->append("TEST"); $nodeList = new NodeList(); $nodeList->append($node1); $nodeList->append($node2); $nodeList->append($node3); $expected = implode("\r\n", array('<empty />', 'Sample Text', '<container>TEST</container>')); $this->object->handleNodeList($nodeList); $this->assertSame($expected, $this->object->getResult()); }
/** * Context の handleContainerElement() が呼び出されることを確認します. * * @covers Peach\Markup\ContainerElement::accept */ public function testAccept() { $context = new TestContext(); $this->object->accept($context); $this->assertSame("handleContainerElement", $context->getResult()); }
/** * handleContainerElement() のテストです. * * @covers Peach\Markup\DebugContext::handleContainerElement * @covers Peach\Markup\DebugContext::startNode * @covers Peach\Markup\DebugContext::handleContainer * @covers Peach\Markup\DebugContext::endNode */ public function testHandleContainerElement() { $expected = implode("\r\n", array("ContainerElement(div) {", " Text", "}")) . "\r\n"; $context = $this->object; $container = new ContainerElement("div"); $container->append("This is test"); $this->expectOutputString($expected); $context->handleContainerElement($container); $this->assertSame($expected, $context->getResult()); }