Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TreeTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Data\Tree\Node;
9 use \Magento\Framework\Data\Tree;
10 
15 class TreeTest extends \PHPUnit\Framework\TestCase
16 {
20  protected $_tree;
21 
22  protected function setUp()
23  {
24  $this->_tree = new Tree();
25  }
26 
27  public function testTreeOperations()
28  {
29  $newNode1 = new Node('abc', 'node1', $this->_tree);
30  $this->_tree->addNode($newNode1);
31  $newNode2 = new Node('def', 'node2', $this->_tree);
32  $this->_tree->addNode($newNode2, $newNode1);
33  $newNode3 = new Node('ghi', 'node3', $this->_tree);
34  $this->_tree->addNode($newNode3, $newNode1);
35  $data1 = ['j', 'k', 'l'];
36  $this->_tree->appendChild($data1, $newNode3);
37  $newNode4 = new Node('mno', 'node4', $this->_tree);
38  $this->_tree->appendChild($newNode4, $newNode3);
39 
40  $this->_tree->removeNode($newNode4);
41  $this->_tree->removeNode($newNode3);
42  $this->_tree->removeNode($newNode2);
43  $this->_tree->removeNode($newNode1);
44 
45  $this->assertEmpty($this->_tree->getNodes()->getNodes());
46  }
47 }