/**
  * Render the add property sub form.
  * @throws Exception
  * @return void
  * @requiresRight id WRITE
  */
 public function addClassProperty()
 {
     if (!tao_helpers_Request::isAjax()) {
         throw new Exception("wrong request mode");
     }
     $clazz = new core_kernel_classes_Class($this->getRequestParameter('id'));
     if ($this->hasRequestParameter('index')) {
         $index = $this->getRequestParameter('index');
     } else {
         $index = count($clazz->getProperties(false)) + 1;
     }
     $propMode = 'simple';
     if ($this->hasSessionAttribute('property_mode')) {
         $propMode = $this->getSessionAttribute('property_mode');
     }
     //instanciate a property form
     $propFormClass = 'tao_actions_form_' . ucfirst(strtolower($propMode)) . 'Property';
     if (!class_exists($propFormClass)) {
         $propFormClass = 'tao_actions_form_SimpleProperty';
     }
     $propFormContainer = new $propFormClass($clazz, $clazz->createProperty('Property_' . $index), array('index' => $index));
     $myForm = $propFormContainer->getForm();
     $this->setData('data', $myForm->renderElements());
     $this->setView('blank.tpl', 'tao');
 }
 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 a custom property to the newly created class
     // Add an instance to this subject class
     $this->subject1 = $this->targetSubjectClass->createInstance("Sub Subject (Unit Test)");
     // 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
     $this->subject2 = $this->targetSubjectSubClass->createInstance("Sub Sub Subject (Unit Test)");
     // ----- Top Class : Work
     // Create a class and test its instances & properties.
     $this->taoClass = new core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAO.rdf#TAOObject');
     $this->targetWorkClass = $this->taoClass->createSubClass('Work', 'The Work class');
     // Add properties to the Work class.
     $this->targetAuthorProperty = $this->targetWorkClass->createProperty('Author', 'The author of the work.');
     $literalClass = new core_kernel_classes_Class(RDFS_LITERAL);
     $this->targetAuthorProperty->setRange($literalClass);
     // Create the Movie class that extends the Work class.
     $this->targetMovieClass = $this->targetWorkClass->createSubClass('Movie', 'The Movie class');
     $this->targetMovieClass = new core_kernel_classes_Class($this->targetMovieClass->getUri());
     // Add properties to the Movie class.
     $this->targetProducerProperty = $this->targetMovieClass->createProperty('Producer', 'The producer of the movie.');
     $this->targetProducerProperty->setRange($literalClass);
     $this->targetProducerProperty->setMultiple(true);
     $this->targetActorsProperty = $this->targetMovieClass->createProperty('Actors', 'The actors playing in the movie.');
     $this->targetActorsProperty->setRange($literalClass);
     $this->targetActorsProperty->setMultiple(true);
     $this->targetRelatedMoviesProperty = $this->targetMovieClass->createProperty('Related Movies', 'Movies related to the movie.');
     $this->targetRelatedMoviesProperty->setRange($this->targetMovieClass);
     $this->targetRelatedMoviesProperty->setMultiple(true);
     //$this->generisUser = core_kernel_users_Service::singleton()->addUser('testCaseUser','testCasepass');
 }
Exemple #3
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);
 }