/**
  * @depends testReadingGroupWithProperty
  */
 public function testReadingMultipleProperties()
 {
     $xml = '
         <config>
             <group title="Test Group">
                 <property name="testProperty1">Enter value</property>
                 <property name="testProperty2">Enter value</property>
                 <property name="testProperty3">Enter value</property>
             </group>
         </config>
     ';
     $this->reader->fromString($xml);
     $this->reader->read();
     $this->reader->read();
     $this->reader->read();
     $this->assertTrue($this->reader->isProperty(), 'Element is expected to be the 1st property.');
     $this->assertEquals('testProperty1', $this->reader->getAttribute('name'));
     $this->reader->read();
     $this->assertTrue($this->reader->isProperty(), 'Element is expected to be the 2nd property.');
     $this->assertEquals('testProperty2', $this->reader->getAttribute('name'));
     $this->reader->read();
     $this->assertTrue($this->reader->isProperty(), 'Element is expected to be the 3rd property.');
     $this->assertEquals('testProperty3', $this->reader->getAttribute('name'));
 }
Пример #2
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;
 }