Exemplo n.º 1
0
 /**
  * @param Section $section
  */
 public function addSection(Section $section)
 {
     $existingKey = false;
     foreach ($this->children as $key => $existingSection) {
         if ($existingSection->getId() == $section->getId()) {
             $existingKey = $key;
             break;
         }
     }
     if ($existingKey !== false) {
         switch ($section->getPolicy()) {
             case Section::POLICY_MERGE:
                 $currentSection = $this->children[$existingKey];
                 foreach ($section->getTrees() as $tree) {
                     $currentSection->addTree($tree);
                 }
                 foreach ($section->getActions() as $action) {
                     $currentSection->addAction($action);
                 }
                 break;
             case Section::POLICY_OVERRIDE:
                 $this->children[$existingKey] = $section;
                 break;
             default:
                 throw new \common_exception_Error();
         }
         //merge the section
     } else {
         $this->children[] = $section;
     }
 }
Exemplo n.º 2
0
 /**
  * Test the section can be loaded from either legacy or new XML format 
  * 
  * @dataProvider legacyAndNewSectionProvider
  * 
  * @param string $xml new format xml
  * @param string $xml legacy format xml
  */
 public function testActions($newXml, $legacyXml)
 {
     $sectionFromNew = Section::fromSimpleXMLElement(new SimpleXMLElement($newXml));
     $this->assertTrue($sectionFromNew instanceof Section);
     $this->assertEquals(count($sectionFromNew->getActions()), 4);
     $sectionFromLegacy = Section::fromSimpleXMLElement(new SimpleXMLElement($legacyXml));
     $this->assertTrue($sectionFromLegacy instanceof Section);
     $this->assertEquals(count($sectionFromLegacy->getActions()), 4);
     $this->assertEquals(count($sectionFromLegacy->getTrees()), 1);
     $trees = $sectionFromLegacy->getTrees();
     $tree = $trees[0];
     $this->assertTrue($tree instanceof Tree);
     $this->assertFalse(is_null($tree->get('selectClass')));
     $this->assertEquals('edit_class', $tree->get('selectClass'));
 }