示例#1
0
 public function tearDown()
 {
     foreach ($this->topClass->getInstances(true) as $instance) {
         $instance->delete();
     }
     foreach ($this->topClass->getSubClasses(true) as $subClass) {
         $subClass->delete();
     }
     $this->topClass->delete();
     $this->emptyClass->delete();
 }
 public function clean()
 {
     $referencer = ResourceReferencer::singleton();
     $classProxy = ClassProxy::singleton();
     $switcher = new Switcher();
     // Remove the resources
     foreach ($this->targetSubjectClass->getInstances() as $instance) {
         $instance->delete();
         $this->assertFalse($referencer->isResourceReferenced($instance));
     }
     foreach ($this->targetSubjectSubClass->getInstances() as $instance) {
         $instance->delete();
         $this->assertFalse($referencer->isResourceReferenced($instance));
     }
     // delete the sub subject class (will be internally unhardified)
     $this->targetSubjectClass->delete(true);
     $this->assertFalse($referencer->isClassReferenced($this->targetSubjectClass));
     $this->assertIsA($classProxy->getImpToDelegateTo($this->targetSubjectClass), 'core_kernel_persistence_smoothsql_Class');
     // delete the sub sub subject class (will be internally unhardified)
     $this->targetSubjectSubClass->delete(true);
     $this->assertFalse($referencer->isClassReferenced($this->targetSubjectSubClass));
     $this->assertIsA($classProxy->getImpToDelegateTo($this->targetSubjectSubClass), 'core_kernel_persistence_smoothsql_Class');
     $this->assertTrue($this->targetWorkClass->delete(true));
     $this->assertTrue($this->targetMovieClass->delete(true));
     if ($this->targetSongClass != null) {
         $this->targetSongClass->delete(true);
     }
     //$this->assertFalse($referencer->isClassReferenced($this->targetWorkClass));
     //$this->assertFalse($referencer->isClassReferenced($this->targetMovieClass));
     //$this->assertFalse($referencer->isClassReferenced($this->targetSongClass));
     //$this->assertFalse($this->targetWorkClass->exists());
     //$this->assertFalse($this->targetWorkClass->exists());
     //$this->assertFalse($this->targetSongClass->exists());
 }
 /**
  * Delete a subclass
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Class clazz
  * @return boolean
  */
 public function deleteClass(core_kernel_classes_Class $clazz)
 {
     $returnValue = (bool) false;
     if ($clazz->isSubClassOf($this->getRootClass()) && !$clazz->equals($this->getRootClass())) {
         $returnValue = $clazz->delete();
     } else {
         common_Logger::w('Tried to delete class ' . $clazz->getUri() . ' as if it were a subclass of ' . $this->getRootClass()->getUri());
     }
     return (bool) $returnValue;
 }
 /**
  * (non-PHPdoc)
  *
  * @see \oat\tao\model\media\MediaManagement::delete
  */
 public function delete($link)
 {
     $instance = new \core_kernel_classes_Class(\tao_helpers_Uri::decode($link));
     $fileLink = $instance->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
     $fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string) $fileLink;
     $instance->delete();
     $fileManager = FileManager::getFileManagementModel();
     $deleted = $fileManager->deleteFile($fileLink);
     return $deleted;
 }
 public static function tearDownAfterClass()
 {
     \taoItems_models_classes_ItemsService::singleton()->deleteItem(self::$itemResource);
     // Unregister Metadata ClassLookup.
     \oat\taoQtiItem\model\qti\Service::singleton()->getMetadataRegistry()->unregisterMetadataClassLookup('oat\\taoQtiItem\\model\\qti\\metadata\\classLookups\\LabelClassLookup');
     // Unregister Metadata Extractor.
     \oat\taoQtiItem\model\qti\Service::singleton()->getMetadataRegistry()->unregisterMetadataExtractor('oat\\taoQtiItem\\model\\qti\\metadata\\imsManifest\\ImsManifestMetadataExtractor');
     // Delete fake class
     $class = new \core_kernel_classes_Class('http://www.test.com#mytestclass');
     $class->delete(true);
 }
示例#6
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();
 }
示例#7
0
 /**
  * Delete a subclass
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param core_kernel_classes_Class $clazz            
  * @return boolean
  */
 public function deleteClass(core_kernel_classes_Class $clazz)
 {
     $returnValue = (bool) false;
     if ($clazz->isSubClassOf($this->getRootClass()) && !$clazz->equals($this->getRootClass())) {
         $returnValue = true;
         $subclasses = $clazz->getSubClasses(false);
         foreach ($subclasses as $subclass) {
             $returnValue = $returnValue && $this->deleteClass($subclass);
         }
         foreach ($clazz->getProperties() as $classProperty) {
             $returnValue = $returnValue && $this->deleteClassProperty($classProperty);
         }
         $returnValue = $returnValue && $clazz->delete();
     } else {
         common_Logger::w('Tried to delete class ' . $clazz->getUri() . ' as if it were a subclass of ' . $this->getRootClass()->getUri());
     }
     return (bool) $returnValue;
 }
 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();
 }
示例#9
0
 public function testClearRoles()
 {
     $prefix = LOCAL_NAMESPACE . '#';
     $roleUris = array($prefix . 'baseRole', $prefix . 'subRole1', $prefix . 'subRole2', $prefix . 'subRole3', $prefix . 'subRole11', $prefix . 'subRole12', $prefix . 'subRole13');
     foreach ($roleUris as $ru) {
         $r = new core_kernel_classes_Class($ru);
         $r->delete(true);
         $this->assertFalse($r->exists());
     }
 }
 public function testCreateMediaInstance()
 {
     $fileTmp = dirname(__DIR__) . '/sample/Brazil.png';
     $this->initializeMock($fileTmp);
     $lang = 'EN-en';
     $classUri = $this->testClass->getUri();
     //clear previous tests
     $root = new \core_kernel_classes_Class($classUri);
     $link = $this->mediaService->createMediaInstance($fileTmp, $classUri, $lang);
     $root = new \core_kernel_classes_Class($classUri);
     $instances = $root->getInstances();
     /** @var \core_kernel_classes_Resource $instance */
     $instance = array_pop($instances);
     $thing = $instance->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
     $linkResult = $thing instanceof \core_kernel_classes_Resource ? $thing->getUri() : (string) $thing;
     $this->assertInstanceOf('\\core_kernel_classes_Resource', $instance, 'It should create an instance under the class in parameter');
     $this->assertEquals('Brazil.png', $instance->getLabel(), 'The instance label is wrong');
     $this->assertInternalType('string', $link, 'The method return should be a string');
     $this->assertEquals($instance->getUri(), $link, 'The instance link is wrong');
     $this->assertEquals($linkResult, 'MyGreatLink', 'The returned link is wrong');
     $this->assertEquals($lang, $instance->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LANGUAGE)), 'The instance language is wrong');
     $root->delete(true);
     $root->setSubClassOf($this->mediaService->getRootClass());
 }