importService = ImportService::singleton(); $this->itemService = taoItems_models_classes_ItemsService::singleton(); $this->qtiService = \oat\taoQtiItem\model\qti\Service::singleton(); } /** * @return string */ protected function getSamplePath($relPath) { return __DIR__ . DIRECTORY_SEPARATOR . 'samples' . str_replace('/', DIRECTORY_SEPARATOR, $relPath); } public function testImportResponseEncoding() { $importQtiFilePath = $this->getSamplePath('/xml/qtiv2p1/textentry_response_special_chars.xml'); $itemClass = $this->itemService->getRootClass(); $report = $this->importService->importQTIFile($importQtiFilePath, $itemClass); $this->assertEquals(\common_report_Report::TYPE_SUCCESS, $report->getType()); $item = $report->getData(); $this->assertNotEmpty($item); $itemXml = $this->qtiService->getXmlByRdfItem($item, DEFAULT_LANG); $this->assertXmlStringEqualsXmlString($this->normalizeXml(file_get_contents($importQtiFilePath)), $this->normalizeXml($itemXml)); $this->itemService->deleteResource($item); } /** * Normalize the xml string for comparison * @param $xml * @return string */ protected function normalizeXml($xml) { $xml = preg_replace('/toolVersion="[0-9a-zA-Z-\.]+"/', '', $xml); //work around DOMNode C14N error : "Relative namespace UR is invalid here" $xml = str_replace('xmlns:html5="html5"', 'xmlns:html5="http://www.imsglobal.org/xsd/html5"', $xml); //replace media url by a fixed uri $xml = preg_replace('/taomedia:\/\/mediamanager\/([a-zA-Z0-9_]+)/', 'taomedia://mediamanager/ASSET_URI', $xml); return $xml; } }