/**
  * Gets kaltura object id and type and return the needed Katura Object
  *  
  * @param string $objectId
  * @param string $objectType
  * @return KalturaUnitTestDataObject - returns the unit test object with propel object from the DB
  */
 private function getUnitTestDataObject(KalturaUnitTestDataObject $unitTestObjectIdentifier)
 {
     $unitTestDataObject = new KalturaUnitTestDataObject($unitTestObjectIdentifier->getType(), $unitTestObjectIdentifier->additionalData, $unitTestObjectIdentifier->dataObject);
     $objectType = $unitTestObjectIdentifier->getType();
     $objectId = $unitTestObjectIdentifier->additionalData["key"];
     $unitTestDataObject->dataObject = KalturaUnitTestDataGenerator::getObjectByTypeAndId($objectType, $objectId, $unitTestDataObject->additionalData);
     return $unitTestDataObject;
 }
Example #2
0
 /**
  * 
  * Generates a new unitTestData object from a given simpleXLMElement
  * @param SimpleXMLElement $simpleXMLElement
  * @return unitTestData - New unitTestData object
  */
 public function fromDataXml(SimpleXMLElement $simpleXMLElement)
 {
     foreach ($simpleXMLElement->Inputs->Input as $input) {
         $unitTestDataObject = KalturaUnitTestDataObject::fromXml($input);
         $this->input[] = $unitTestDataObject;
     }
     foreach ($simpleXMLElement->OutputReferences->OutputReference as $outputReference) {
         $unitTestDataObject = KalturaUnitTestDataObject::fromXml($outputReference);
         $this->outputReference[] = $unitTestDataObject;
     }
 }
 /**
  * 
  * Returns the test data file in XML format (including the objects) 
  * @return string XML encoded representation of the test data file object
  */
 public function toDataXML()
 {
     //TODO: Add the objects header
     $dom = new DOMDocument("1.0");
     $dom->formatOutput = true;
     //Create elements in the Dom referencing the entire test data file
     $unitTestsElement = $dom->createElement("UnitTests");
     $dom->appendChild($unitTestsElement);
     $unitTestsDataElement = $dom->createElement("UnitTestsData");
     $unitTestsElement->appendChild($unitTestsDataElement);
     //For each unit test data
     foreach ($this->unitTestsData as $unitTestData) {
         //create all his elements
         $domUnitTestData = $dom->createElement("UnitTestData");
         $unitTestsDataElement->appendChild($domUnitTestData);
         $inputs = $dom->createElement("Inputs");
         $outputReferences = $dom->createElement("OutputReferences");
         $domUnitTestData->appendChild($inputs);
         $domUnitTestData->appendChild($outputReferences);
         //for each input:
         foreach ($unitTestData->input as $input) {
             //Create the xml from the object
             $objectAsDOM = KalturaUnitTestDataObject::toXml($input, "Input");
             if ($objectAsDOM->documentElement != NULL) {
                 $importedNode = $dom->importNode($objectAsDOM->documentElement, true);
                 //Add him to the input elements
                 $inputs->appendChild($importedNode);
             } else {
                 //Object is null so we make only an empty node!
                 throw new Exception("One of the objects is null : " . $input);
             }
         }
         //for each outputReference:
         foreach ($unitTestData->outputReference as $outputReference) {
             //Create the xml from the object
             $objectAsDOM = KalturaUnitTestDataObject::toXml($outputReference, "OutputReference");
             if ($objectAsDOM->documentElement != NULL) {
                 $importedNode = $dom->importNode($objectAsDOM->documentElement, true);
                 //Add him to the output reference elements
                 $outputReferences->appendChild($importedNode);
             } else {
                 //Object is null so we make only an empty node!
                 throw new Exception("One of the objects is null : " . var_dump($outputReference));
             }
         }
         $unitTestsDataElement->appendChild($domUnitTestData);
     }
     //return the XML well formated
     $dom->formatOutput = true;
     return $dom->saveXML();
 }
 /**
  * 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;
 }