Exemplo n.º 1
0
 public function testParseString()
 {
     $parser = new template\parser();
     $this->assert->object($root = $parser->parseString(''))->isInstanceOf('mageekguy\\atoum\\template')->array($root->getChildren())->isEmpty();
     $this->assert->object($root = $parser->parseString($string = uniqid()))->isInstanceOf('mageekguy\\atoum\\template')->array($root->getChildren())->hasSize(1)->object($root->getChild(0))->isInstanceOf('mageekguy\\atoum\\template\\data')->string($root->getChild(0)->getData())->isEqualTo($string);
     $this->assert->object($root = $parser->parseString($string = uniqid() . "\n" . uniqid() . "\n"))->isInstanceOf('mageekguy\\atoum\\template')->array($root->getChildren())->hasSize(1)->object($root->getChild(0))->isInstanceOf('mageekguy\\atoum\\template\\data')->string($root->getChild(0)->getData())->isEqualTo($string);
     $this->assert->object($root = $parser->parseString('<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' />'))->isInstanceOf('mageekguy\\atoum\\template')->array($root->getChildren())->hasSize(1)->object($root->getChild(0))->isInstanceOf('mageekguy\\atoum\\template\\tag')->string($root->getChild(0)->getTag())->isEqualTo($tag)->variable($root->getChild(0)->getId())->isNull()->string($root->getChild(0)->getData())->isEmpty()->integer($root->getChild(0)->getLine())->isEqualTo(1)->integer($root->getChild(0)->getOffset())->isEqualTo(1);
     $this->assert->object($root = $parser->parseString('<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '/>'))->isInstanceOf('mageekguy\\atoum\\template')->array($root->getChildren())->hasSize(1)->object($root->getChild(0))->isInstanceOf('mageekguy\\atoum\\template\\tag')->string($root->getChild(0)->getTag())->isEqualTo($tag)->variable($root->getChild(0)->getId())->isNull()->string($root->getChild(0)->getData())->isEmpty()->integer($root->getChild(0)->getLine())->isEqualTo(1)->integer($root->getChild(0)->getOffset())->isEqualTo(1);
     $this->assert->object($root = $parser->parseString('<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' id="' . ($id = uniqid()) . '" />'))->isInstanceOf('mageekguy\\atoum\\template')->array($root->getChildren())->hasSize(1)->object($root->getChild(0))->isInstanceOf('mageekguy\\atoum\\template\\tag')->string($root->getChild(0)->getTag())->isEqualTo($tag)->string($root->getChild(0)->getId())->isEqualTo($id)->string($root->getChild(0)->getData())->isEmpty()->integer($root->getChild(0)->getLine())->isEqualTo(1)->integer($root->getChild(0)->getOffset())->isEqualTo(1);
     $this->assert->object($root = $parser->parseString('<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' id="' . ($id = uniqid()) . '"/>'))->isInstanceOf('mageekguy\\atoum\\template')->array($root->getChildren())->hasSize(1)->object($root->getChild(0))->isInstanceOf('mageekguy\\atoum\\template\\tag')->string($root->getChild(0)->getTag())->isEqualTo($tag)->string($root->getChild(0)->getId())->isEqualTo($id)->string($root->getChild(0)->getData())->isEmpty()->integer($root->getChild(0)->getLine())->isEqualTo(1)->integer($root->getChild(0)->getOffset())->isEqualTo(1);
     $this->assert->object($root = $parser->parseString('<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '>' . ($data = uniqid()) . '</' . template\parser::defaultNamespace . ':' . $tag . '>'))->isInstanceOf('mageekguy\\atoum\\template')->array($root->getChildren())->hasSize(1)->object($root->getChild(0))->isInstanceOf('mageekguy\\atoum\\template\\tag')->string($root->getChild(0)->getTag())->isEqualTo($tag)->variable($root->getChild(0)->getId())->isNull()->string($root->getChild(0)->getData())->isEmpty()->integer($root->getChild(0)->getLine())->isEqualTo(1)->integer($root->getChild(0)->getOffset())->isEqualTo(1);
     $this->assert->object($root = $parser->parseString(($string1 = uniqid()) . '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '>' . ($data = uniqid()) . '</' . template\parser::defaultNamespace . ':' . $tag . '>' . ($string2 = uniqid())))->isInstanceOf('mageekguy\\atoum\\template')->array($root->getChildren())->hasSize(3)->object($root->getChild(0))->isInstanceOf('mageekguy\\atoum\\template\\data')->string($root->getChild(0)->getData())->isEqualTo($string1)->object($root->getChild(1))->isInstanceOf('mageekguy\\atoum\\template\\tag')->variable($root->getChild(1)->getId())->isNull()->string($root->getChild(1)->getData())->isEmpty()->integer($root->getChild(1)->getLine())->isEqualTo(1)->integer($root->getChild(1)->getOffset())->isEqualTo(strlen($string1) + 1)->object($root->getChild(2))->isInstanceOf('mageekguy\\atoum\\template\\data')->string($root->getChild(2)->getData())->isEqualTo($string2);
     $this->assert->object($root = $parser->parseString(($string1 = uniqid()) . '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' id="' . ($id = uniqid()) . '">' . ($data = uniqid()) . '</' . template\parser::defaultNamespace . ':' . $tag . '>' . ($string2 = uniqid())))->isInstanceOf('mageekguy\\atoum\\template')->array($root->getChildren())->hasSize(3)->object($root->getChild(0))->isInstanceOf('mageekguy\\atoum\\template\\data')->string($root->getChild(0)->getData())->isEqualTo($string1)->object($root->getChild(1))->isInstanceOf('mageekguy\\atoum\\template\\tag')->string($root->getChild(1)->getId())->isEqualTo($id)->string($root->getChild(1)->getData())->isEmpty()->integer($root->getChild(1)->getLine())->isEqualTo(1)->integer($root->getChild(1)->getOffset())->isEqualTo(strlen($string1) + 1)->object($root->getChild(2))->isInstanceOf('mageekguy\\atoum\\template\\data')->string($root->getChild(2)->getData())->isEqualTo($string2);
     $this->assert->object($root = $parser->parseString(($string = str_repeat("\n", 6)) . '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '/>'))->array($root->getChildren())->hasSize(2)->object($root->getChild(0))->isInstanceOf('mageekguy\\atoum\\template\\data')->string($root->getChild(0)->getData())->isEqualTo($string)->object($root->getChild(1))->isInstanceOf('mageekguy\\atoum\\template\\tag')->variable($root->getChild(1)->getId())->isNull()->string($root->getChild(1)->getData())->isEmpty()->integer($root->getChild(1)->getLine())->isEqualTo(7)->integer($root->getChild(1)->getOffset())->isEqualTo(1);
 }