Пример #1
0
 public function testRenameElement()
 {
     $this->_populateSampleStructure();
     // rename element and see how children got updated
     $element = $this->_structure->getElement('four');
     $this->assertNotEmpty($element);
     $this->assertFalse($this->_structure->getElement('four.5'));
     $this->assertSame($this->_structure, $this->_structure->renameElement('four', 'four.5'));
     $this->assertSame($element, $this->_structure->getElement('four.5'));
     $this->assertEquals('four.5', $this->_structure->getAttribute('two', Magento_Data_Structure::PARENT));
     $this->assertEquals('four.5', $this->_structure->getAttribute('three', Magento_Data_Structure::PARENT));
     // rename element and see how parent got updated
     $this->_structure->renameElement('three', 'three.5');
     // first child
     $this->assertSame(array('three.5' => 'th', 'two' => 'tw'), $this->_structure->getChildren('four.5'));
     $this->_structure->renameElement('two', 'two.5');
     // second and last child
     $this->assertSame(array('three.5' => 'th', 'two.5' => 'tw'), $this->_structure->getChildren('four.5'));
 }
Пример #2
0
 /**
  * Rename element in layout and layout structure
  *
  * @param string $oldName
  * @param string $newName
  * @return bool
  */
 public function renameElement($oldName, $newName)
 {
     if (isset($this->_blocks[$oldName])) {
         $block = $this->_blocks[$oldName];
         $this->_blocks[$oldName] = null;
         unset($this->_blocks[$oldName]);
         $this->_blocks[$newName] = $block;
     }
     $this->_structure->renameElement($oldName, $newName);
     return $this;
 }