public function addTag($tag, atoum\template $template) { $children = $template->getChildren(); while (($child = array_shift($children)) !== null) { if ($child->getTag() === $tag) { $this->tags[] = $child; } $children = array_merge($child->getChildren(), $children); } return $this; }
public function testGetChildren() { $template = new atoum\template(); $this->assert->array($template->getChildren())->isEmpty(); $template->addChild($childTemplate = new atoum\template()); $this->assert->array($template->getChildren())->isIdenticalTo(array($childTemplate)); $template->addChild($otherChildTemplate = new atoum\template()); $this->assert->array($template->getChildren())->isIdenticalTo(array($childTemplate, $otherChildTemplate)); $childTemplate->addChild($littleChildTemplate = new atoum\template()); $this->assert->array($template->getChildren())->isIdenticalTo(array($childTemplate, $otherChildTemplate)); }
public function testAddChild() { $this->if($this->newTestedInstance)->then->boolean($this->testedInstance->hasChildren())->isFalse()->object($this->testedInstance->addChild($childTemplate = new atoum\template()))->isTestedInstance->object($childTemplate->getParent())->isTestedInstance->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate))->object($this->testedInstance->addChild($childTemplate))->isTestedInstance->object($childTemplate->getParent())->isTestedInstance->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate))->if($otherTemplate = new atoum\template(), $otherTemplate->addChild($otherChildTemplate = new atoum\template()))->then->array($otherTemplate->getChildren())->isIdenticalTo(array($otherChildTemplate))->object($otherChildTemplate->getParent())->isIdenticalTo($otherTemplate)->object($this->testedInstance->addChild($otherChildTemplate))->isTestedInstance->array($otherTemplate->getChildren())->isEmpty()->object($otherChildTemplate->getParent())->isTestedInstance->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate, $otherChildTemplate))->if($this->newTestedInstance, $templateWithId = new atoum\template\tag(uniqid()), $templateWithId->setId($id = uniqid()), $templateWithSameId = clone $templateWithId)->then->boolean($this->testedInstance->hasChildren())->isFalse()->object($this->testedInstance->addChild($templateWithId))->isTestedInstance->array($this->testedInstance->getChildren())->isIdenticalTo(array($templateWithId))->object($this->testedInstance->addChild($templateWithId))->isTestedInstance->array($this->testedInstance->getChildren())->isIdenticalTo(array($templateWithId))->exception(function ($test) use($templateWithSameId) { $test->testedInstance->addChild($templateWithSameId); })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Id \'' . $id . '\' is already defined'); }