/** * sets the KalturaDataGeneratorConfigFile object from simpleXMLElement (the source xml of the data) * @param SimpleXMLElement $simpleXMLElement * * @return None, sets the given object */ public function fromSourceXML(SimpleXMLElement $simpleXMLElement) { //For each test file foreach ($simpleXMLElement->TestDataFile as $xmlTestDataFile) { //Create new test file obejct $testDataFile = new KalturaUnitTestDataFile(); //For each UnitTest data (in this file) foreach ($xmlTestDataFile->UnitTestsData->UnitTestData as $xmlUnitTestData) { //Create new unit test data $unitTestData = new KalturaUnitTestData(); //For each input create the needed Kaltura object identifier foreach ($xmlUnitTestData->Inputs->Input as $input) { $additionalData = kXml::getAttributesAsArray($input); $unitTestDataObjectIdentifier = new KalturaUnitTestDataObject((string) $input["type"], $additionalData); $unitTestData->input[] = $unitTestDataObjectIdentifier; } //And for each output reference create the needed kaltura object identifier foreach ($xmlUnitTestData->OutputReferences->OutputReference as $outputReference) { $additionalData = kXml::getAttributesAsArray($outputReference); $unitTestDataObjectIdentifier = new KalturaUnitTestDataObject((string) $outputReference["type"], $additionalData); $unitTestData->outputReference[] = $unitTestDataObjectIdentifier; } //Add the new unit test into the tests array. $testDataFile->unitTestsData[] = $unitTestData; } $testDataFile->fileName = trim((string) $xmlTestDataFile->FileName); $this->testFiles[] = $testDataFile; } }
/** * * 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); } }
/** * sets the KalturaTestDataSourceFile object from simpleXMLElement (the source xml of the data) * @param SimpleXMLElement $simpleXMLElement * * @return None, sets the given object */ public function fromSourceXML(SimpleXMLElement $simpleXMLElement) { //For each test file foreach ($simpleXMLElement->TestCaseData as $xmlTestDataFile) { //Create new test file obejct $testDataFile = new KalturaTestCaseDataFile(trim((string) $xmlTestDataFile["testCaseName"])); foreach ($xmlTestDataFile->TestProcedureData as $xmlTestProcedureData) { $testProcedureData = new KalturaTestProcedureData(); if (isset($xmlTestProcedureData["testProcedureName"])) { $testProcedureData->setProcedureName($xmlTestProcedureData["testProcedureName"]); } //TODO: maybe get this from procedure / test case instance config $testCaseNum = 0; //For each test data (in this file) foreach ($xmlTestProcedureData->TestCaseData as $xmlTestCaseData) { $testCaseName = $testProcedureData->getProcedureName() . " with data set #{$testCaseNum}"; $testCaseNum++; //User defined test cases name if (isset($xmlTestCaseData["testCaseInstanceName"])) { $testCaseName = $xmlTestCaseData["testCaseInstanceName"]; $testCaseNum--; } //Create new unit test data $testCaseData = new KalturaTestCaseInstanceData($testCaseName); //For each input create the needed Kaltura object identifier foreach ($xmlTestCaseData->Input as $input) { $additionalData = kXml::getAttributesAsArray($input); $testInputDataObjectIdentifier = new KalturaTestDataObject((string) $input["type"], $additionalData); $testCaseData->addInput($testInputDataObjectIdentifier); } //And for each output reference create the needed kaltura object identifier foreach ($xmlTestCaseData->OutputReference as $outputReference) { $additionalData = kXml::getAttributesAsArray($outputReference); $testOutputReferenceDataObjectIdentifier = new KalturaTestDataObject((string) $outputReference["type"], $additionalData); $testCaseData->addOutputReference($testOutputReferenceDataObjectIdentifier); } //Add the new test case data into the test procedure data. $testProcedureData->addTestCaseInstance($testCaseData); } //Add the new procedure test data into the test file. $testDataFile->addTestProcedureData($testProcedureData); } $this->testFiles[] = $testDataFile; } }
/** * * Generates a new testCaseFailure object from a given simpleXmlElement (failure file xml) * @param SimpleXMlElement $unitTestFailureXml */ public function fromXml(SimpleXMlElement $testCaseInstanceFailureXml) { $this->testCaseInstanceName = (string) $testCaseInstanceFailureXml["testCaseInstanceName"]; //Sets the inputs as key => value byt the xml attributes foreach ($testCaseInstanceFailureXml->Inputs->Input as $inputXml) { $this->testCaseInput[] = kXml::getAttributesAsArray($inputXml); } foreach ($testCaseInstanceFailureXml->Failures->Failure as $failureXml) { $this->failures[] = KalturaFailure::generateFromXml($failureXml); } }
/** * 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); } } } }
/** * 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; }