コード例 #1
0
ファイル: HelperTest.php プロジェクト: trashtoy/peach2
 /**
  * createNode() のテストです. 引数によって, 以下の結果が返ることを確認します.
  * 
  * - {@link Node} 型オブジェクトの場合: 引数自身
  * - {@link NodeList} 型オブジェクトの場合: 引数自身
  * - {@link HelperObject} 型オブジェクトの場合: 引数のオブジェクトがラップしているノード
  * - 文字列の場合: 引数の文字列を要素名に持つ新しい {@link Element}
  * - null または空文字列の場合: 空の {@link NodeList}
  * - それ以外: 引数の文字列表現のテキストノード
  * 
  * @covers Peach\Markup\Helper::createNode
  * @covers Peach\Markup\Helper::createElement
  */
 public function testCreateNode()
 {
     $h = $this->object;
     $node = new EmptyElement("br");
     $this->assertSame($node, $h->createNode($node));
     $nodeList = new NodeList(array("First", "Second", "Third"));
     $this->assertSame($nodeList, $h->createNode($nodeList));
     $div = new ContainerElement("div");
     $div->setAttribute("id", "test");
     $div->append("Sample Text");
     $ho = $h->createObject($div);
     $this->assertSame($div, $h->createNode($ho));
     $p = new ContainerElement("p");
     $this->assertEquals($p, $h->createNode("p"));
     $emptyList = new NodeList();
     $this->assertEquals($emptyList, $h->createNode(null));
     $this->assertEquals($emptyList, $h->createNode(""));
     $datetime = new Datetime(2012, 5, 21, 7, 34);
     $textNode = new Text("2012-05-21 07:34");
     $this->assertEquals($textNode, $h->createNode($datetime));
 }
コード例 #2
0
ファイル: HelperObject.php プロジェクト: trashtoy/peach2
 /**
  * このオブジェクトをプロトタイプとして, 新しい HelperObject を生成します.
  * 
  * @return Element
  */
 private function createPrototype()
 {
     $original = $this->node;
     if ($original instanceof ContainerElement) {
         $node = new ContainerElement($original->getName());
         $node->setAttributes($original->getAttributes());
         return $node;
     }
     if ($original instanceof EmptyElement) {
         $node = new EmptyElement($original->getName());
         $node->setAttributes($original->getAttributes());
         return $node;
     }
     return null;
 }
コード例 #3
0
ファイル: HelperObjectTest.php プロジェクト: trashtoy/peach2
 /**
  * getChildNodes() のテストです. 以下を確認します.
  * 
  * - このオブジェクトがラップしているノードが Container だった場合はそのノードの childNodes() の結果を返すこと
  * - それ以外は空配列を返すこと
  * 
  * @covers Peach\Markup\HelperObject::getChildNodes
  */
 public function testGetChildNodes()
 {
     $h = $this->helper;
     $expected = array(new Text("First"), new Text("Second"), new Text("Third"));
     $p = new ContainerElement("p");
     $p->append("First");
     $p->append("Second");
     $p->append("Third");
     $obj1 = new HelperObject($h, $p);
     $this->assertEquals($expected, $obj1->getChildNodes());
     $text = new Text("This is test");
     $obj2 = new HelperObject($h, $text);
     $this->assertSame(array(), $obj2->getChildNodes());
 }