Beispiel #1
0
 /**
  * Read config from xml
  *
  * @param string $xmlString
  * @return $this
  */
 public function readFromXml($xmlString)
 {
     $this->xmlReader->fromString($xmlString);
     while ($this->xmlReader->read()) {
         if ($this->xmlReader->isGroup()) {
             $groupTitle = $this->xmlReader->getAttribute('title');
             $groupIdentifier = $this->xmlReader->getElementIdentifier();
             $this->propertyGroups[$groupIdentifier] = new PropertyGroup($groupTitle);
         } elseif ($this->xmlReader->isMultipleProperty()) {
             $property = new Property();
             $property->setName($this->xmlReader->getAttribute('name'));
             $property->setQuestion($this->xmlReader->getElementValue());
             $property->setType(Property::TYPE_MULTIPLE);
             $this->propertyGroups[$groupIdentifier]->addProperty($property);
         } elseif ($this->xmlReader->isBooleanProperty()) {
             $property = new Property();
             $property->setName($this->xmlReader->getAttribute('name'));
             $property->setQuestion($this->xmlReader->getElementValue());
             $property->setType(Property::TYPE_BOOL);
             $this->propertyGroups[$groupIdentifier]->addProperty($property);
         } elseif ($this->xmlReader->isProperty()) {
             $property = new Property();
             $property->setName($this->xmlReader->getAttribute('name'));
             $property->setQuestion($this->xmlReader->getElementValue());
             $property->setType(Property::TYPE_MIXED);
             $this->propertyGroups[$groupIdentifier]->addProperty($property);
         } elseif ($this->xmlReader->isPropertyWithOptions()) {
             $property = new Property();
             $property->setName($this->xmlReader->getAttribute('name'));
             $property->setQuestion($this->xmlReader->getAttribute('title'));
             foreach ($this->xmlReader->getPropertyOptions() as $value => $name) {
                 $property->addOption($name, $value);
             }
             $this->propertyGroups[$groupIdentifier]->addProperty($property);
             $this->xmlReader->next();
         }
     }
     return $this;
 }
 /**
  * @depends testReadingGroupWithProperty
  */
 public function testReadingMultipleGroups()
 {
     $xml = '
         <config>
             <group title="Test Group 1">
                 <property name="testProperty1">Enter value</property>
             </group>
             <group title="Test Group 2">
                 <property name="testProperty2">Enter value</property>
             </group>
         </config>
     ';
     $this->reader->fromString($xml);
     $this->reader->read();
     $this->reader->read();
     $this->assertTrue($this->reader->isGroup(), 'Element is expected to be the 1st group.');
     $this->assertEquals('Test Group 1', $this->reader->getAttribute('title'), 'Title is wrong.');
     $this->reader->read();
     $this->reader->read();
     $this->assertTrue($this->reader->isGroup(), 'Element is expected to be the 2nd group.');
     $this->assertEquals('Test Group 2', $this->reader->getAttribute('title'), 'Title is wrong.');
 }