/**
  * 
  * Creates a test file from the given KalturaTestCaseDataFile object (the data source for the test)
  * @param testDataFile $testDataFile
  */
 private function createTestDataFile(KalturaTestCaseDataFile $testDataSourceFile)
 {
     //TODO: break this function to 2 parts!
     //1. Create the new test data file
     $newTestDataFile = new KalturaTestCaseDataFile($testDataSourceFile->getTestCaseName());
     //2.For every test data we need to:
     foreach ($testDataSourceFile->getTestProceduresData() as $testProcedureData) {
         $newTestProcedureData = new KalturaTestProcedureData($testProcedureData->getProcedureName());
         foreach ($testProcedureData->getTestCasesData() as $testCaseData) {
             $newTestCaseData = new KalturaTestCaseInstanceData($testCaseData->getTestCaseInstanceName());
             //2. Foreach input - Get the object from kaltura DB and add it to the inputObjects array
             foreach ($testCaseData->getInput() as $inputIdentifier) {
                 $inputObject = $this->getTestDataObject($inputIdentifier);
                 $newTestCaseData->addInput($inputObject);
             }
             //3. Foreach outputReference - Get the object from kaltura DB and add it to the outputReferenceObjects array
             foreach ($testCaseData->getOutputReferences() as $outputReferenceIdentifier) {
                 $outputReferenceObject = $this->getTestDataObject($outputReferenceIdentifier);
                 $newTestCaseData->addOutputReference($outputReferenceObject);
             }
             //5. Add the new unit test data to the Data file
             $newTestProcedureData->addTestCaseInstance($newTestCaseData);
         }
         $newTestDataFile->addTestProcedureData($newTestProcedureData);
     }
     chdir(dirname($this->dataSourceFile->getFilePath()));
     //3. Open the file at the file path
     $testDatFileHandle = fopen("{$testDataSourceFile->getTestCaseName()}.data", "w+");
     //4. Convert the test data to xml dom
     $newTestDataDom = KalturaTestCaseDataFile::toXml($newTestDataFile);
     $newTestDataDom->formatOutput = true;
     //5. Save the entire test data file to the test data file name path (in XML)
     fwrite($testDatFileHandle, $newTestDataDom->saveXML());
 }
 /**
  * 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;
     }
 }