/** * * Generates a new testCaseFailure object from a given simpleXmlElement (failure file xml) * @param SimpleXMlElement $unitTestFailureXml */ public function fromXml(SimpleXMlElement $unitTestFailureXml) { //Sets the inputs as key => value byt the xml attributes foreach ($unitTestFailureXml->Inputs->Input as $inputXml) { $this->testCaseInput[] = kXml::getAttributesAsArray($inputXml); } foreach ($unitTestFailureXml->Failures->Failure as $failureXml) { $this->testCaseFailures[] = KalturaFailure::generateFromXml($failureXml); } }
/** * * Returns a DomDocument containing the kaltura failure * @param KalturaFailure $kalturaFailure * @param unknown_type $rootNodeName * @return DomDocument */ public static function toXml(KalturaFailure $kalturaFailure, $rootNodeName = 'data') { $dom = new DOMDocument("1.0"); $failureNode = $dom->createElement($rootNodeName); $dom->appendChild($failureNode); $fieldNode = $dom->createElement("Field", $kalturaFailure->getField()); $failureNode->appendChild($fieldNode); $outputReferenceNode = $dom->createElement("OutputReference"); $failureNode->appendChild($outputReferenceNode); KalturaFailure::setElementValue($dom, $outputReferenceNode, $kalturaFailure->getOutputReferenceValue(), $kalturaFailure->getField()); $actualOutputNode = $dom->createElement("ActualOutput"); $failureNode->appendChild($actualOutputNode); KalturaFailure::setElementValue($dom, $actualOutputNode, $kalturaFailure->getActualValue(), $kalturaFailure->getField()); $assertNode = $dom->createElement("Assert"); $failureNode->appendChild($assertNode); KalturaFailure::setElementValue($dom, $assertNode, $kalturaFailure->getAssert()); if (!is_null($kalturaFailure->getMessage())) { $messageNode = $dom->createElement("Message"); $failureNode->appendChild($messageNode); KalturaFailure::setElementValue($dom, $messageNode, $kalturaFailure->getMessage()); } return $dom; }
/** * * Generates a new KalturaFailure from a given SimpleXMLElement * @param SimpleXMLElement $failureXml */ public static function generateFromXml(SimpleXMLElement $failureXml) { $field = (string) $failureXml->Field; $assert = null; $message = null; if (isset($failureXml->Assert)) { $assert = $failureXml->Assert; } if (isset($failureXml->Message)) { $message = $failureXml->Message; } //If we have an array if (isset($failureXml->ActualOutput->Array)) { $actualValue = KalturaFailure::getArrayValueFromXML($failureXml->ActualOutput->Array); } else { //Convert the simleXMl into string $actualValue = (string) $failureXml->ActualOutput; //No string was given if (strlen($actualValue) == 0) { $actualValue = null; } } if (isset($failureXml->OutputReference->Array)) { $outputReferenceValue = KalturaFailure::getArrayValueFromXML($failureXml->OutputReference->Array); } else { $outputReferenceValue = (string) $failureXml->OutputReference; //No string was given if (strlen($outputReferenceValue) == 0) { $outputReferenceValue = null; } } $kalturaFailure = new KalturaFailure($field, $actualValue, $outputReferenceValue, $assert, $message); return $kalturaFailure; }
/** * * Returns a DomDocument containing the test case failure * @param KalturaTestCaseInstanceFailure $failure * @param string $rootNodeName - default to 'data' * @return DOMDocument - the xml for the given error */ public static function toXml(KalturaTestCaseInstanceFailure $testCaseInstanceFailure, $rootNodeName = 'data') { if (count($testCaseInstanceFailure->getFailures()) == 0) { return new DOMDocument("1.0"); } $dom = new DOMDocument(1.0); $rootNode = $dom->createElement($rootNodeName); $dom->appendChild($rootNode); $rootNode->setAttribute("testCaseInstanceName", $testCaseInstanceFailure->getTestCaseInstanceName()); $inputsNode = $dom->createElement("Inputs"); foreach ($testCaseInstanceFailure->getTestCaseInput() as $inputKey => $inputValue) { $node = $dom->createElement("Input"); if ($inputValue != null) { $type = gettype($inputValue); if (is_object($inputValue)) { $class = get_class($inputValue); KalturaLog::debug("class [" . $class . "]\n"); if (class_exists($class)) { $type = get_class($inputValue); } } $node->setAttribute("type", $type); $id = $inputValue; if ($inputValue instanceof BaseObject) { $id = $inputValue->getId(); } elseif ($inputValue instanceof KalturaObjectBase || $inputValue instanceof KalturaObject) { if (property_exists($inputValue, 'id')) { $id = $inputValue->id; } } //Fixes problem where id was object if (is_object($id)) { $idType = get_class($id); $id = "not a string but {$idType}"; } $node->setAttribute($type . "Id", $id); } $inputsNode->appendChild($node); } $failuresNode = $dom->createElement("Failures"); foreach ($testCaseInstanceFailure->getFailures() as $kalturaFailure) { $objectAsDOM = KalturaFailure::toXml($kalturaFailure, "Failure"); kXml::appendDomToElement($objectAsDOM, $failuresNode, $dom); } $rootNode->appendChild($inputsNode); $rootNode->appendChild($failuresNode); //pass back DomElement object return $dom; }