/** * * 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()); }
/** * * Returns the given KalturaTestDataFile as DomDocument * @param KalturaTestDataFile $testDataFile */ public static function toXml(KalturaTestCaseDataFile $testDataFile) { $dom = new DOMDocument("1.0"); //Create elements in the Dom referencing the entire test data file $testCaseDataElement = $dom->createElement("TestCaseData"); $testCaseDataElement->setAttribute("testCaseName", $testDataFile->getTestCaseName()); $dom->appendChild($testCaseDataElement); //For each test procedure data foreach ($testDataFile->getTestProceduresData() as $testProcedureData) { $domTestProcedureData = KalturaTestProcedureData::toXml($testProcedureData); kXml::appendDomToElement($domTestProcedureData, $testCaseDataElement, $dom); } return $dom; }