mageekguy\atoum\template::getById PHP Method

getById() public method

public getById ( $id, $fromRoot = true )
    public function getById($id, $fromRoot = true)
    {
        $root = $fromRoot === false ? $this : $this->getRoot();
        if ($root->getId() === $id) {
            return $root;
        } else {
            foreach ($root->children as $child) {
                $tag = $child->getById($id, false);
                if ($tag !== null) {
                    return $tag;
                }
            }
            return null;
        }
    }

Usage Example

Ejemplo n.º 1
0
 public function testGetById()
 {
     $template = new atoum\template();
     $this->assert->variable($template->getById(uniqid()))->isNull();
     $tag = new atoum\template\tag(uniqid());
     $template->addChild($tag->setId($id = uniqid()));
     $this->assert->variable($template->getById(uniqid()))->isNull()->object($template->getById($id))->isIdenticalTo($tag);
     $childTag = new atoum\template\tag(uniqid());
     $tag->addChild($childTag->setId($childId = uniqid()));
     $this->assert->variable($template->getById(uniqid()))->isNull()->object($template->getById($id))->isIdenticalTo($tag)->object($tag->getById($id))->isIdenticalTo($tag)->object($template->getById($childId))->isIdenticalTo($childTag)->object($tag->getById($childId))->isIdenticalTo($childTag)->object($childTag->getById($childId))->isIdenticalTo($childTag)->variable($childTag->getById($id, false))->isNull();
 }