예제 #1
0
 public function setUp()
 {
     parent::setUp();
     TaoPhpUnitTestRunner::initTest();
     $rdfClass = new core_kernel_classes_Class(CLASS_GENERIS_RESOURCE);
     $this->class = $rdfClass->createSubClass('test class');
     $this->property = $this->class->createProperty('test property');
 }
 public function testDeepCloneTriplesSimple()
 {
     $object = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAO.rdf#TAOObject');
     $subClass = $object->createSubClass("My sub Class test");
     //see if clone works
     $return = CloneHelper::deepCloneTriples($subClass->getRdfTriples());
     $this->assertEquals($subClass->getRdfTriples()->sequence, $return);
     $subClass->delete(true);
 }
예제 #3
0
 public function setUp()
 {
     GenerisPhpUnitTestRunner::initTest();
     $class = new core_kernel_classes_Class(CLASS_GENERIS_RESOURCE);
     $this->topClass = $class->createSubClass('test class 1');
     $this->emptyClass = $class->createSubClass('test class 2');
     $class1a = $this->topClass->createSubClass('test class 1a');
     $class1b = $this->topClass->createSubClass('test class 1b');
     $class1c = $this->topClass->createSubClass('test class 1c');
     $class1c1 = $class1c->createSubClass('test class 1c1');
     $instance1_1 = $this->topClass->createInstance('test instance 1.1');
     $instance1_2 = $this->topClass->createInstance('test instance 1.2');
     $instance1_3 = $this->topClass->createInstance('test instance 1.3');
     $instance1b_1 = $class1b->createInstance('test instance 1b.1');
     $instance1b_2 = $class1b->createInstance('test instance 1b.2');
     $instance1c1_1 = $class1c1->createInstance('test instance 1c1.1');
     $instance1c1_2 = $class1c1->createInstance('test instance 1c1.2');
 }
 public function testGetDirectory()
 {
     $root = new \core_kernel_classes_Class($this->rootClass);
     //Remove what has been done
     $subclasses = $root->getSubClasses();
     foreach ($subclasses as $subclass) {
         $subclass->delete(true);
     }
     $root->delete();
     $root->setLabel('myRootClass');
     $acceptableMime = array();
     $depth = 1;
     $directory = $this->mediaManagerManagement->getDirectory($this->rootClass, $acceptableMime, $depth);
     $this->assertInternalType('array', $directory, 'The result should be an array');
     $this->assertArrayHasKey('label', $directory, 'The result should contain "label"');
     $this->assertArrayHasKey('path', $directory, 'The result should contain "path"');
     $this->assertArrayHasKey('children', $directory, 'The result should contain "children"');
     $this->assertInternalType('array', $directory['children'], 'Children should be an array');
     $this->assertEmpty($directory['children'], 'Children should be empty');
     $this->assertEquals('myRootClass', $directory['label'], 'The label is not correct');
     $this->assertEquals('taomedia://mediamanager/' . \tao_helpers_Uri::encode($this->rootClass), $directory['path'], 'The path is not correct');
     $root->createSubClass('mySubClass1');
     $root->createSubClass('mySubClass0');
     $newDirectory = $this->mediaManagerManagement->getDirectory($this->rootClass, $acceptableMime, $depth);
     $this->assertInternalType('array', $newDirectory['children'], 'Children should be an array');
     $this->assertNotEmpty($newDirectory['children'], 'Children should not be empty');
     $labels = array();
     foreach ($newDirectory['children'] as $i => $child) {
         $this->assertInternalType('array', $child, 'The result should be an array');
         $this->assertArrayHasKey('label', $child, 'The result should contain "label"');
         $this->assertArrayHasKey('path', $child, 'The result should contain "path"');
         $labels[] = $child['label'];
     }
     $this->assertEquals(2, count($labels));
     $this->assertContains('mySubClass0', $labels);
     $this->assertContains('mySubClass1', $labels);
     //Remove what has been done
     $subclasses = $root->getSubClasses();
     foreach ($subclasses as $subclass) {
         $subclass->delete();
     }
     $root->delete();
 }
