예제 #1
0
 /**
  * @param int $number
  * @param \PHPUnit_Framework_MockObject_MockObject|null $returnValue
  *
  * @dataProvider testAddDataProvider
  */
 public function testAdd($number, $returnValue)
 {
     $nodeMock = $this->getMock('Magento\\Framework\\Data\\Tree\\Node', [], [], '', false);
     $nodeMock->expects($this->once())->method('setParent')->with($this->containerMock);
     $this->containerMock->expects($this->exactly($number))->method('getTree')->will($this->returnValue($returnValue));
     $nodeMock->expects($this->once())->method('getId')->will($this->returnValue('id_node'));
     $this->assertEquals($nodeMock, $this->collection->add($nodeMock));
     $this->assertEquals(['id_node' => $nodeMock], $this->collection->getNodes());
     $this->assertEquals($nodeMock, $this->collection->searchById('id_node'));
     $this->assertEquals(null, $this->collection->searchById('id_node_new'));
 }
예제 #2
0
 public function testSearchById()
 {
     $tree = new \Magento\Framework\Data\Tree();
     $node1 = new \Magento\Framework\Data\Tree\Node(['id' => 'node1'], 'id', $tree);
     $this->collection->add($node1);
     $node2 = new \Magento\Framework\Data\Tree\Node(['id' => 'node2'], 'id', $tree);
     $this->collection->add($node2);
     $this->assertSame($this->collection->lastNode(), $node2);
     $node3 = new \Magento\Framework\Data\Tree\Node(['id' => 'node3'], 'id', $tree);
     $this->collection->add($node3);
     $this->assertSame($this->collection->searchById('node2'), $node2);
 }
예제 #3
0
 /**
  * @param Node $childNode
  * @return $this
  */
 public function removeChild($childNode)
 {
     $this->_childNodes->delete($childNode);
     return $this;
 }
예제 #4
0
 /**
  * Enter description here...
  *
  * @param Node $nodeId
  * @return Node
  */
 public function getNodeById($nodeId)
 {
     return $this->_nodes->searchById($nodeId);
 }