/** * @test */ public function it_should_append_new_node_to_another_node() { $root = $this->tree('root_1'); $node = $this->tree('node_1_2'); $child = new Tree(['label' => 'child of node']); expect('new node appended to node', $child->appendTo($node))->true(); expect('new node is a old node child', $child->isChildOf($node))->true(); expect('root is one of a parents of a new node', $root->isParentOf($child))->true(); expect('root is not closest parent of a new node', $root->isParentOf($child, true))->false(); expect('old node is closest parent of a new node', $node->isParentOf($child, true))->true(); }
public function testAppendTo() { $root = $this->tree('root_1'); $this->specify('it should be able to append new node to root', function () use($root) { $child = new Tree(['label' => 'child of root']); expect('new node appended to root', $child->appendTo($root))->true(); expect('new node is a root child', $child->isChildOf($root))->true(); expect('root is a parent of new node', $root->isParentOf($child))->true(); }); $node = $this->tree('node_1_2'); $this->specify('it should be able to append new node to another node', function () use($root, $node) { $child = new Tree(['label' => 'child of node']); expect('new node appended to node', $child->appendTo($node))->true(); expect('new node is a old node child', $child->isChildOf($node))->true(); expect('root is one of a parents of a new node', $root->isParentOf($child))->true(); expect('root is not closest parent of a new node', $root->isParentOf($child, true))->false(); expect('old node is closest parent of a new node', $node->isParentOf($child, true))->true(); }); }