예제 #5
0
 public function testInject()
 {
     $generisClass = new core_kernel_classes_Class(CLASS_GENERIS_RESOURCE);
     $testClass = $generisClass->createSubClass();
     try {
         $testInstance = $testClass->createInstanceWithProperties(array(RDFS_LABEL => '"hi"'));
         $testInstance->setPropertiesValues(array(RDFS_COMMENT => '"hi"'));
         $this->assertEquals($testInstance->getUniquePropertyValue(new core_kernel_classes_Property(RDFS_LABEL)), "\"hi\"");
     } catch (PDOException $e) {
         $this->fail('SQL Error: ' . $e->getMessage());
     }
     $testInstance->delete();
     $generisClass->delete();
 }
 public static function generateItems($count = 100)
 {
     // load QTI constants
     \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem');
     $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDevTools');
     $generationId = NameGenerator::generateRandomString(4);
     $topClass = new \core_kernel_classes_Class(TAO_ITEM_CLASS);
     $class = $topClass->createSubClass('Generation ' . $generationId);
     $fileClass = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/generis.rdf#File');
     $sampleFile = $ext->getDir() . 'data/items/sampleItem.xml';
     helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::LONG);
     for ($i = 0; $i < $count; $i++) {
         $report = ImportService::singleton()->importQTIFile($sampleFile, $class, false);
         $item = $report->getData();
         $item->setLabel(NameGenerator::generateTitle());
     }
     helpers_TimeOutHelper::reset();
     return $class;
 }
 public function createContextOfThetest()
 {
     // Top Class : TaoSubject
     $subjectClass = new core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAOSubject.rdf#Subject');
     // Create a new subject class for the unit test
     $this->targetSubjectClass = $subjectClass->createSubClass("Sub Subject Class (Unit Test)");
     // Add an instance to this subject class
     $subject1 = $this->targetSubjectClass->createInstance("Sub Subject (Unit Test)");
     $this->assertEquals(count($this->targetSubjectClass->getInstances()), 1);
     // Create a new subject sub class to the previous sub class
     $this->targetSubjectSubClass = $this->targetSubjectClass->createSubClass("Sub Sub Subject Class (Unit Test)");
     // Add an instance to this sub subject class
     $subject2 = $this->targetSubjectSubClass->createInstance("Sub Sub Subject (Unit Test)");
     $this->assertEquals(count($this->targetSubjectSubClass->getInstances()), 1);
     $this->assertEquals(count($this->targetSubjectClass->getInstances()), 1);
     // If get instances in the sub classes of the targetSubjectClass, we should get 2 instances
     $this->assertEquals(count($this->targetSubjectClass->getInstances(true)), 2);
     $this->dataIntegrity['statements0'] = $this->countStatements();
     $this->dataIntegrity['subSubjectClassCount0'] = $this->targetSubjectClass->countInstances();
     $this->dataIntegrity['subSubSubjectClassCount0'] = $this->targetSubjectSubClass->countInstances();
 }
 /**
  * tests initialization
  * load qti service
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     \common_ext_ExtensionsManager::singleton()->getExtensionById('taoItems');
     $itemTopClass = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAOItem.rdf#Item');
     $this->itemClass = $itemTopClass->createSubClass('style service unit test', 'create for unit test ' . time());
     $itemService = \taoItems_models_classes_ItemsService::singleton();
     $qtiItemModel = new \core_kernel_classes_Resource(ItemModel::MODEL_URI);
     $itemA = $this->itemClass->createInstance('itemA');
     $itemService->setItemModel($itemA, $qtiItemModel);
     $itemService->setItemContent($itemA, file_get_contents(dirname(__FILE__) . '/samples/itemA.xml'));
     $this->items[] = $itemA;
     $itemB = $this->itemClass->createInstance('itemB');
     $itemService->setItemModel($itemB, $qtiItemModel);
     $itemService->setItemContent($itemB, file_get_contents(dirname(__FILE__) . '/samples/itemB.xml'));
     $this->items[] = $itemB;
     $itemC = $this->itemClass->createInstance('itemC');
     $itemService->setItemModel($itemC, $qtiItemModel);
     $itemService->setItemContent($itemC, file_get_contents(dirname(__FILE__) . '/samples/itemC.xml'));
     $this->items[] = $itemC;
 }
예제 #9
0
 /**
  * Main method: run the import
  */
 public function import()
 {
     $this->log();
     foreach ($this->getSasFiles() as $extension => $sasFile) {
         $this->parseSasFile($extension, $sasFile);
     }
     //insert process vars
     $processVarNum = count($this->processVars);
     $processVarInserted = 0;
     foreach ($this->processVars as $processVar) {
         if ($this->addProcessVariable($processVar)) {
             $processVarInserted++;
             if (!$this->outputModeWeb) {
                 echo "\r{$processVarInserted} / {$processVarNum}  process variable inserted";
             }
         }
     }
     if ($this->outputModeWeb) {
         $this->log("{$processVarInserted} / {$processVarNum}  process variable inserted");
     } else {
         echo "\n";
     }
     //insert formal params
     $formaParamNum = count($this->formalParams);
     $formaParamInserted = 0;
     foreach ($this->formalParams as $formalParam) {
         if ($this->addFormalParameter($formalParam)) {
             $formaParamInserted++;
             if (!$this->outputModeWeb) {
                 echo "\r{$formaParamInserted} / {$formaParamNum}  formal parameters inserted";
             }
         }
     }
     if ($this->outputModeWeb) {
         $this->log("{$formaParamInserted} / {$formaParamNum}  formal parameters inserted");
     } else {
         echo "\n";
     }
     //insert service definitions
     $serviceNum = count($this->services);
     $serviceInserted = 0;
     foreach ($this->services as $extensionName => $services) {
         $extensionServiceClass = $this->serviceDefClass->createSubClass($extensionName, "{$extensionName} related services");
         foreach ($services as $service) {
             if ($this->addService($extensionServiceClass, $service['name'], $service['url'], $service['description'], $service['params'])) {
                 $serviceInserted++;
                 if (!$this->outputModeWeb) {
                     echo "\r{$serviceInserted} / {$serviceNum}  services definition inserted";
                 }
             }
         }
     }
     if ($this->outputModeWeb) {
         $this->log("{$serviceInserted} / {$serviceNum}  services definition inserted");
     } else {
         echo "\n";
     }
     // @todo remove temporary solution and improve the way AccessControl and workflows interact
     $missingRights = array(array('ext' => 'taoItems', 'mod' => 'SaSItems'), array('ext' => 'taoTestTaker', 'mod' => 'SasTestTaker'), array('ext' => 'taoTestTaker', 'mod' => 'SasImport'), array('ext' => 'taoTests', 'mod' => 'SaSTests'), array('ext' => 'taoGroups', 'mod' => 'SaSGroups'), array('ext' => 'taoDelivery', 'mod' => 'SaSResultServer'), array('ext' => 'taoDelivery', 'mod' => 'SaSDelivery'), array('ext' => 'tao', 'mod' => 'WebService'), array('ext' => 'taoResults', 'mod' => 'SaSResults'), array('ext' => 'tao', 'mod' => 'SaSUsers'), array('ext' => 'tao', 'mod' => 'File'));
     foreach ($missingRights as $filter) {
         $rule = new AccessRule(AccessRule::GRANT, INSTANCE_ROLE_WORKFLOW, $filter);
         AclProxy::applyRule($rule);
     }
     $this->log("import finished");
 }
 /**
  * Import a QTI Test and its dependent Items into the TAO Platform.
  *
  * @param core_kernel_classes_Class $targetClass The RDFS Class where Ontology resources must be created.
  * @param oat\taoQtiItem\model\qti\Resource $qtiTestResource The QTI Test Resource representing the IMS QTI Test to be imported.
  * @param taoQtiTest_models_classes_ManifestParser $manifestParser The parser used to retrieve the IMS Manifest.
  * @param string $folder The absolute path to the folder where the IMS archive containing the test content
  * @return common_report_Report A report about how the importation behaved.
  */
 protected function importTest(core_kernel_classes_Class $targetClass, Resource $qtiTestResource, taoQtiTest_models_classes_ManifestParser $manifestParser, $folder)
 {
     $itemImportService = ImportService::singleton();
     $itemService = taoItems_models_classes_ItemsService::singleton();
     $testClass = $targetClass;
     // Create an RDFS resource in the knowledge base that will hold
     // the information about the imported QTI Test.
     $testResource = $this->createInstance($testClass);
     $qtiTestModelResource = new core_kernel_classes_Resource(INSTANCE_TEST_MODEL_QTI);
     $modelProperty = new core_kernel_classes_Property(PROPERTY_TEST_TESTMODEL);
     $testResource->editPropertyValues($modelProperty, $qtiTestModelResource);
     // Create the report that will hold information about the import
     // of $qtiTestResource in TAO.
     $report = new common_report_Report(common_report_Report::TYPE_INFO);
     // The class where the items that belong to the test will be imported.
     $itemClass = new core_kernel_classes_Class(TAO_ITEM_CLASS);
     $targetClass = $itemClass->createSubClass($testResource->getLabel());
     // Load and validate the manifest
     $qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($folder . 'imsmanifest.xml');
     $qtiManifestParser->validate();
     // Prepare Metadata mechanisms.
     $metadataMapping = oat\taoQtiItem\model\qti\Service::singleton()->getMetadataRegistry()->getMapping();
     $metadataInjectors = array();
     $metadataGuardians = array();
     $metadataClassLookups = array();
     $metadataValues = array();
     $domManifest = new DOMDocument('1.0', 'UTF-8');
     $domManifest->load($folder . 'imsmanifest.xml');
     foreach ($metadataMapping['injectors'] as $injector) {
         $metadataInjectors[] = new $injector();
     }
     foreach ($metadataMapping['guardians'] as $guardian) {
         $metadataGuardians[] = new $guardian();
     }
     foreach ($metadataMapping['classLookups'] as $classLookup) {
         $metadataClassLookups[] = new $classLookup();
     }
     foreach ($metadataMapping['extractors'] as $extractor) {
         $metadataExtractor = new $extractor();
         $metadataValues = array_merge($metadataValues, $metadataExtractor->extract($domManifest));
     }
     // Set up $report with useful information for client code (especially for rollback).
     $reportCtx = new stdClass();
     $reportCtx->manifestResource = $qtiTestResource;
     $reportCtx->rdfsResource = $testResource;
     $reportCtx->itemClass = $targetClass;
     $reportCtx->items = array();
     $report->setData($reportCtx);
     // Expected test.xml file location.
     $expectedTestFile = $folder . str_replace('/', DIRECTORY_SEPARATOR, $qtiTestResource->getFile());
     // Already imported test items (qti xml file paths).
     $alreadyImportedTestItemFiles = array();
     // -- Check if the file referenced by the test QTI resource exists.
     if (is_readable($expectedTestFile) === false) {
         $report->add(common_report_Report::createFailure(__('No file found at location "%s".', $qtiTestResource->getFile())));
     } else {
         // -- Load the test in a QTISM flavour.
         $testDefinition = new XmlDocument();
         try {
             $testDefinition->load($expectedTestFile, true);
             // -- Load all items related to test.
             $itemError = false;
             // discover test's base path.
             $dependencies = taoQtiTest_helpers_Utils::buildAssessmentItemRefsTestMap($testDefinition, $manifestParser, $folder);
             if (count($dependencies['items']) > 0) {
                 foreach ($dependencies['items'] as $assessmentItemRefId => $qtiDependency) {
                     if ($qtiDependency !== false) {
                         if (Resource::isAssessmentItem($qtiDependency->getType())) {
                             $resourceIdentifier = $qtiDependency->getIdentifier();
                             // Check if the item is already stored in the bank.
                             foreach ($metadataGuardians as $guardian) {
                                 if (isset($metadataValues[$resourceIdentifier]) === true) {
                                     if (($guard = $guardian->guard($metadataValues[$resourceIdentifier])) !== false) {
                                         common_Logger::i("Item with identifier '{$resourceIdentifier}' already in Item Bank.");
                                         $msg = __('The IMS QTI Item referenced as "%s" in the IMS Manifest file was already stored in the Item Bank.', $resourceIdentifier);
                                         $report->add(common_report_Report::createInfo($msg, $guard));
                                         $reportCtx->items[$assessmentItemRefId] = $guard;
                                         // Simply do not import again.
                                         continue 2;
                                     }
                                 }
                             }
                             // Determine target class from metadata, if possible.
                             // This is applied to items, not for test definitions.
                             // The test definitions' target class will not be affected
                             // by class lookups.
                             $lookupTargetClass = false;
                             foreach ($metadataClassLookups as $classLookup) {
                                 if (isset($metadataValues[$resourceIdentifier]) === true) {
                                     if (($lookupTargetClass = $classLookup->lookup($metadataValues[$resourceIdentifier])) !== false) {
                                         break;
                                     }
                                 }
                             }
                             $qtiFile = $folder . str_replace('/', DIRECTORY_SEPARATOR, $qtiDependency->getFile());
                             // Skip if $qtiFile already imported (multiple assessmentItemRef "hrefing" the same file).
                             if (array_key_exists($qtiFile, $alreadyImportedTestItemFiles) === false) {
                                 $isApip = $qtiDependency->getType() === 'imsqti_apipitem_xmlv2p1';
                                 $itemReport = $itemImportService->importQtiItem($folder, $qtiDependency, $lookupTargetClass !== false ? $lookupTargetClass : $targetClass, $isApip, $dependencies['dependencies']);
                                 $rdfItem = $itemReport->getData();
                                 if ($rdfItem) {
                                     $reportCtx->items[$assessmentItemRefId] = $rdfItem;
                                     $alreadyImportedTestItemFiles[$qtiFile] = $rdfItem;
                                     $itemReport->setMessage(__('IMS QTI Item referenced as "%s" in the IMS Manifest file successfully imported.', $qtiDependency->getIdentifier()));
                                 } else {
                                     $itemReport->setType(common_report_Report::TYPE_ERROR);
                                     $itemReport->setMessage(__('IMS QTI Item referenced as "%s" in the IMS Manifest file could not be imported.', $qtiDependency->getIdentifier()));
                                     $itemError = $itemError === false ? true : $itemError;
                                 }
                                 $report->add($itemReport);
                             } else {
                                 $reportCtx->items[$assessmentItemRefId] = $alreadyImportedTestItemFiles[$qtiFile];
                             }
                         }
                     } else {
                         $msg = __('The dependency to the IMS QTI AssessmentItemRef "%s" in the IMS Manifest file could not be resolved.', $assessmentItemRefId);
                         $report->add(common_report_Report::createFailure($msg));
                         $itemError = $itemError === false ? true : $itemError;
                     }
                 }
                 // If items did not produce errors, we import the test definition.
                 if ($itemError === false) {
                     common_Logger::i('Importing test...');
                     // Second step is to take care of the test definition and the related media (auxiliary files).
                     // 1. Import test definition (i.e. the QTI-XML Test file).
                     $testContent = $this->importTestDefinition($testResource, $testDefinition, $qtiTestResource, $reportCtx->items, $folder, $report);
                     if ($testContent !== false) {
                         // 2. Import test auxilliary files (e.g. stylesheets, images, ...).
                         $this->importTestAuxiliaryFiles($testContent, $qtiTestResource, $folder, $report);
                         // 3. Give meaningful names to resources.
                         $testTitle = $testDefinition->getDocumentComponent()->getTitle();
                         $testResource->setLabel($testDefinition->getDocumentComponent()->getTitle());
                         $targetClass->setLabel($testDefinition->getDocumentComponent()->getTitle());
                         // 4. if $targetClass does not contain any instances (because everything resolved by class lookups),
                         // Just delete it.
                         if ($targetClass->countInstances() == 0) {
                             $targetClass->delete();
                         }
                     }
                 } else {
                     $msg = __("One or more dependent IMS QTI Items could not be imported.");
                     $report->add(common_report_Report::createFailure($msg));
                 }
             } else {
                 // No depencies found (i.e. no item resources bound to the test).
                 $msg = __("No reference to any IMS QTI Item found.");
                 $report->add(common_report_Report::createFailure($msg));
             }
         } catch (StorageException $e) {
             // Source of the exception = $testDefinition->load()
             // What is the reason ?
             $finalErrorString = '';
             $eStrs = array();
             if (($libXmlErrors = $e->getErrors()) !== null) {
                 foreach ($libXmlErrors as $libXmlError) {
                     $eStrs[] = __('XML error at line %1$d column %2$d "%3$s".', $libXmlError->line, $libXmlError->column, trim($libXmlError->message));
                 }
             }
             $finalErrorString = implode("\n", $eStrs);
             if (empty($finalErrorString) === true) {
                 // Not XML malformation related. No info from LibXmlErrors extracted.
                 if (($previous = $e->getPrevious()) != null) {
                     // Useful information could be found here.
                     $finalErrorString = $previous->getMessage();
                     if ($previous instanceof UnmarshallingException) {
                         $domElement = $previous->getDOMElement();
                         $finalErrorString = __('Inconsistency at line %1d:', $domElement->getLineNo()) . ' ' . $previous->getMessage();
                     }
                 } else {
                     $finalErrorString = __("Unknown error.");
                 }
             }
             $msg = __("Error found in the IMS QTI Test:\n%s", $finalErrorString);
             $report->add(common_report_Report::createFailure($msg));
         }
     }
     if ($report->containsError() === false) {
         $report->setType(common_report_Report::TYPE_SUCCESS);
         $msg = __("IMS QTI Test referenced as \"%s\" in the IMS Manifest file successfully imported.", $qtiTestResource->getIdentifier());
         $report->setMessage($msg);
     } else {
         $report->setType(common_report_Report::TYPE_ERROR);
         $msg = __("The IMS QTI Test referenced as \"%s\" in the IMS Manifest file could not be imported.", $qtiTestResource->getIdentifier());
         $report->setMessage($msg);
     }
     return $report;
 }
 /**
  * Import a QTI Test and its dependent Items into the TAO Platform.
  *
  * @param core_kernel_classes_Class $targetClass The RDFS Class where Ontology resources must be created.
  * @param oat\taoQtiItem\model\qti\Resource $qtiTestResource The QTI Test Resource representing the IMS QTI Test to be imported.
  * @param taoQtiTest_models_classes_ManifestParser $manifestParser The parser used to retrieve the IMS Manifest.
  * @param string $folder The absolute path to the folder where the IMS archive containing the test content
  * @return common_report_Report A report about how the importation behaved.
  */
 protected function importTest(core_kernel_classes_Class $targetClass, Resource $qtiTestResource, taoQtiTest_models_classes_ManifestParser $manifestParser, $folder)
 {
     $itemImportService = ImportService::singleton();
     $itemService = taoItems_models_classes_ItemsService::singleton();
     $testClass = $targetClass;
     // Create an RDFS resource in the knowledge base that will hold
     // the information about the imported QTI Test.
     $testResource = $this->createInstance($testClass);
     $qtiTestModelResource = new core_kernel_classes_Resource(INSTANCE_TEST_MODEL_QTI);
     $modelProperty = new core_kernel_classes_Property(PROPERTY_TEST_TESTMODEL);
     $testResource->editPropertyValues($modelProperty, $qtiTestModelResource);
     // Create the report that will hold information about the import
     // of $qtiTestResource in TAO.
     $report = new common_report_Report(common_report_Report::TYPE_INFO);
     // The class where the items that belong to the test will be imported.
     $itemClass = new core_kernel_classes_Class(TAO_ITEM_CLASS);
     $targetClass = $itemClass->createSubClass($testResource->getLabel());
     // Load and validate the manifest
     $qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($folder . 'imsmanifest.xml');
     $qtiManifestParser->validate();
     // Set up $report with useful information for client code (especially for rollback).
     $reportCtx = new stdClass();
     $reportCtx->manifestResource = $qtiTestResource;
     $reportCtx->rdfsResource = $testResource;
     $reportCtx->itemClass = $targetClass;
     $reportCtx->items = array();
     $report->setData($reportCtx);
     // Expected test.xml file location.
     $expectedTestFile = $folder . str_replace('/', DIRECTORY_SEPARATOR, $qtiTestResource->getFile());
     // Already imported test items (qti xml file paths).
     $alreadyImportedTestItemFiles = array();
     // -- Check if the file referenced by the test QTI resource exists.
     if (is_readable($expectedTestFile) === false) {
         $report->add(common_report_Report::createFailure(__('No file found at location "%s".', $qtiTestResource->getFile())));
     } else {
         // -- Load the test in a QTISM flavour.
         $testDefinition = new XmlDocument();
         try {
             $testDefinition->load($expectedTestFile, true);
             // -- Load all items related to test.
             $itemError = false;
             // discover test's base path.
             $dependencies = taoQtiTest_helpers_Utils::buildAssessmentItemRefsTestMap($testDefinition, $manifestParser, $folder);
             if (count($dependencies) > 0) {
                 foreach ($dependencies as $assessmentItemRefId => $qtiDependency) {
                     if ($qtiDependency !== false) {
                         if (Resource::isAssessmentItem($qtiDependency->getType())) {
                             $qtiFile = $folder . str_replace('/', DIRECTORY_SEPARATOR, $qtiDependency->getFile());
                             // Skip if $qtiFile already imported (multiple assessmentItemRef "hrefing" the same file).
                             if (array_key_exists($qtiFile, $alreadyImportedTestItemFiles) === false) {
                                 $itemReport = $itemImportService->importQTIFile($qtiFile, $targetClass);
                                 $rdfItem = $itemReport->getData();
                                 if ($rdfItem) {
                                     $itemPath = taoItems_models_classes_ItemsService::singleton()->getItemFolder($rdfItem);
                                     foreach ($qtiDependency->getAuxiliaryFiles() as $auxResource) {
                                         // $auxResource is a relativ URL, so we need to replace the slashes with directory separators
                                         $auxPath = $folder . str_replace('/', DIRECTORY_SEPARATOR, $auxResource);
                                         // does the file referenced by $auxPath exist?
                                         if (is_readable($auxPath) === true) {
                                             $relPath = helpers_File::getRelPath($qtiFile, $auxPath);
                                             $destPath = $itemPath . $relPath;
                                             tao_helpers_File::copy($auxPath, $destPath, true);
                                         } else {
                                             $msg = __('Auxiliary file not found at location "%s".', $auxResource);
                                             $itemReport->add(new common_report_Report(common_report_Report::TYPE_WARNING, $msg));
                                         }
                                     }
                                     $reportCtx->items[$assessmentItemRefId] = $rdfItem;
                                     $alreadyImportedTestItemFiles[$qtiFile] = $rdfItem;
                                     $itemReport->setMessage(__('IMS QTI Item referenced as "%s" in the IMS Manifest file successfully imported.', $qtiDependency->getIdentifier()));
                                 } else {
                                     $itemReport->setType(common_report_Report::TYPE_ERROR);
                                     $itemReport->setMessage(__('IMS QTI Item referenced as "%s" in the IMS Manifest file could not be imported.', $qtiDependency->getIdentifier()));
                                     $itemError = $itemError === false ? true : $itemError;
                                 }
                                 $report->add($itemReport);
                             } else {
                                 $reportCtx->items[$assessmentItemRefId] = $alreadyImportedTestItemFiles[$qtiFile];
                             }
                         }
                     } else {
                         $msg = __('The dependency to the IMS QTI AssessmentItemRef "%s" in the IMS Manifest file could not be resolved.', $assessmentItemRefId);
                         $report->add(common_report_Report::createFailure($msg));
                         $itemError = $itemError === false ? true : $itemError;
                     }
                 }
                 // If items did not produce errors, we import the test definition.
                 if ($itemError === false) {
                     common_Logger::i('Importing test...');
                     // Second step is to take care of the test definition and the related media (auxiliary files).
                     // 1. Import test definition (i.e. the QTI-XML Test file).
                     $testContent = $this->importTestDefinition($testResource, $testDefinition, $qtiTestResource, $reportCtx->items, $folder, $report);
                     if ($testContent !== false) {
                         // 2. Import test auxilliary files (e.g. stylesheets, images, ...).
                         $this->importTestAuxiliaryFiles($testContent, $qtiTestResource, $folder, $report);
                         // 3. Give meaningful names to resources.
                         $testTitle = $testDefinition->getDocumentComponent()->getTitle();
                         $testResource->setLabel($testDefinition->getDocumentComponent()->getTitle());
                         $targetClass->setLabel($testDefinition->getDocumentComponent()->getTitle());
                     }
                 } else {
                     $msg = __("One or more dependent IMS QTI Items could not be imported.");
                     $report->add(common_report_Report::createFailure($msg));
                 }
             } else {
                 // No depencies found (i.e. no item resources bound to the test).
                 $msg = __("No reference to any IMS QTI Item found.");
                 $report->add(common_report_Report::createFailure($msg));
             }
         } catch (StorageException $e) {
             // Source of the exception = $testDefinition->load()
             // What is the reason ?
             $finalErrorString = '';
             $eStrs = array();
             if (($libXmlErrors = $e->getErrors()) !== null) {
                 foreach ($libXmlErrors as $libXmlError) {
                     $eStrs[] = __('XML error at line %1$d column %2$d "%3$s".', $libXmlError->line, $libXmlError->column, trim($libXmlError->message));
                 }
             }
             $finalErrorString = implode("\n", $eStrs);
             if (empty($finalErrorString) === true) {
                 // Not XML malformation related. No info from LibXmlErrors extracted.
                 if (($previous = $e->getPrevious()) != null) {
                     // Useful information could be found here.
                     $finalErrorString = $previous->getMessage();
                     if ($previous instanceof UnmarshallingException) {
                         $domElement = $previous->getDOMElement();
                         $finalErrorString = __('Inconsistency at line %1d:', $domElement->getLineNo()) . ' ' . $previous->getMessage();
                     }
                 } else {
                     $finalErrorString = __("Unknown error.");
                 }
             }
             $msg = __("Error found in the IMS QTI Test:\n%s", $finalErrorString);
             $report->add(common_report_Report::createFailure($msg));
         }
     }
     if ($report->containsError() === false) {
         $report->setType(common_report_Report::TYPE_SUCCESS);
         $msg = __("IMS QTI Test referenced as \"%s\" in the IMS Manifest file successfully imported.", $qtiTestResource->getIdentifier());
         $report->setMessage($msg);
     } else {
         $report->setType(common_report_Report::TYPE_ERROR);
         $msg = __("The IMS QTI Test referenced as \"%s\" in the IMS Manifest file could not be imported.", $qtiTestResource->getIdentifier());
         $report->setMessage($msg);
     }
     return $report;
 }
 public function testCreateUnits()
 {
     set_time_limit(300);
     $this->itemClass = null;
     $this->units = array();
     $this->properties = array();
     $this->files = array();
     $classUri = LOCAL_NAMESPACE . '#TranslationItemsClass';
     $translationClass = new core_kernel_classes_Class($classUri);
     if (!$translationClass->exists()) {
         $itemClass = new core_kernel_classes_Class(TAO_ITEM_CLASS);
         $translationClass = $itemClass->createSubClass('Translation Items', 'created for translation process execution test case', $classUri);
         $this->assertIsA($translationClass, 'core_kernel_classes_Class');
     }
     $this->itemClass = $translationClass;
     foreach ($this->unitNames as $unitName) {
         //create unit:
         $this->units[$unitName] = $translationClass->createInstance($unitName, 'created for translation process execution test case');
         $this->assertNotNull($this->units[$unitName]);
     }
     //		var_dump($this->units, $this->properties, $this->files);
 }
 public function testSetType()
 {
     $this->hardify();
     $this->setProperties();
     $this->targetSongClass = $this->targetWorkClass->createSubClass('Song', 'The Song Class');
     $instance = $this->targetWorkClass->createInstance('setType test instance');
     $sanityCheckInstance = $this->targetWorkClass->createInstance('sanityCheck setType test');
     // verify everything is sane to begin with
     $this->assertIsA($instance, 'core_kernel_classes_resource');
     $this->assertTrue($instance->exists());
     $this->assertIsA($sanityCheckInstance, 'core_kernel_classes_resource');
     $this->assertTrue($sanityCheckInstance->exists());
     $instfound = 0;
     $sanityfound = 0;
     foreach ($this->targetWorkClass->getInstances() as $workInst) {
         if ($workInst->equals($instance)) {
             $instfound++;
         }
         if ($workInst->equals($sanityCheckInstance)) {
             $sanityfound++;
         }
     }
     $this->assertEquals($instfound, 1);
     $this->assertEquals($sanityfound, 1);
     foreach ($this->targetSongClass->getInstances() as $songInst) {
         $this->assertFalse($songInst->equals($instance), 'instance in getInstances of targetSongclass');
         $this->assertFalse($songInst->equals($sanityCheckInstance), 'sanity check instance in getInstances of targetSongclass');
     }
     $types = $instance->getTypes();
     $this->assertEquals(count($types), 1);
     $this->assertTrue($this->targetWorkClass->equals(current($types)));
     // remove the old type (targetWorkClass)
     $this->assertTrue($instance->removeType($this->targetWorkClass));
     $types = $instance->getTypes();
     $this->assertEquals(count($types), 0);
     $sanityfound = 0;
     foreach ($this->targetWorkClass->getInstances() as $workInst) {
         if ($workInst->equals($sanityCheckInstance)) {
             $sanityfound++;
         }
         $this->assertFalse($workInst->equals($instance), 'instance still in getInstances() of class after removeType()');
     }
     $this->assertEquals($sanityfound, 1);
     foreach ($this->targetSongClass->getInstances() as $songInst) {
         $this->assertFalse($songInst->equals($instance), 'instance in getInstances of targetSongclass');
         $this->assertFalse($songInst->equals($sanityCheckInstance), 'sanity check instance in getInstances of targetSongclass');
     }
     // set the new type (targetSongClass)
     $this->assertTrue($instance->setType($this->targetSongClass));
     $types = $instance->getTypes();
     $this->assertEquals(count($types), 1);
     $this->assertTrue($this->targetSongClass->equals(current($types)));
     $sanityfound = 0;
     foreach ($this->targetWorkClass->getInstances() as $workInst) {
         if ($workInst->equals($sanityCheckInstance)) {
             $sanityfound++;
         }
         $this->assertFalse($workInst->equals($instance), 'instance still in getInstances() of class after removeType()');
     }
     $this->assertEquals($sanityfound, 1);
     $instfound = 0;
     foreach ($this->targetSongClass->getInstances() as $songInst) {
         if ($songInst->equals($instance)) {
             $instfound++;
         }
         $this->assertFalse($songInst->equals($sanityCheckInstance), 'sanity check instance in getInstances of targetSongclass');
     }
     $this->assertEquals($instfound, 1);
     // cleanup and check cleanup
     $this->assertTrue($instance->delete());
     $this->assertFalse($instance->exists());
     $this->assertTrue($sanityCheckInstance->delete());
     $this->assertFalse($sanityCheckInstance->exists());
     foreach ($this->targetWorkClass->getInstances() as $workInst) {
         $this->assertFalse($workInst->equals($instance), 'instance still in getInstances() of class targetWorkClass after delete()');
         $this->assertFalse($workInst->equals($sanityCheckInstance), 'instance still in getInstances() of class targetWorkClass after delete()');
     }
     foreach ($this->targetSongClass->getInstances() as $songInst) {
         $this->assertFalse($songInst->equals($instance), 'instance still in getInstances() of class targetSongClass after delete()');
         $this->assertFalse($songInst->equals($sanityCheckInstance), 'instance still in getInstances() of class targetSongClass after delete()');
     }
 }
