public function testInject() { $generisClass = new core_kernel_classes_Class(CLASS_GENERIS_RESOURCE); $testClass = $generisClass->createSubClass(); $switcher = new Switcher(); $switcher->hardify($testClass); 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 (Exception $e) { $this->fail('SQL Error: ' . $e->getMessage()); } $testInstance->delete(); $switcher->unhardify($testClass); $testClass->delete(); }
public function testCreateInstanceHardified() { $rr = ResourceReferencer::singleton(); $this->assertFalse($rr->isClassReferenced($this->class)); $softinstance = core_kernel_classes_ResourceFactory::create($this->class); $this->assertFalse($rr->isResourceReferenced($softinstance)); $switcher = new Switcher(); $switcher->hardify($this->class, array('topclass' => $this->class)); unset($switcher); $this->assertTrue($rr->isClassReferenced($this->class)); common_Logger::i('creating hardified'); $hardinstance = core_kernel_classes_ResourceFactory::create($this->class); $this->assertTrue($rr->isResourceReferenced($hardinstance), 'Instance created from harmode class was added in softmode'); $softinstance->delete(); $hardinstance->delete(); $switcher = new Switcher(); $switcher->unhardify($this->class); unset($switcher); }
public function testUnhardifier() { $switcher = new Switcher(); $switcher->unhardify($this->targetSubjectClass, array('recursive' => true, 'removeForeigns' => false)); unset($switcher); }
/** * Overlaod resource::delete to remove refrence * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param Resource resource * @param boolean deleteReference * @return boolean */ public function delete(\core_kernel_classes_Resource $resource, $deleteReference = false) { $returnValue = (bool) false; $switcher = new Switcher(); $success = $switcher->unhardify(new \core_kernel_classes_Class($resource)); if (true == $success) { $returnValue = \core_kernel_persistence_smoothsql_Class::singleton()->delete($resource, $deleteReference); } else { $returnValue = false; } return (bool) $returnValue; }
/** * Decompile a specific class with the decompilation options found in the data returned * by the decompileClass method. * * This method returns an associative array containing the following informations: * * array( * "success" => true/false, * "count" => integer // the class instances that were unoptimized * "relatedClasses" => array("class1", "class2", ...) // the classes that were impacted by the unoptimization * // depending on the unoptimization options * ) * * @see Optimization::decompileClass() * @param \core_kernel_classes_Class class The class you would like to compile. */ public static function decompileClass(\core_kernel_classes_Class $class) { $result = array('success' => false); $optimizableClasses = self::getOptimizableClasses(); if (isset($optimizableClasses[$class->getUri()]) && isset($optimizableClasses[$class->getUri()]['decompile'])) { //build the option array and launch the compilation: $userDefinedOptions = array(); $options = array_merge($optimizableClasses[$class->getUri()]['decompile'], $userDefinedOptions); $switcher = new Switcher(); $switcher->unhardify($class, $options); //prepare return value $decompiledClass = $switcher->getDecompiledClasses(); $count = isset($decompiledClass[$class->getUri()]) ? $decompiledClass[$class->getUri()] : 0; $relatedClasses = array(); foreach ($decompiledClass as $relatedClassUri => $nb) { if ($relatedClassUri != $class->getUri()) { $relatedClass = new \core_kernel_classes_Class($relatedClassUri); $relatedClasses[$relatedClass->getLabel()] = $nb; } } $result = array('success' => true, 'count' => $count, 'relatedClasses' => $relatedClasses); unset($switcher); } return $result; }
public function testHardGetInstances() { $this->hardify(); // Get the hardified instance from the hard sql imlpementation $this->assertEquals(count($this->targetSubjectClass->getInstances()), 1); $this->assertEquals(count($this->targetSubjectSubClass->getInstances()), 1); $this->assertEquals(count($this->targetSubjectClass->getInstances(true)), 2); $this->assertEquals(count($this->targetWorkClass->getInstances(true)), 0); $this->assertEquals(count($this->targetMovieClass->getInstances()), 0); $userClass = new core_kernel_classes_Class(CLASS_GENERIS_USER); $users = $userClass->getInstances(); $this->assertEquals(count($users), 1); $user = $userClass->createInstance('toto', 'toto'); $switcher = new Switcher(); $switcher->hardify($userClass, array('recursive' => false)); $users = $userClass->getInstances(); $this->assertEquals(count($users), 2); $switcher->unhardify($userClass, array('recursive' => false)); $this->assertTrue($user->delete()); }
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); }