/** * test qti file parsing: validation and loading in a non-persistant context */ public function testFileParsing() { //check if wrong packages are not validated correctly foreach (glob(dirname(__FILE__) . '/samples/parser/wrong/*.zip') as $file) { $qtiParser = new PackageParser($file); $qtiParser->validate(); $this->assertFalse($qtiParser->isValid(), 'failed with: ' . $file); $this->assertTrue(count($qtiParser->getErrors()) > 0); $this->assertTrue(strlen($qtiParser->displayErrors()) > 0); } //check if package samples are valid foreach (glob(dirname(__FILE__) . '/samples/package/QTI/*.zip') as $file) { $qtiParser = new PackageParser($file); $qtiParser->validate(); if (!$qtiParser->isValid()) { echo $qtiParser->displayErrors(); } $this->assertTrue($qtiParser->isValid()); } //check if wrong manifest files are not validated correctly foreach (glob(dirname(__FILE__) . '/samples/package/wrong/*.xml') as $file) { $qtiParser = new ManifestParser($file); $qtiParser->validate(); $this->assertFalse($qtiParser->isValid()); $this->assertTrue(count($qtiParser->getErrors()) > 0); $this->assertTrue(strlen($qtiParser->displayErrors()) > 0); } //check if manifest samples are valid $basePath = common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getDir(); foreach (glob(dirname(__FILE__) . '/samples/package/*.xml') as $file) { $qtiParser = new ManifestParser($file); $schema = ''; $fileContent = file_get_contents($file); if (strpos($fileContent, 'xmlns="http://www.imsglobal.org/xsd/apip/apipv1p0/imscp_v1p1"')) { $schema = $basePath . 'model/qti/data/apipv1p0/Core_Level/Package/apipv1p0_imscpv1p2_v1p0.xsd'; } $qtiParser->validate($schema); if (!$qtiParser->isValid()) { echo $qtiParser->displayErrors(); } $this->assertTrue($qtiParser->isValid()); } }
protected function createQtiManifest($manifestFile, $validate = true) { //load and validate the manifest $qtiManifestParser = new ManifestParser($manifestFile); if ($validate) { $basePath = common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getDir(); $qtiManifestParser->validateMultiple(array($basePath . 'model/qti/data/imscp_v1p1.xsd', $basePath . 'model/qti/data/apipv1p0/Core_Level/Package/apipv1p0_imscpv1p2_v1p0.xsd')); if (!$qtiManifestParser->isValid()) { $eStrs = array(); foreach ($qtiManifestParser->getErrors() as $libXmlError) { $eStrs[] = __('XML error at line %1$d "%2$s".', $libXmlError['line'], str_replace('[LibXMLError] ', '', trim($libXmlError['message']))); } // Add sub-report. throw new ValidationException($manifestFile, $eStrs); } } return $qtiManifestParser->load(); }
protected function createQtiManifest($manifestFile, $validate = true) { //load and validate the manifest $qtiManifestParser = new ManifestParser($manifestFile); if ($validate) { $qtiManifestParser->validate(); if (!$qtiManifestParser->isValid()) { $eStrs = array(); foreach ($qtiManifestParser->getErrors() as $libXmlError) { if (isset($libXmlError['line'])) { $error = __('XML error at line %1$d "%2$s".', $libXmlError['line'], str_replace('[LibXMLError] ', '', trim($libXmlError['message']))); } else { $error = __('XML error "%1$s".', str_replace('[LibXMLError] ', '', trim($libXmlError['message']))); } $eStrs[] = $error; } // Add sub-report. throw new ValidationException($manifestFile, $eStrs); } } return $qtiManifestParser->load(); }