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 __construct($tag, $data = null, $line = null, $offset = null) { $tag = (string) $tag; if ($tag === '') { throw new exceptions\logic('Tag must not be an empty string'); } if ($line !== null) { $line = (int) $line; if ($line <= 0) { throw new exceptions\logic('Line must be greater than 0'); } } if ($offset !== null) { $offset = (int) $offset; if ($offset <= 0) { throw new exceptions\logic('Offset must be greater than 0'); } } parent::__construct($data); $this->tag = $tag; $this->line = $line; $this->offset = $offset; }
public function testCurrent() { $iterator = new template\iterator(); $this->assert->boolean($iterator->valid())->isFalse()->variable($iterator->current())->isNull(); $template = new atoum\template(); $template->addChild($tag = new template\tag(uniqid())); $iterator->addTag($tag->getTag(), $template); $this->assert->boolean($iterator->valid())->isTrue()->object($iterator->current())->isIdenticalTo($tag); $iterator->next(); $this->assert->boolean($iterator->valid())->isFalse()->variable($iterator->current())->isNull(); }
public function testGetChild() { $template = new atoum\template(); $this->assert->variable($template->getChild(0))->isNull()->variable($template->getChild(rand(1, PHP_INT_MAX)))->isNull()->variable($template->getChild(-rand(1, PHP_INT_MAX)))->isNull(); $template->addChild($childTemplate = new atoum\template()); $this->assert->variable($template->getChild(0))->isIdenticalTo($childTemplate)->variable($template->getChild(rand(1, PHP_INT_MAX)))->isNull()->variable($template->getChild(-rand(1, PHP_INT_MAX)))->isNull(); }
public function testBuild() { $this->if($this->newTestedInstance)->then->string($this->testedInstance->getData())->isEmpty()->boolean($this->testedInstance->hasChildren())->isFalse()->object($this->testedInstance->build())->isTestedInstance->string($this->testedInstance->getData())->isEmpty()->if($this->newTestedInstance($data = uniqid()))->then->string($this->testedInstance->getData())->isEqualTo($data)->boolean($this->testedInstance->hasChildren())->isFalse()->object($this->testedInstance->build())->isTestedInstance->string($this->testedInstance->getData())->isEqualTo($data)->object($this->testedInstance->build())->isTestedInstance->string($this->testedInstance->getData())->isEqualTo($data)->if($this->testedInstance->addChild($childTemplate = new atoum\template($childData = uniqid())))->then->string($this->testedInstance->getData())->isEqualTo($data)->string($childTemplate->getData())->isEqualTo($childData)->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate))->object($this->testedInstance->build())->isTestedInstance->string($this->testedInstance->getData())->isEqualTo($data . $childData)->string($childTemplate->getData())->isEqualTo($childData)->object($this->testedInstance->build())->isTestedInstance->string($this->testedInstance->getData())->isEqualTo($data . $childData . $childData); }
public function setParent(atoum\template $parent) { $parent->addChild($this); return $this; }