* @package taoQTI */ class QtiPackageParsingTest extends TaoPhpUnitTestRunner { protected $qtiService; /** * tests initialization */ public function setUp(): void { TaoPhpUnitTestRunner::initTest(); $this->qtiService = Service::singleton(); } /** * 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()); } } }