/** * Gets kaltura object id and type and return the needed Katura Object * * @param string $objectId * @param string $objectType * @return KalturaTestDataObject - returns the test object with propel object from the DB */ private function getTestDataObject(KalturaTestDataObject $testObjectIdentifier) { $testDataObject = new KalturaTestDataObject($testObjectIdentifier->getType(), $testObjectIdentifier->getAdditionalData(), $testObjectIdentifier->getDataObject()); $objectType = $testObjectIdentifier->getType(); $additionalData = $testObjectIdentifier->getAdditionalData(); $objectId = $additionalData["key"]; $testDataObject->setDataObject(KalturaTestDataGenerator::getObjectByTypeAndId($objectType, $objectId, $testDataObject->getAdditionalData())); return $testDataObject; }
/** * * Transforms the the given input object into the right value (including getting from global data) * @param KalturaTestDataObject $inputObject */ protected function transformToValue($inputObject) { $inputAsObject = $inputObject->getValue(); $isGlobalData = KalturaGlobalData::isGlobalData($inputAsObject); KalturaLog::debug("isGlobalData [{$isGlobalData}] \n"); if ($isGlobalData) { $name = $inputAsObject; $inputAsObject = KalturaGlobalData::getData($name); KalturaLog::debug("inputAsObject global name [{$name}] value [{$inputAsObject}]\n"); //TODO: check if needed if (!$inputAsObject) { $inputAsObject = $name; } } return $inputAsObject; }
/** * Gets a xml based data and returns a new unit test data object with those values * @param SimpleXMLElement $xml * @return KalturaTestDataObject the new unit test data object with the given data */ public function fromXml($xml) { $this->type = (string) $xml['type']; $this->dataObject = KalturaTestDataObject::getObjectInstance($this->type); $this->additionalData = kXml::getAttributesAsArray($xml); if (class_exists($this->type)) { foreach ($xml->children() as $child) { $childKey = $child->getName(); //if dbValue exists if (isset($child["dbValue"])) { $commentValue = $child['dbValue']; $this->comments[$childKey] = "{$commentValue}"; } 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(); $arrayKey = $childValue; foreach ($child->children() as $singleElementKey => $singleElementValue) { if (isset($singleElementValue["key"])) { $key = (string) $singleElementValue["key"]; $arrayValue[$key] = (string) $singleElementValue; } $arrayKey = $singleElementKey; //if dbValue exists if (isset($singleElementValue["dbValue"])) { $singleElementComment = $singleElementValue["dbValue"]; $this->comments[$singleElementKey][$key] = "{$singleElementComment}"; } } if (count($arrayValue) > 0) { KalturaTestDataObject::setPropertyValue($this->dataObject, $arrayKey, $arrayValue, $childValueType); } else { KalturaTestDataObject::setPropertyValue($this->dataObject, $arrayKey, $arrayValue, 'Array'); } } else { KalturaTestDataObject::setPropertyValue($this->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 $child = $xml->children(); if ($this->type == 'fileHandler') { KalturaTestDataObject::setPropertyValue($this->value, "value", file_get_contents(getcwd() . (string) $xml['key']), null); } else { if (count($child) == 0) { KalturaTestDataObject::setPropertyValue($this->value, "value", trim($xml), null); } else { KalturaTestDataObject::setPropertyValue($this->value, "value", $child->saveXML(), null); } } } }
/** * * Returns the given KalturaTestCaseInstanceData as a DomDocument * @param KalturaTestCaseInstanceData $testCaseInstanceData */ public static function toXml(KalturaTestCaseInstanceData $testCaseInstanceData) { $dom = new DOMDocument("1.0"); //Create all his elements $domTestCaseData = $dom->createElement("TestCaseData"); $domTestCaseData->setAttribute("testCaseInstanceName", $testCaseInstanceData->getTestCaseInstanceName()); $dom->appendChild($domTestCaseData); //For each input: foreach ($testCaseInstanceData->getInput() as $input) { //Create the xml from the object $objectAsDOM = KalturaTestDataObject::toXml($input, "Input"); kXml::appendDomToElement($objectAsDOM, $domTestCaseData, $dom); } //For each outputReference: foreach ($testCaseInstanceData->getOutputReferences() as $outputReference) { //Create the xml from the object $objectAsDOM = KalturaTestDataObject::toXml($outputReference, "OutputReference"); kXml::appendDomToElement($objectAsDOM, $domTestCaseData, $dom); } return $dom; }
/** * Gets a xml based data and returns a new test data object base with those values * @param SimpleXMLElement $xml * @return KalturaTestDataObject the new unit test data object with the given data */ public static function generatefromXml($xml) { $objectInstace = new KalturaTestDataObject(); $objectInstace->fromXml($xml); // pass back propel object return $objectInstace; }