예제 #14
0
 public function testDeleteInstances()
 {
     $taoClass = new core_kernel_classes_Class(CLASS_GENERIS_RESOURCE);
     $creativeWorkClass = $taoClass->createSubClass('Creative Work');
     $authorProperty = $taoClass->createProperty('Author');
     $relatedWorksProperty = $creativeWorkClass->createProperty('Related Works');
     $bookLotr = $creativeWorkClass->createInstance('The Lord of The Rings (book)');
     $bookLotr->setPropertyValue($authorProperty, 'J.R.R. Tolkien');
     $movieLotr = $creativeWorkClass->createInstance('The Lord of The Rings (movie)');
     $movieLotr->setPropertyValue($authorProperty, 'Peter Jackson');
     $movieLotr->setPropertyValue($relatedWorksProperty, $bookLotr);
     $bookLotr->setPropertyValue($relatedWorksProperty, $movieLotr);
     $movieMinorityReport = $creativeWorkClass->createInstance('Minority Report');
     $movieMinorityReport->setPropertyValue($authorProperty, 'Steven Spielberg');
     $this->assertEquals(count($creativeWorkClass->getInstances()), 3);
     // delete the LOTR movie with its references.
     $relatedWorks = $bookLotr->getPropertyValuesCollection($relatedWorksProperty);
     $this->assertEquals($relatedWorks->sequence[0]->getLabel(), 'The Lord of The Rings (movie)');
     $creativeWorkClass->deleteInstances(array($movieLotr), true);
     $relatedWorks = $bookLotr->getPropertyValues($relatedWorksProperty);
     $this->assertEquals(count($relatedWorks), 0);
     // Only 1 resource deleted ?
     $this->assertFalse($movieLotr->exists());
     $this->assertTrue($bookLotr->exists());
     $this->assertTrue($movieMinorityReport->exists());
     // Remove the rest.
     $creativeWorkClass->deleteInstances(array($bookLotr, $movieMinorityReport));
     $this->assertEquals(count($creativeWorkClass->getInstances()), 0);
     $this->assertFalse($bookLotr->exists());
     $this->assertFalse($movieMinorityReport->exists());
     $this->assertTrue($authorProperty->delete());
     $this->assertTrue($relatedWorksProperty->delete());
     $creativeWorkClass->delete(true);
 }
 public function testSearchInstancesMultipleImpl()
 {
     $clazz = new core_kernel_classes_Class(RDFS_CLASS);
     $sub1Clazz = $clazz->createSubClass();
     $sub1ClazzInstance = $sub1Clazz->createInstance('test case instance');
     $sub2Clazz = $sub1Clazz->createSubClass();
     $sub2ClazzInstance = $sub2Clazz->createInstance('test case instance');
     $sub3Clazz = $sub2Clazz->createSubClass();
     $sub3ClazzInstance = $sub3Clazz->createInstance('test case instance');
     $options = array('recursive' => true, 'append' => true, 'createForeigns' => true, 'referencesAllTypes' => true, 'rmSources' => true);
     //Test the search instances on the smooth impl
     $propertyFilter = array(RDFS_LABEL => 'test case instance');
     $instances = $clazz->searchInstances($propertyFilter, array('recursive' => true));
     $this->assertTrue(array_key_exists($sub1ClazzInstance->getUri(), $instances));
     $this->assertTrue(array_key_exists($sub2ClazzInstance->getUri(), $instances));
     $this->assertTrue(array_key_exists($sub3ClazzInstance->getUri(), $instances));
     common_Logger::d('starting hardify');
     //Test the search instances on the hard impl
     $switcher = new Switcher();
     $switcher->hardify($sub1Clazz, $options);
     unset($switcher);
     //Required to update cache data
     common_Logger::d('done hardify');
     $propertyFilter = array(RDFS_LABEL => 'test case instance');
     $instances = $sub1Clazz->searchInstances($propertyFilter, array('recursive' => true));
     $this->assertTrue(array_key_exists($sub1ClazzInstance->getUri(), $instances));
     $this->assertTrue(array_key_exists($sub2ClazzInstance->getUri(), $instances));
     $this->assertTrue(array_key_exists($sub3ClazzInstance->getUri(), $instances));
     $switcher = new Switcher();
     $switcher->unhardify($sub1Clazz, $options);
     unset($switcher);
     //Required to update cache data
     //Test the search instances on a shared model (smooth + hard)
     //Disable recursivity on hardify, and hardify the sub2Clazz
     $switcher = new Switcher();
     $options['recursive'] = false;
     $switcher->hardify($sub2Clazz, $options);
     unset($switcher);
     //Required to update cache data
     $instances = $sub1Clazz->searchInstances($propertyFilter, array('recursive' => true));
     $this->assertTrue(array_key_exists($sub1ClazzInstance->getUri(), $instances));
     $this->assertTrue(array_key_exists($sub2ClazzInstance->getUri(), $instances));
     $this->assertTrue(array_key_exists($sub3ClazzInstance->getUri(), $instances));
     try {
         $instances = $sub1Clazz->searchInstances($propertyFilter, array('recursive' => true, 'offset' => 1));
         $this->assertTrue(false);
     } catch (common_Exception $e) {
         $this->assertTrue(true);
     }
     $switcher = new Switcher();
     $switcher->unhardify($sub2Clazz, $options);
     unset($switcher);
     //Required to update cache data
     //clean data test
     foreach ($sub1Clazz->getInstances(true) as $instance) {
         $instance->delete();
     }
     $sub1Clazz->delete(true);
     $sub2Clazz->delete(true);
     $sub3Clazz->delete(true);
 }