/** * Gets a xml based data and returns a new unit test data object with those values * @param SimpleXMLElement $xml * @return KalturaUnitTestDataObject the new unit test data object with the given data */ public static function fromXml($xml) { $objectInstace = new KalturaUnitTestDataObject(); $objectInstace->type = (string) $xml['type']; $objectInstace->dataObject = KalturaUnitTestDataObject::getObjectInstance($objectInstace->type); $objectInstace->additionalData = kXml::getAttributesAsArray($xml); if (class_exists($objectInstace->type)) { foreach ($xml->children() as $child) { $childKey = $child->getName(); //if dbValue exists if (isset($child["dbValue"])) { $objectInstace->comments[$childKey] = (string) $child["dbValue"]; } if (strlen($child) != 0) { $childValue = (string) $child; } else { $childValue = null; } $childValueType = (string) $child["type"]; try { //TODO: Handle fields which are arrays (currently handled hard coded) if ($childKey == "array" || $childKey == "Array") { $arrayValue = array(); foreach ($child->children() as $singleElementKey => $singleElementValue) { $key = (string) $singleElementValue["key"]; $arrayValue[$key] = (string) $singleElementValue; $arrayKey = $singleElementKey; //if dbValue exists if (isset($singleElementValue["dbValue"])) { $objectInstace->comments[$singleElementKey][$key] = (string) $singleElementValue["dbValue"]; } } KalturaUnitTestDataObject::setPropertyValue(&$objectInstace->dataObject, $arrayKey, $arrayValue, $childValueType); } else { KalturaUnitTestDataObject::setPropertyValue(&$objectInstace->dataObject, $childKey, $childValue, $childValueType); } } catch (Exception $e) { throw new Exception("Error can't set by name" . $childValue . $e, $e->getCode()); } } } else { //Handle no classes objects like string and int //TODO: add support for file... here or there... } // pass back propel object return $objectInstace; }