/**
  * initialize a test method
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     $activityExecutionClass = new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION);
     $this->activityExecution = $activityExecutionClass->createInstance('test');
     $this->service = wfEngine_models_classes_RecoveryService::singleton();
 }
 /**
  * tests initialization
  */
 public function setUp()
 {
     TaoTestRunner::initTest();
     $resultsService = taoResults_models_classes_ResultsService::singleton();
     $this->resultsService = $resultsService;
     $this->statsService = taoResults_models_classes_StatisticsService::singleton();
     $this->reportService = taoResults_models_classes_ReportService::singleton();
     //create an activity execution
     $activityExecutionClass = new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION);
     //create an activity definition
     $activityDefinitionClass = new core_kernel_classes_Class(CLASS_ACTIVITIES);
     $this->activityExecution = $activityExecutionClass->createInstance("MyActivityExecution");
     //links the activity execution to the activity definition
     $this->activityDefinition = $activityDefinitionClass->createInstance("MyActivityDefinition");
     $this->activityExecution->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_ACTIVITY), $this->activityDefinition->getUri());
     //links the call of service to the activity execution
     $interactiveServiceClass = new core_kernel_classes_Class(CLASS_CALLOFSERVICES);
     $this->interactiveService = $interactiveServiceClass->createInstance("MyInteractiveServiceCall");
     $this->activityDefinition->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES), $this->interactiveService->getUri());
     $this->interactiveService->setPropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION), "#interactiveServiceDefinition");
     $deliveryResult = new core_kernel_classes_Resource("#MyDeliveryResult");
     $variableIDentifier = "GRADE";
     $value = 0.4;
     //create a small delivery
     $this->subClass = $this->resultsService->createSubClass(new core_kernel_classes_Class(TAO_DELIVERY_RESULT), "UnitTestingGenClass");
     $this->delivery = $this->subClass->createInstance("UnitTestingGenDelivery");
     $this->delivery->setPropertyValue(new core_kernel_classes_Property(PROPERTY_RESULT_OF_DELIVERY), "#unitTestResultOfDelivery");
     $this->delivery->setPropertyValue(new core_kernel_classes_Property(PROPERTY_RESULT_OF_SUBJECT), "#unitTestResultOfSubject");
     $this->delivery->setPropertyValue(new core_kernel_classes_Property(PROPERTY_RESULT_OF_PROCESS), "#unitTestResultOfProcess");
     //stores a grade in this delivery
     $this->grade = $this->resultsService->storeGrade($this->delivery, $this->activityExecution, $variableIDentifier, $value);
     $this->response = $this->resultsService->storeResponse($this->delivery, $this->activityExecution, $variableIDentifier, $value);
 }
 /**
  * 
  * @param array $formalParam
  * @return boolean
  */
 private function addFormalParameter($formalParam)
 {
     if (is_array($formalParam)) {
         if ($formalParam['processVar']) {
             $label = self::unCamelize(str_replace('^', '', $formalParam['processVar']));
         } else {
             $label = self::unCamelize($formalParam['name']);
         }
         $formalParamResource = $this->formalParamClass->createInstance($label);
         if (!is_null($formalParamResource)) {
             $formalParamResource->setPropertyValue($this->formalParamNameProp, $formalParam['name']);
             if ($formalParam['processVar']) {
                 $processVar = $this->getProcessVar(str_replace('^', '', $formalParam['processVar']));
                 if (!is_null($processVar)) {
                     $formalParamResource->setPropertyValue($this->formalParamDefProcessVarProp, $processVar->getUri());
                 }
             }
             if ($formalParam['constant']) {
                 $formalParamResource->setPropertyValue($this->formalParamDefConstantProp, $formalParam['constant']);
             }
             return true;
         }
     }
     return false;
 }
Beispiel #4
0
 public function initRoles()
 {
     // Main parent role.
     $roleClass = new core_kernel_classes_Class(CLASS_ROLE);
     $isSystemProperty = new core_kernel_classes_Property(PROPERTY_ROLE_ISSYSTEM);
     $includesRoleProperty = new core_kernel_classes_Property(PROPERTY_ROLE_INCLUDESROLE);
     $trueInstance = new core_kernel_classes_Resource(GENERIS_TRUE);
     $falseInstance = new core_kernel_classes_Resource(GENERIS_FALSE);
     $prefix = LOCAL_NAMESPACE . '#';
     // Do not forget that more you go deep in the Roles hierarchy, more rights you have.
     $baseRole = $roleClass->createInstance('BASE Role', 'The base role of the hierarchy (minimal rights).', $prefix . 'baseRole');
     $baseRole->setPropertyValue($isSystemProperty, $falseInstance);
     $subRole1 = $roleClass->createInstance('SUB Role 1', 'Includes BASE role.', $prefix . 'subRole1');
     $subRole1->setPropertyValue($includesRoleProperty, $baseRole);
     $subRole1->setPropertyValue($isSystemProperty, $falseInstance);
     $subRole2 = $roleClass->createInstance('SUB Role 2', 'Includes BASE role.', $prefix . 'subRole2');
     $subRole2->setPropertyValue($includesRoleProperty, $baseRole);
     $subRole2->setPropertyValue($isSystemProperty, $falseInstance);
     $subRole3 = $roleClass->createInstance('SUB Role 3', 'Includes BASE role.', $prefix . 'subRole3');
     $subRole3->setPropertyValue($includesRoleProperty, $baseRole);
     $subRole3->setPropertyValue($isSystemProperty, $falseInstance);
     $subRole11 = $roleClass->createInstance('SUB Role 11', 'Includes SUB Role 1.', $prefix . 'subRole11');
     $subRole11->setPropertyValue($includesRoleProperty, $subRole1);
     $subRole11->setPropertyValue($isSystemProperty, $falseInstance);
     $subRole12 = $roleClass->createInstance('SUB Role 12', 'Includes SUB Role 1.', $prefix . 'subRole12');
     $subRole12->setPropertyValue($includesRoleProperty, $subRole1);
     $subRole12->setPropertyValue($isSystemProperty, $falseInstance);
     $subRole13 = $roleClass->createInstance('SUB Role 13', 'Includes SUB Role 1, SUB Role 11, SUB Role 12.', $prefix . 'subRole13');
     $subRole13->setPropertyValue($includesRoleProperty, $subRole1);
     $subRole13->setPropertyValue($includesRoleProperty, $subRole11);
     $subRole13->setPropertyValue($includesRoleProperty, $subRole12);
     $subRole13->setPropertyValue($isSystemProperty, $falseInstance);
 }
 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');
 }
 /**
  * tests initialization
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $processDefinition = $processDefinitionClass->createInstance('process of Checker UnitTest', 'created for the unit test of process cloner');
     if ($processDefinition instanceof core_kernel_classes_Resource) {
         $this->proc = $processDefinition;
     }
     $this->authoringService = wfAuthoring_models_classes_ProcessService::singleton();
 }
Beispiel #7
0
 public function testIsFile()
 {
     $clazz = new core_kernel_classes_Class(CLASS_GENERIS_FILE);
     $instance = $clazz->createInstance('toto.txt', 'toto');
     $fileNameProp = new core_kernel_classes_Property(PROPERTY_FILE_FILENAME);
     $instance->setPropertyValue($fileNameProp, 'file://toto.txt');
     $this->assertTrue(core_kernel_file_File::isFile($instance));
     $this->assertFalse(core_kernel_file_File::isFile($clazz));
     $instance->delete();
 }
Beispiel #8
0
 /**
  * tests initialization
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     $this->clearPassword = $this->testUserData[PROPERTY_USER_PASSWORD];
     $this->testUserData[PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($this->testUserData[PROPERTY_USER_PASSWORD]);
     $this->userService = tao_models_classes_UserService::singleton();
     $class = new core_kernel_classes_Class(CLASS_GENERIS_USER);
     $this->testUser = $class->createInstance();
     $this->assertNotNull($this->testUser);
     $this->userService->bindProperties($this->testUser, $this->testUserData);
 }
 /**
  * tests initialization
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $processDefinition = $processDefinitionClass->createInstance('processForUnitTest', 'created for the unit test of process definition service');
     if ($processDefinition instanceof core_kernel_classes_Resource) {
         $this->processDefinition = $processDefinition;
     } else {
         $this->fail('fail to create a process definition resource');
     }
     $this->authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $this->service = wfEngine_models_classes_ProcessDefinitionService::singleton();
 }
 /**
  * @return array
  */
 protected function getResource($relPath)
 {
     $dir = $this->getTempDirectory();
     $file = $dir->getFile($relPath);
     $file->put(file_get_contents(__DIR__ . $relPath));
     /** @var FileReferenceSerializer $serializer */
     $serializer = ServiceManager::getServiceManager()->get(FileReferenceSerializer::SERVICE_ID);
     $fileUri = $serializer->serialize($file);
     $class = new \core_kernel_classes_Class('fakeClass');
     $resource = $class->createInstance('fakeInstance');
     $prop = new \core_kernel_classes_Property('fakeProp');
     $prop->setRange(new \core_kernel_classes_Class(CLASS_GENERIS_FILE));
     $resource->editPropertyValues($prop, new \core_kernel_classes_Resource($fileUri));
     return array($file, $resource);
 }
 /**
  * tests initialization
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     $this->authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $this->variableService = wfEngine_models_classes_VariableService::singleton();
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $this->processDefinition = $processDefinitionClass->createInstance('ProcessForUnitTest', 'Unit test');
     //define activities and connectors
     $activity = $this->authoringService->createActivity($this->processDefinition, 'activity for interactive service unit test');
     if ($activity instanceof core_kernel_classes_Resource) {
         $this->activity = $activity;
     } else {
         $this->fail('fail to create a process definition resource');
     }
     $this->service = wfEngine_models_classes_ConnectorService::singleton();
 }
 public function testAdd()
 {
     $rootClass = new \core_kernel_classes_Class($this->classUri);
     $filePath = dirname(__DIR__) . '/sample/Italy.png';
     $instance = $rootClass->createInstance();
     $instance->setPropertyValue(new \core_kernel_classes_Property(MEDIA_LINK), 'myGreatLink');
     $returnedLink = $instance->getUri();
     $this->service->expects($this->once())->method('createMediaInstance')->with($filePath, $this->classUri, 'EN_en', 'Italy1.png')->willReturn($returnedLink);
     //mock the fileInfo method
     $fileInfo = array('name' => 'myName', 'mime' => 'mime/type', 'size' => 1024);
     $this->mediaManagerManagement->expects($this->once())->method('getFileInfo')->with($returnedLink)->willReturn($fileInfo);
     $success = $this->mediaManagerManagement->add($filePath, 'Italy1.png', $this->classUri);
     // has no error
     $this->assertInternalType('array', $success, 'Should be a file info array');
     $this->assertArrayNotHasKey('error', $success, 'upload doesn\'t succeed');
     $this->assertEquals($fileInfo, $success, 'Doesn\'t return the getFileInfo value');
     return $returnedLink;
 }
 public function testSetPropertiesValues()
 {
     $this->hardify();
     $instance = $this->targetMovieClass->createInstance("Hard Sub Movie (Unit Test)");
     $instance2 = $this->targetMovieClass->createInstance("Hard Sub Movie2 (Unit Test)");
     $instance->setPropertiesValues(array($this->targetRelatedMoviesProperty->getUri() => $instance2, $this->targetActorsProperty->getUri() => array('I\'m special"! !', 'So special"! !'), RDFS_LABEL => 'I\'m special"! !'));
     $actors = $instance->getPropertyValues($this->targetActorsProperty);
     $this->assertEquals(2, count($actors));
     $this->assertTrue(in_array('I\'m special"! !', $actors));
     $this->assertTrue(in_array('So special"! !', $actors));
     $relateds = $instance->getPropertyValues($this->targetRelatedMoviesProperty);
     $this->assertEquals(1, count($relateds));
     $related = current($relateds);
     $this->assertEquals($instance2->getUri(), $related);
     $labels = $instance->getPropertyValues(new core_kernel_classes_Property(RDFS_LABEL));
     $this->assertEquals(2, count($labels));
     $this->assertTrue(in_array('I\'m special"! !', $labels));
     $this->assertTrue(in_array("Hard Sub Movie (Unit Test)", $labels));
     $instance->delete();
     $instance2->delete();
 }
 /**
  * Will make the Global Manager include the Management Role of the extension
  * to install (if it exists).
  *
  * @access public
  * @author Jerome Bogaerts <*****@*****.**>
  * @return void
  * @since 2.4
  */
 public function installManagementRole()
 {
     // Try to get a Management Role described by the extension itself.
     // (this information comes actually from the Manifest of the extension)
     $roleUri = $this->extension->getManifest()->getManagementRoleUri();
     if (!empty($roleUri)) {
         $role = new core_kernel_classes_Resource($roleUri);
         $roleService = tao_models_classes_RoleService::singleton();
         if (!$role->exists()) {
             // Management role does not exist yet, so we create it
             $roleClass = new core_kernel_classes_Class(CLASS_MANAGEMENTROLE);
             $roleLabel = $this->extension->getId() . ' Manager';
             $role = $roleClass->createInstance($roleLabel, $roleLabel . ' Role', $role->getUri());
             $roleService->includeRole($role, new core_kernel_classes_Resource(INSTANCE_ROLE_BACKOFFICE));
         }
         // Take the Global Manager role and make it include
         // the Management role of the currently installed extension.
         if ($role->getUri() !== INSTANCE_ROLE_GLOBALMANAGER) {
             $globalManagerRole = new core_kernel_classes_Resource(INSTANCE_ROLE_GLOBALMANAGER);
             $roleService->includeRole($globalManagerRole, $role);
         }
         common_Logger::d("Management Role " . $role->getUri() . " created for extension '" . $this->extension->getId() . "'.");
     } else {
         // There is no Management role described by the Extension Manifest.
         common_Logger::i("No management role for extension '" . $this->extension->getId() . "'.");
     }
 }
 /**
  * Test the tokens into a parallel process
  */
 public function testVirtualParallelJoinProcess()
 {
     error_reporting(E_ALL);
     $t_start = microtime(true);
     //init services
     $activityService = wfEngine_models_classes_ActivityService::singleton();
     $processVariableService = wfEngine_models_classes_VariableService::singleton();
     $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $activityExecutionService->cache = (bool) self::SERVICE_CACHE;
     //process definition
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $processDefinition = $processDefinitionClass->createInstance('PJ processForUnitTest_' . date(DATE_ISO8601), 'created for the unit test of process execution');
     $this->assertNotNull($processDefinition);
     /*
     		                +---------------+
     		                |  activity 0   |
     		                +-------+-------+
     		                        |
     		                    +---v---+
     		                    |  c 0  |   split
     		                    +--+-+--+
     		                       | |
     		          3  +---------+ +---------+  unit_var_12345678
     		             |                     |
     		     +-------v--------+    +-------v------+
     		     |   activity 1   |    |  activity 2  |
     		     +-------+--------+    +--------+-----+
     		             |                      |
     		             +--------+    +--------+
     		                   +--v----v--+
     		                   |   c 2    |    join
     		                   +----+-----+
     		                        |
     		                +-------v--------+
     		                |  activity 3    |
     		                +----------------+
     */
     //activities definitions
     $activity0 = $authoringService->createActivity($processDefinition, 'activity0');
     $this->assertNotNull($activity0);
     $connector0 = null;
     $authoringService->setFirstActivity($processDefinition, $activity0);
     $connector0 = $authoringService->createConnector($activity0);
     $connectorParallele = new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_PARALLEL);
     $authoringService->setConnectorType($connector0, $connectorParallele);
     $this->assertNotNull($connector0);
     $parallelActivity1 = $authoringService->createActivity($processDefinition, 'activity1');
     $this->assertNotNull($parallelActivity1);
     $roleRestrictedUser = new core_kernel_classes_Resource(INSTANCE_ACL_ROLE_RESTRICTED_USER);
     $activityService->setAcl($parallelActivity1, $roleRestrictedUser, $this->testUserRole);
     //!!! it is mendatory to set the role restricted user ACL mode to make this parallel process test case work
     $connector1 = null;
     $connector1 = $authoringService->createConnector($parallelActivity1);
     $this->assertNotNull($connector1);
     $parallelActivity2 = $authoringService->createActivity($processDefinition, 'activity2');
     $this->assertNotNull($parallelActivity2);
     $activityService->setAcl($parallelActivity2, $roleRestrictedUser, $this->testUserRole);
     //!!! it is mendatory to set the role restricted user ACL mode to make this parallel process test case work
     $connector2 = null;
     $connector2 = $authoringService->createConnector($parallelActivity2);
     $this->assertNotNull($connector2);
     //define parallel activities, first branch with constant cardinality value, while the second listens to a process variable:
     $parallelCount1 = 3;
     $parallelCount2 = 5;
     $parallelCount2_processVar_key = 'unit_var_' . time();
     $parallelCount2_processVar = $processVariableService->createProcessVariable('Var for unit test', $parallelCount2_processVar_key);
     $prallelActivitiesArray = array($parallelActivity1->getUri() => $parallelCount1, $parallelActivity2->getUri() => $parallelCount2_processVar);
     $result = $authoringService->setParallelActivities($connector0, $prallelActivitiesArray);
     $this->assertTrue($result);
     //set several split variables:
     $splitVariable1_key = 'unit_split_var1_' . time();
     $splitVariable1 = $processVariableService->createProcessVariable('Split Var1 for unit test', $splitVariable1_key);
     $splitVariable2_key = 'unit_split_var2_' . time();
     $splitVariable2 = $processVariableService->createProcessVariable('Split Var2 for unit test', $splitVariable2_key);
     $splitVariablesArray = array($parallelActivity1->getUri() => array($splitVariable1), $parallelActivity2->getUri() => array($splitVariable1, $splitVariable2));
     $connectorService = wfAuthoring_models_classes_ConnectorService::singleton();
     $connectorService->setSplitVariables($connector0, $splitVariablesArray);
     $prallelActivitiesArray[$parallelActivity2->getUri()] = $parallelCount2;
     $joinActivity = $authoringService->createActivity($processDefinition, 'activity3');
     //join parallel Activity 1 and 2 to "joinActivity"
     $connector1 = wfAuthoring_models_classes_ConnectorService::singleton()->createJoin(array($parallelActivity1, $parallelActivity2), $joinActivity);
     /*
     $authoringService->createJoinActivity($connector1, $joinActivity, '', $parallelActivity1);
     $authoringService->createJoinActivity($connector2, $joinActivity, '', $parallelActivity2);
     */
     //run the process
     $processExecName = 'Test Parallel Process Execution';
     $processExecComment = 'created for processExecustionService test case by ' . __METHOD__;
     $processInstance = $this->service->createProcessExecution($processDefinition, $processExecName, $processExecComment);
     $this->assertTrue($this->service->checkStatus($processInstance, 'started'));
     $this->out(__METHOD__, true);
     $this->out("<strong>Forward transitions:</strong>", true);
     $previousActivityExecution = null;
     $numberActivities = 2 + $parallelCount1 + $parallelCount2;
     $createdUsers = array();
     $loginProperty = new core_kernel_classes_Property(PROPERTY_USER_LOGIN);
     for ($i = 1; $i <= $numberActivities; $i++) {
         $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
         $countActivities = count($activitieExecs);
         $activity = null;
         $activityExecution = null;
         if ($countActivities > 1) {
             //select one of the available activities in the parallel branch:
             foreach ($activitieExecs as $activityExecUri => $activityExec) {
                 if (!$activityExecutionService->isFinished($activityExec)) {
                     $activityDefinition = $activityExecutionService->getExecutionOf($activityExec);
                     $activityUri = $activityDefinition->getUri();
                     if (isset($prallelActivitiesArray[$activityUri])) {
                         if ($prallelActivitiesArray[$activityUri] > 0) {
                             $prallelActivitiesArray[$activityUri]--;
                             $activityExecution = $activityExec;
                             $activity = $activityDefinition;
                             break;
                         }
                     }
                 }
             }
         } else {
             if ($countActivities == 1) {
                 $activityExecution = reset($activitieExecs);
                 $activity = $activityExecutionService->getExecutionOf($activityExecution);
             } else {
                 $this->fail('no current activity definition found for the iteration ' . $i);
             }
         }
         $this->out("<strong> Iteration {$i} :</strong>", true);
         $this->out("<strong>" . (is_null($activity) ? 'null' : $activity->getLabel()) . "</strong> (among {$countActivities})");
         //issue : no activity found for the last iteration...
         //init execution
         $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
         $this->assertNotNull($activityExecution);
         if ($i == 1) {
             //set value of the parallel thread:
             $processVariableService->push($parallelCount2_processVar_key, $parallelCount2);
             //set some values to the split variables:
             $values1 = array();
             for ($j = 1; $j <= $parallelCount1; $j++) {
                 $values1[] = 'A' . $j;
             }
             $values2 = array();
             for ($j = 1; $j <= $parallelCount2; $j++) {
                 $values2[] = 'B' . $j;
             }
             $processVariableService->push($splitVariable1_key, serialize($values1));
             $processVariableService->push($splitVariable2_key, serialize($values2));
         } else {
             //check dispatched value:
             //				$value1 = $processVariableService->get($splitVariable1_key);
             //				$value2 = $processVariableService->get($splitVariable2_key);
             //				var_dump($value1, $value2);
         }
         $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
         $this->assertNotNull($activityExecStatus);
         $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_STARTED);
         //transition to next activity
         $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
         $this->out("performing transition ...");
         //transition to next activity
         $performed = $this->service->performTransition($processInstance, $activityExecution);
         if (!$performed) {
             $this->out('transition failed.');
         }
         $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
         $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
         //try undoing the transition:
         switch ($i) {
             case 1:
                 $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
                 $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
                 $this->assertEquals(count($activitieExecs), 1);
                 $activityBis = $activityExecutionService->getExecutionOf(reset($activitieExecs));
                 $this->assertTrue($activity->getUri() == $activityBis->getUri());
                 $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
                 break;
             case 1 + $parallelCount1:
                 $this->assertFalse($this->service->undoForwardTransition($processInstance, $activityExecution));
                 $history = $this->service->getExecutionHistory($processInstance);
                 $this->assertEquals(count($history), 2 * ($parallelCount1 + $parallelCount2) + 1);
                 //activity 1, 2(closed), 2, 3 and 4
                 $this->assertFalse($this->service->undoForwardTransition($processInstance, new core_kernel_classes_Resource(reset($history))));
                 $this->assertNotNull($previousActivityExecution);
                 $this->assertFalse($this->service->undoForwardTransition($processInstance, $previousActivityExecution));
                 break;
             case 1 + $parallelCount1 + $parallelCount2:
                 $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
                 $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
                 $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2);
                 $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
                 break;
         }
         $previousActivityExecution = $activityExecution;
         if ($this->service->isPaused($processInstance)) {
             //Login another user to execute parallel branch
             $this->userService->logout();
             $this->out("logout " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"', true);
             list($usec, $sec) = explode(" ", microtime());
             $login = '******' . $i . '-' . $usec;
             $pass = '******';
             $userData = array(PROPERTY_USER_LOGIN => $login, PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt($pass), PROPERTY_USER_DEFLG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_UILG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_ROLES => INSTANCE_ROLE_WORKFLOW, RDFS_LABEL => $login);
             if (!$this->userService->loginAvailable($login)) {
                 $this->fail('test login already taken');
             }
             $otherUser = $this->testUserClass->createInstanceWithProperties($userData);
             $createdUsers[$otherUser->getUri()] = $otherUser;
             if ($this->userService->loginUser($login, $pass)) {
                 $this->currentUser = $this->userService->getCurrentUser();
                 $this->out("new user logged in: " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"');
             } else {
                 $this->fail("unable to login user {$login}");
             }
         }
     }
     $this->assertTrue($this->service->isFinished($processInstance));
     $this->assertTrue($this->service->resume($processInstance));
     $this->out("<strong>Backward transitions:</strong>", true);
     //		var_dump($this->service->getAllActivityExecutions($processInstance));
     $j = 0;
     $iterationNumber = 2;
     while ($j < $iterationNumber) {
         $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
         $activityExecution = null;
         $activity = null;
         switch ($j) {
             case 0:
                 $this->assertEquals(count($activitieExecs), 1);
                 //check
                 $activityExecution = reset($activitieExecs);
                 $activity = $activityExecutionService->getExecutionOf($activityExecution);
                 break;
             case 1:
                 $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2);
                 //check
                 $activity = $parallelActivity2;
                 foreach ($this->service->getCurrentActivityExecutions($processInstance, $activity) as $activityExec) {
                     if ($activityExecutionService->getActivityExecutionUser($activityExec)->getUri() == $this->currentUser->getUri()) {
                         $activityExecution = $activityExec;
                     }
                 }
                 if (is_null($activityExecution)) {
                     $activity = $parallelActivity1;
                     foreach ($this->service->getCurrentActivityExecutions($processInstance, $activity) as $activityExec) {
                         if ($activityExecutionService->getActivityExecutionUser($activityExec)->getUri() == $this->currentUser->getUri()) {
                             $activityExecution = $activityExec;
                         }
                     }
                 }
                 $this->assertNotNull($activityExecution);
                 break;
         }
         $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
         //init execution
         $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
         $this->assertNotNull($activityExecution);
         $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
         $this->assertNotNull($activityExecStatus);
         $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
         $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
         $this->out("performing transition ...");
         //transition to next activity
         $transitionResult = $this->service->performBackwardTransition($processInstance, $activityExecution);
         if ($j == 0) {
             $this->assertTrue(count($transitionResult) > 0);
         } else {
             if ($j == $iterationNumber - 1) {
                 //var_dump($transitionResult);
                 $this->assertFalse($transitionResult);
             }
         }
         $processStatus = $this->service->getStatus($processInstance);
         $this->assertNotNull($processStatus);
         $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
         $this->out("process status: " . $processStatus->getLabel());
         $this->assertEquals($processStatus->getUri(), INSTANCE_PROCESSSTATUS_PAUSED);
         $j++;
     }
     $this->out("<strong>Forward transitions again:</strong>", true);
     $currentActivityExecutions = $this->service->getCurrentActivityExecutions($processInstance);
     $currentActivityExecutionsCount = count($currentActivityExecutions);
     $this->assertEquals($currentActivityExecutionsCount, $parallelCount1 + $parallelCount2);
     for ($i = 0; $i < $currentActivityExecutionsCount; $i++) {
         $currentActivityExecution = array_pop($currentActivityExecutions);
         $user = $activityExecutionService->getActivityExecutionUser($currentActivityExecution);
         $activityDefinition = $activityExecutionService->getExecutionOf($currentActivityExecution);
         $this->assertNotNull($user);
         $this->assertNotNull($activityDefinition);
         if (!is_null($user) && !is_null($activityDefinition)) {
             $this->userService->logout();
             $this->out("logout " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"', true);
             $login = (string) $user->getUniquePropertyValue($loginProperty);
             $pass = '******';
             if ($this->userService->loginUser($login, $pass)) {
                 $this->currentUser = $this->userService->getCurrentUser();
                 $this->out("new user logged in: " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"');
             } else {
                 $this->fail("unable to login user {$login}<br>");
             }
             $iterationNo = $i + 1;
             $this->out("<strong>Iteration {$iterationNo}: " . $activityDefinition->getLabel() . "</strong>", true);
             //execute activity:
             $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $currentActivityExecution, $this->currentUser);
             $this->assertNotNull($activityExecution);
             $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
             $this->assertNotNull($activityExecStatus);
             $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
             //transition to next activity
             $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
             $this->out("performing transition ...");
             //transition to next activity
             $this->service->performTransition($processInstance, $activityExecution);
             $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
             $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
             //try undoing the transition:
             if ($i < $currentActivityExecutionsCount - 1) {
                 $this->assertFalse($this->service->undoForwardTransition($processInstance, $activityExecution));
             }
         }
     }
     //try undoing the transition:
     $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
     $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
     $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2);
     $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
     $this->assertEquals(count($transitionResult), 1);
     $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
     $this->assertEquals(count($activitieExecs), 1);
     $activityExecution = reset($activitieExecs);
     $activity = $activityExecutionService->getExecutionOf($activityExecution);
     $this->assertEquals($activity->getUri(), $joinActivity->getUri());
     $this->out("<strong>Executing last activity: " . $activity->getLabel() . "</strong>", true);
     //init execution
     $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
     $this->assertNotNull($activityExecution);
     $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
     $this->assertNotNull($activityExecStatus);
     $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_STARTED);
     //transition to next activity
     $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
     $this->out("performing transition ...");
     //transition to next activity
     $this->service->performTransition($processInstance, $activityExecution);
     $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
     $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
     $this->assertTrue($this->service->isFinished($processInstance));
     $t_end = microtime(true);
     $duration = $t_end - $t_start;
     $this->out('Elapsed time: ' . $duration . 's', true);
     $this->out('deleting created resources:', true);
     //delete process exec:
     $this->assertTrue($this->service->deleteProcessExecution($processInstance));
     //delete processdef:
     $this->assertTrue($authoringService->deleteProcess($processDefinition));
     $parallelCount2_processVar->delete();
     //delete created users:
     foreach ($createdUsers as $createdUser) {
         $this->out('deleting ' . $createdUser->getLabel() . ' "' . $createdUser->getUri() . '"');
         $this->assertTrue($this->userService->removeUser($createdUser));
     }
     if (!is_null($this->currentUser)) {
         $this->userService->logout();
         $this->userService->removeUser($this->currentUser);
     }
 }
Beispiel #16
0
 /**
  * Test user insertion with special chars
  */
 public function testAddUtf8User()
 {
     $this->assertTrue($this->userService->loginAvailable($this->testUserUtf8Data[PROPERTY_USER_LOGIN]));
     $tmclass = new core_kernel_classes_Class(CLASS_TAO_USER);
     $this->testUserUtf8 = $tmclass->createInstance();
     $this->assertNotNull($this->testUserUtf8);
     $this->assertTrue($this->testUserUtf8->exists());
     $result = $this->userService->bindProperties($this->testUserUtf8, $this->testUserUtf8Data);
     $this->assertNotNull($result);
     $this->assertNotEquals($result, false);
     $this->assertFalse($this->userService->loginAvailable($this->testUserUtf8Data[PROPERTY_USER_LOGIN]));
     //check inserted data
     $this->testUserUtf8 = $this->getUserByLogin($this->testUserUtf8Data[PROPERTY_USER_LOGIN]);
     $this->assertInstanceOf('core_kernel_classes_Resource', $this->testUserUtf8);
     foreach ($this->testUserUtf8Data as $prop => $value) {
         try {
             $p = new core_kernel_classes_Property($prop);
             $v = $this->testUserUtf8->getUniquePropertyValue($p);
             $v = $v instanceof core_kernel_classes_Literal ? $v->literal : $v->getUri();
             $this->assertEquals($value, $v);
         } catch (common_Exception $ce) {
             $this->fail($ce);
         }
     }
 }
 protected function createLinearSuperProcess($processes)
 {
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $processDefinition = $processDefinitionClass->createInstance('process for ' . __CLASS__);
     $this->assertIsA($processDefinition, 'core_kernel_classes_Resource');
     $activityService = wfAuthoring_models_classes_ActivityService::singleton();
     $connectorService = wfAuthoring_models_classes_ConnectorService::singleton();
     $processRunnerService = new core_kernel_classes_Resource(INSTANCE_SERVICE_PROCESSRUNNER);
     $processRunnerParam = new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_PROCESSDEFINITION);
     $last = null;
     foreach ($processes as $subProcess) {
         $serviceCall = new tao_models_classes_service_ServiceCall($processRunnerService);
         $serviceCall->addInParameter(new tao_models_classes_service_ConstantParameter($processRunnerParam, $subProcess));
         $current = $activityService->createActivity($processDefinition);
         $current->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES), $serviceCall->toOntology());
         if (is_null($last)) {
             $current->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISINITIAL), GENERIS_TRUE);
         } else {
             $connectorService->createSequential($last, $current);
         }
         $last = $current;
     }
     return $processDefinition;
 }
 /**
  * Test the referencer on resources
  * @see oat\generisHard\models\hardapi\ResourceReferencer
  */
 public function testResourceReferencer()
 {
     $referencer = ResourceReferencer::singleton();
     $this->assertIsA($referencer, 'oat\\generisHard\\models\\hardapi\\ResourceReferencer');
     $testTakerClass = new core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAOSubject.rdf#Subject');
     $testTaker = $testTakerClass->createInstance('test taker 1');
     $table = '_' . Utils::getShortName($testTakerClass);
     $referencer->referenceResource($testTaker, $table);
     $this->assertTrue($referencer->isResourceReferenced($testTaker));
     $this->assertEquals($referencer->resourceLocation($testTaker), $table);
     $referencer->unReferenceResource($testTaker);
     $this->assertFalse($referencer->isResourceReferenced($testTaker));
     $testTaker->delete();
 }
 /**
  * (non-PHPdoc)
  * @see taoTests_models_classes_TestModel::onTestModelSet()
  */
 public function prepareContent(core_kernel_classes_Resource $test, $items = array())
 {
     $class = new core_kernel_classes_Class(CLASS_LTI_TESTCONTENT);
     $content = $class->createInstance();
     $test->setPropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP), $content);
 }
 public function testVirtualProcess()
 {
     $processAuthoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $processDefinition = $processDefinitionClass->createInstance('ProcessForUnitTest', 'Unit test');
     $this->assertIsA($processDefinition, 'core_kernel_classes_Resource');
     $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     //define activities and connectors
     $activity1 = $authoringService->createActivity($processDefinition, 'activity1');
     $this->assertNotNull($activity1);
     $authoringService->setFirstActivity($processDefinition, $activity1);
     //check first activity
     $this->assertTrue($this->service->isActivity($activity1));
     $this->assertTrue($this->service->isInitial($activity1));
     $connector1 = $authoringService->createConnector($activity1);
     $authoringService->setConnectorType($connector1, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
     $activity2 = $authoringService->createSequenceActivity($connector1, null, 'activity2');
     $this->assertNotNull($activity2);
     $this->assertTrue($this->service->isActivity($activity2));
     $this->assertFalse($this->service->isFinal($activity1));
     $this->assertFalse($this->service->isInitial($activity2));
     $this->assertTrue($this->service->isFinal($activity2));
     $activity1->delete(true);
     $connector1->delete(true);
     $activity2->delete(true);
     $processDefinition->delete(true);
 }
 public function testIsFileReferenceResourceRange()
 {
     $classFile = new \core_kernel_classes_Class("http://www.tao.lu/Ontologies/generis.rdf#File");
     $file = $classFile->createInstance("test");
     $rdfsTriple = new \core_kernel_classes_Triple();
     $rdfsTriple->predicate = "http://www.w3.org/1999/02/22-rdf-syntax-ns#value";
     $rdfsTriple->object = $file->getUri();
     $this->assertTrue(CloneHelper::isFileReference($rdfsTriple));
     $file->delete();
 }
 public function testGetFileInfo()
 {
     $fileTmp = dirname(__DIR__) . '/sample/Brazil.png';
     $root = new \core_kernel_classes_Class($this->rootClass);
     $instance = $root->createInstance('Brazil.png');
     $instance->setPropertyValue(new \core_kernel_classes_Property(MEDIA_LINK), 'myGreatLink');
     $instance->setPropertyValue(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), 'image/png');
     $uri = $instance->getUri();
     $this->fileManagerMock->expects($this->once())->method('retrieveFile')->with('myGreatLink')->willReturn($fileTmp);
     $fileInfo = $this->mediaManagerManagement->getFileInfo($uri);
     $instance->delete(true);
     $this->assertInternalType('array', $fileInfo, 'The result should be an array');
     $this->assertArrayHasKey('name', $fileInfo, 'The result should contain "name"');
     $this->assertArrayHasKey('mime', $fileInfo, 'The result should contain "mime"');
     $this->assertArrayHasKey('size', $fileInfo, 'The result should contain "size"');
     $this->assertArrayHasKey('uri', $fileInfo, 'The result should contain "size"');
     $this->assertEquals($instance->getLabel(), $fileInfo['name'], 'The file name is not correct');
     $this->assertEquals('image/png', $fileInfo['mime'], 'The mime type is not correct');
     $this->assertEquals('taomedia://mediamanager/' . \tao_helpers_Uri::encode($uri), $fileInfo['uri'], 'The uri is not correct');
 }
 public function testCreateSequenceActivity()
 {
     $processDefinition = $this->proc;
     $authoringService = $this->authoringService;
     $processVariableService = wfEngine_models_classes_VariableService::singleton();
     //set the required process variables subjectUri and wsdlContract
     $var_map = $processVariableService->getProcessVariable("map", true);
     $var_param1 = $processVariableService->getProcessVariable("param1", true);
     $var_param2 = $processVariableService->getProcessVariable("param2", true);
     //create formal param associated to the 3 required proc var:
     $paramMap = $authoringService->getFormalParameter('map');
     if (is_null($paramMap)) {
         $paramMap = $authoringService->createFormalParameter('map', 'processvariable', $var_map->getUri(), 'label of the formal param "map"');
     }
     $param1 = $authoringService->getFormalParameter('param1');
     if (is_null($param1)) {
         $param1 = $authoringService->createFormalParameter('param1', 'processvariable', $var_param1->getUri(), 'label of the formal param "param1"');
     }
     $param2 = $authoringService->getFormalParameter('param2');
     if (is_null($param2)) {
         $param2 = $authoringService->createFormalParameter('param2', 'processvariable', $var_param2->getUri(), 'label of the formal param "param2"');
     }
     //creating the activity definition and connecting them sequentially:
     $activityDefinitions = array();
     //create an activity and set it as the first:
     $activity1 = $authoringService->createActivity($processDefinition, 'activity1');
     $this->assertNotNull($activity1);
     $authoringService->setFirstActivity($processDefinition, $activity1);
     $activityDefinitions[] = $activity1;
     //create a connector to the first activity and set the type as "sequential"
     $connector1 = null;
     $connector1 = $authoringService->createConnector($activity1);
     $authoringService->setConnectorType($connector1, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
     $this->assertNotNull($connector1);
     //same for the 2nd activity:
     $activity2 = $authoringService->createSequenceActivity($connector1, null, 'activity2');
     $connector2 = $authoringService->createConnector($activity2);
     $authoringService->setConnectorType($connector2, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
     $activityDefinitions[] = $activity2;
     //then the last:
     $activity3 = $authoringService->createSequenceActivity($connector2, null, 'activity3');
     $activityDefinitions[] = $activity3;
     //the last activity does not have a connector
     //set the service(i.e. unit) to each activity:
     $services = array();
     $services[1] = array('url' => 'url of unit1', 'label' => 'label of unit1');
     $services[2] = array('url' => 'url of unit2', 'label' => 'label of unit2');
     $services[3] = array('url' => 'url of unit3', 'label' => 'label of unit3');
     $i = 1;
     $serviceDefinitions = array();
     foreach ($activityDefinitions as $activity) {
         $url_unit = $services[$i]['url'];
         $label_unit = $services[$i]['label'];
         //try to find if a service definiton has already been created for the unit:
         $serviceDefinition = null;
         $serviceDefinitionClass = new core_kernel_classes_Class(CLASS_SUPPORTSERVICES);
         $foundServiceDefinitions = $serviceDefinitionClass->searchInstances(array(PROPERTY_SUPPORTSERVICES_URL => $url_unit), array('like' => false));
         if (!empty($foundServiceDefinitions)) {
             $serviceDefinition = array_shift($foundServiceDefinitions);
         }
         if (is_null($serviceDefinition)) {
             //if no corresponding service def found, create a service definition:
             $serviceDefinition = $serviceDefinitionClass->createInstance($label_unit, 'created by process map testcase');
             //set service definition (the unit) and parameters:
             $serviceDefinition->setPropertyValue(new core_kernel_classes_Property(PROPERTY_SUPPORTSERVICES_URL), $url_unit);
             $serviceDefinition->setPropertyValue(new core_kernel_classes_Property(PROPERTY_SERVICESDEFINITION_FORMALPARAMIN), $paramMap->getUri());
             $serviceDefinition->setPropertyValue(new core_kernel_classes_Property(PROPERTY_SERVICESDEFINITION_FORMALPARAMIN), $param1->getUri());
             $serviceDefinition->setPropertyValue(new core_kernel_classes_Property(PROPERTY_SERVICESDEFINITION_FORMALPARAMIN), $param2->getUri());
             $serviceDefinitions[$serviceDefinition->getUri()] = $serviceDefinition;
         }
         $this->assertNotNull($serviceDefinition);
         //create a call of service and associate the service definition to it:
         $service = $authoringService->createInteractiveService($activity);
         $service->setPropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION), $serviceDefinition->getUri());
         $authoringService->setActualParameter($service, $paramMap, $var_map->getUri(), PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE);
         $authoringService->setActualParameter($service, $param1, $var_param1->getUri(), PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE);
         $authoringService->setActualParameter($service, $param2, $var_param2->getUri(), PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE);
         $this->assertNotNull($service);
         $i++;
     }
     //end of process definition creation
     //get the ordered list of activity of the sequential process:
     $activityList = array();
     //get list of all activities:
     $activities = $authoringService->getActivitiesByProcess($processDefinition);
     $totalNumber = count($activities);
     //find the first one: property isinitial == true (must be only one, if not error) and set as the currentActivity:
     $currentActivity = null;
     foreach ($activities as $activity) {
         $isIntial = $activity->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISINITIAL));
         if (!is_null($isIntial) && $isIntial instanceof core_kernel_classes_Resource) {
             if ($isIntial->getUri() == GENERIS_TRUE) {
                 $currentActivity = $activity;
                 break;
             }
         }
     }
     $this->assertNotNull($currentActivity);
     //start the loop:
     for ($i = 0; $i < $totalNumber; $i++) {
         //set the test in the table:
         $activityList[$i] = $currentActivity;
         //get its connector (check the type is "sequential) if ok, get the next activity
         $connectors = $currentActivity->getPropertyValues(new core_kernel_classes_Property(PROPERTY_STEP_NEXT));
         $nextActivity = null;
         foreach ($connectors as $connectorUri) {
             $connector = new core_kernel_classes_Resource($connectorUri);
             $connectorType = $connector->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TYPE));
             if ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_SEQUENCE) {
                 $nextActivity = $connector->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_STEP_NEXT));
                 break;
             }
         }
         if (!is_null($nextActivity)) {
             $currentActivity = $nextActivity;
         } else {
             if ($i == $totalNumber - 1) {
                 //it is normal, since it is the last activity and test
             } else {
                 throw new Exception('the next activity of the connector is not found');
             }
         }
     }
     $this->assertEquals(count($activityList), 3);
     //delete all created resources:
     $var_map->delete();
     $var_param1->delete();
     $var_param2->delete();
     $paramMap->delete();
     $param1->delete();
     $param2->delete();
     foreach ($serviceDefinitions as $serviceDefinition) {
         $serviceDefinition->delete();
     }
 }
 /**
  * Short description of method setActualParameter
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource callOfService
  * @param  Resource formalParam
  * @param  string value
  * @param  string parameterInOrOut
  * @param  string actualParameterType
  * @return boolean
  */
 public function setActualParameter(core_kernel_classes_Resource $callOfService, core_kernel_classes_Resource $formalParam, $value, $parameterInOrOut = PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, $actualParameterType = PROPERTY_ACTUALPARAMETER_CONSTANTVALUE)
 {
     $returnValue = (bool) false;
     //must exist:
     if ($formalParam->hasType(new core_kernel_classes_Class(CLASS_FORMALPARAMETER))) {
         if (in_array($parameterInOrOut, array(PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_CALLOFSERVICES_ACTUALPARAMETEROUT)) && in_array($actualParameterType, array(PROPERTY_ACTUALPARAMETER_CONSTANTVALUE, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE))) {
             //create new resource for the property value of the current call of service PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN or PROPERTY_CALLOFSERVICES_ACTUALPARAMETEROUT
             $actualParameterClass = new core_kernel_classes_Class(CLASS_ACTUALPARAMETER);
             $newActualParameter = $actualParameterClass->createInstance($formalParam->getLabel(), "actual parameter created by Process Authoring Service");
             $newActualParameter->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTUALPARAMETER_FORMALPARAMETER), $formalParam->getUri());
             $newActualParameter->setPropertyValue(new core_kernel_classes_Property($actualParameterType), $value);
             $returnValue = $callOfService->setPropertyValue(new core_kernel_classes_Property($parameterInOrOut), $newActualParameter->getUri());
         }
     } else {
         throw new Exception('the formal parameter ' . $formalParam->getUri() . ' does not exist');
     }
     return (bool) $returnValue;
 }
 /**
  * Short description of method createTransitionRule
  *
  * @access private
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource connector
  * @param  Expression expression
  * @return core_kernel_classes_Resource
  */
 private function createTransitionRule(core_kernel_classes_Resource $connector, core_kernel_rules_Expression $expression)
 {
     $returnValue = null;
     $transitionRule = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE));
     if (empty($transitionRule) || $transitionRule == null) {
         //create an instance of transition rule:
         $transitionRuleClass = new core_kernel_classes_Class(CLASS_TRANSITIONRULES);
         $transitionRule = $transitionRuleClass->createInstance();
         //Associate the newly created transition rule to the connector:
         $connector->editPropertyValues(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE), $transitionRule->getUri());
     }
     if (empty($expression)) {
         common_Logger::e('condition is not an instance of ressource : ' . $expression);
     } else {
         //delete old condition:
         $oldCondition = $transitionRule->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_RULE_IF));
         if (!is_null($oldCondition)) {
             $this->deleteCondition($oldCondition);
         }
         $transitionRule->editPropertyValues(new core_kernel_classes_Property(PROPERTY_RULE_IF), $expression);
     }
     $returnValue = $transitionRule;
     return $returnValue;
 }
 /**
  * @dataProvider sharedStimulusImportProvider
  */
 public function testEdit($filename, $expectedReport, $called)
 {
     if (file_exists($filename)) {
         $tmpDir = \tao_helpers_File::createTempDir();
         copy($filename, $tmpDir . basename($filename));
         $filename = $tmpDir . basename($filename);
     }
     $clazz = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAOMedia.rdf#Media');
     $instance = $clazz->createInstance('my Label');
     $file['uploaded_file'] = $filename;
     $file['name'] = basename($filename);
     $form = new FileImportForm($instance->getUri());
     $form = $form->getForm();
     $form->setValues(array('source' => $file, 'lang' => 'EN_en'));
     if ($called) {
         $this->service->expects($this->once())->method('editMediaInstance')->willReturn(true);
     }
     $report = $this->packageImporter->edit($instance, $form);
     /** @var \common_report_Report $expectedReport*/
     $expectedReport->setMessage(preg_replace('/%s/', 'edited', $expectedReport->getMessage()));
     $this->assertEquals($expectedReport->getMessage(), $report->getMessage(), __('Report message is wrong'));
     $this->assertEquals($expectedReport->getType(), $report->getType(), __('Report should be success'));
     $instance->delete(true);
 }
 public function testGetCallUrl()
 {
     //create unique process variables for this unit test only:
     $variableService = wfEngine_models_classes_VariableService::singleton();
     $myProcessVarCode1 = 'myProcessVarCode1' . time();
     $myProcessVarCode2 = 'myProcessVarCode2' . time();
     $myProcessVar1 = $variableService->getProcessVariable($myProcessVarCode1, true);
     $myProcessVar2 = $variableService->getProcessVariable($myProcessVarCode2, true);
     $parameterNames = array('param1' . time(), 'param2' . time(), 'param3' . time(), 'param4' . time());
     $inputParameters = array($parameterNames[0] => $myProcessVar1, $parameterNames[1] => '^' . $myProcessVarCode2, $parameterNames[2] => 'myConstantValue', $parameterNames[3] => null);
     $serviceUrl = 'http://www.myWebSite.com/myServiceScript.php';
     $serviceDefinition1 = $this->authoringService->createServiceDefinition('myServiceDefinition', $serviceUrl, $inputParameters);
     $this->assertNotNull($serviceDefinition1);
     $service1 = $this->authoringService->createInteractiveService($this->activity);
     $this->assertTrue($this->service->isInteractiveService($service1));
     $this->assertTrue($this->authoringService->setCallOfServiceDefinition($service1, $serviceDefinition1));
     //check call url
     $callUrl = $this->service->getCallUrl($service1);
     $this->assertEquals($callUrl, 'http://www.myWebSite.com/myServiceScript.php?');
     //assign actual params:
     for ($i = 1; $i <= 4; $i++) {
         $formalParam = $this->authoringService->getFormalParameter($parameterNames[$i - 1]);
         $this->assertNotNull($formalParam);
         if (!is_null($formalParam) && $formalParam instanceof core_kernel_classes_Resource) {
             $defaultProcessVar = $formalParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_DEFAULTPROCESSVARIABLE));
             if (!is_null($defaultProcessVar)) {
                 $this->assertTrue($this->authoringService->setActualParameter($service1, $formalParam, $defaultProcessVar->getUri(), PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE));
             } else {
                 $this->assertTrue($this->authoringService->setActualParameter($service1, $formalParam, 'value' . $i));
             }
         }
     }
     //a no-orthodox way to create a valid activity execution :
     $userService = wfEngine_models_classes_UserService::singleton();
     $currentUser = new core_kernel_classes_Resource(LOCAL_NAMESPACE . '#unitTestUser');
     $this->assertNotNull($currentUser);
     $classActivityExecution = new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION);
     $activityExec1 = $classActivityExecution->createInstance('activity exec for interactive service test case');
     $activityExec1->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_CURRENT_USER), $currentUser->getUri());
     $procVarValue1 = 'procVarValue1';
     $procVarValue2 = 'procVarValue2';
     $activityExec1->setPropertyValue(new core_kernel_classes_Property($myProcessVar1->getUri()), $procVarValue1);
     $activityExec1->setPropertyValue(new core_kernel_classes_Property($myProcessVar2->getUri()), $procVarValue2);
     //check call url again
     $callUrl = $this->service->getCallUrl($service1);
     $this->assertEquals(strlen($callUrl), strlen('http://www.myWebSite.com/myServiceScript.php?' . $parameterNames[0] . '=&' . $parameterNames[1] . '=&' . $parameterNames[2] . '=&' . $parameterNames[3] . '=&'));
     //and again:
     $callUrl = $this->service->getCallUrl($service1, $activityExec1);
     $this->assertEquals(strlen($callUrl), strlen('http://www.myWebSite.com/myServiceScript.php?' . $parameterNames[0] . '=procVarValue1&' . $parameterNames[1] . '=procVarValue2&' . $parameterNames[2] . '=value3&' . $parameterNames[3] . '=value4&'));
     $this->assertTrue(strpos($callUrl, $procVarValue1));
     $this->assertTrue(strpos($callUrl, $procVarValue2));
     $this->assertTrue(strpos($callUrl, $parameterNames[2] . '=value3'));
     $this->assertTrue(strpos($callUrl, $parameterNames[3] . '=value4'));
     //delete all created resources:
     $myProcessVar1->delete();
     $myProcessVar2->delete();
     $serviceDefinition1->delete();
     $activityExec1->delete();
     $service1->delete();
     for ($i = 0; $i < 4; $i++) {
         $formalParam = $this->authoringService->getFormalParameter($parameterNames[$i]);
         $this->assertNotNull($formalParam);
         if (!is_null($formalParam) && $formalParam instanceof core_kernel_classes_Resource) {
             $this->assertTrue($formalParam->delete());
         }
     }
 }
 protected function createProcess($label, $comment = '')
 {
     $returnValue = null;
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $returnValue = $processDefinitionClass->createInstance($label, empty($comment) ? 'created by the script CreateProcess.php on ' . date(DATE_ISO8601) : $comment);
     if (!is_null($returnValue) && $returnValue instanceof core_kernel_classes_Resource) {
         $returnValue->setPropertyValue($this->propertyIsSample, GENERIS_TRUE);
         self::$processes[$returnValue->getUri()] = $returnValue;
     } else {
         throw new Exception('cannot create process ' . $label);
     }
     return $returnValue;
 }
 /**
  * Test the notifications in a sequencial process
  */
 public function testNotificationsInProcess()
 {
     try {
         $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
         $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
         $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
         $roleService = wfEngine_models_classes_RoleService::singleton();
         //create a new process def
         $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
         $processDefinition = $processDefinitionClass->createInstance('ProcessForUnitTest', 'Unit test');
         $this->assertIsA($processDefinition, 'core_kernel_classes_Resource');
         $aclModeRole = new core_kernel_classes_Resource(INSTANCE_ACL_ROLE);
         $aclModeUser = new core_kernel_classes_Resource(INSTANCE_ACL_USER);
         $wfRole = new core_kernel_classes_Resource(INSTANCE_ROLE_WORKFLOW);
         $role1 = $roleService->addRole('Role 1', $wfRole);
         $role2 = $roleService->addRole('Role 2', $wfRole);
         $roleService->setRoleToUsers($role2, array($this->currentUser));
         //define activities and connectors
         $activity1 = $authoringService->createActivity($processDefinition, 'activity1');
         $this->assertNotNull($activity1);
         $authoringService->setFirstActivity($processDefinition, $activity1);
         //activity is allowed to the created role
         $activityExecutionService->setAcl($activity1, $aclModeRole, $role2);
         $connector1 = null;
         $connector1 = $authoringService->createConnector($activity1);
         $authoringService->setConnectorType($connector1, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector1);
         $this->service->bindProperties($connector1, array(PROPERTY_CONNECTORS_NOTIFY => INSTANCE_NOTIFY_USER, PROPERTY_CONNECTORS_USER_NOTIFIED => $this->currentUser->getUri(), PROPERTY_CONNECTORS_NOTIFICATION_MESSAGE => 'Connector 1 notification to user ' . $this->currentUser->getLabel()));
         $activity2 = $authoringService->createSequenceActivity($connector1, null, 'activity2');
         $this->assertNotNull($activity2);
         //2nd activity is allowed to create role
         $activityExecutionService->setAcl($activity2, $aclModeRole, $role2);
         $connector2 = null;
         $connector2 = $authoringService->createConnector($activity2);
         $authoringService->setConnectorType($connector2, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector2);
         $this->service->bindProperties($connector2, array(PROPERTY_CONNECTORS_NOTIFY => INSTANCE_NOTIFY_PREVIOUS, PROPERTY_CONNECTORS_NOTIFICATION_MESSAGE => 'Connector 2 notification to previous activity user ' . $this->currentUser->getLabel()));
         $activity3 = $authoringService->createSequenceActivity($connector2, null, 'activity3');
         $this->assertNotNull($activity3);
         $connector3 = null;
         $connector3 = $authoringService->createConnector($activity3);
         $authoringService->setConnectorType($connector3, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector3);
         $this->service->bindProperties($connector3, array(PROPERTY_CONNECTORS_NOTIFY => INSTANCE_NOTIFY_NEXT, PROPERTY_CONNECTORS_NOTIFICATION_MESSAGE => 'Connector 3 notification to next activity user ' . $this->currentUser->getLabel()));
         $activity4 = $authoringService->createSequenceActivity($connector3, null, 'activity4');
         $this->assertNotNull($activity4);
         //allowed to the currentUser only
         $activityExecutionService->setAcl($activity4, $aclModeUser, $this->currentUser);
         $connector4 = null;
         $connector4 = $authoringService->createConnector($activity4);
         $authoringService->setConnectorType($connector4, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector4);
         $this->service->bindProperties($connector4, array(PROPERTY_CONNECTORS_NOTIFY => INSTANCE_NOTIFY_ROLE, PROPERTY_CONNECTORS_ROLE_NOTIFIED => $role2->getUri(), PROPERTY_CONNECTORS_NOTIFICATION_MESSAGE => 'Connector 4 notification to role user ' . $role2->getLabel()));
         $activity5 = $authoringService->createSequenceActivity($connector4, null, 'activity5');
         $this->assertNotNull($activity5);
         //run the process
         $processExecName = 'Test Process Execution';
         $processExecComment = 'created for Notification service test case by ' . __METHOD__;
         $proc = $processExecutionService->createProcessExecution($processDefinition, $processExecName, $processExecComment);
         $i = 1;
         while ($i <= 5) {
             $activityExecs = $processExecutionService->getAvailableCurrentActivityExecutions($proc, $this->currentUser);
             $this->assertEquals(count($activityExecs), 1);
             $activityExec = reset($activityExecs);
             $activity = $activityExecutionService->getExecutionOf($activityExec);
             $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
             $this->assertTrue($activity->getLabel() == 'activity' . $i);
             //init execution
             $activityExecution = $processExecutionService->initCurrentActivityExecution($proc, $activityExec, $this->currentUser);
             $this->assertIsA($activityExecution, "core_kernel_classes_Resource");
             //transition to nextactivity
             $transitionResult = $processExecutionService->performTransition($proc, $activityExecution);
             $this->assertFalse($processExecutionService->isPaused($proc));
             $i++;
         }
         $this->assertTrue($processExecutionService->isFinished($proc));
         //check the created notifications
         $notifications = array();
         $notificationProcessExecProp = new core_kernel_classes_Property(PROPERTY_NOTIFICATION_PROCESS_EXECUTION);
         $notificationToProp = new core_kernel_classes_Property(PROPERTY_NOTIFICATION_TO);
         $notificationsToSend = $this->service->getNotificationsToSend();
         $this->assertTrue(count($notificationsToSend) > 0);
         foreach ($this->service->getNotificationsToSend() as $notification) {
             $notificationProcess = $notification->getOnePropertyValue($notificationProcessExecProp);
             if (!is_null($notificationProcess)) {
                 if ($notificationProcess->getUri() == $proc->getUri()) {
                     $notifiedUser = $notification->getOnePropertyValue($notificationToProp);
                     $this->assertNotNull($notifiedUser);
                     $this->assertEquals($notifiedUser->getUri(), $this->currentUser->getUri());
                     $notifications[] = $notification;
                 }
             }
         }
         $notificationCount = count($notifications);
         $this->assertEquals($notificationCount, 4);
         //			$this->out("$notificationCount notifications to be sent");
         //			$this->assertTrue($this->service->sendNotifications(new tao_helpers_transfert_MailAdapter()));
         //			$this->out("All notifications sent");
         //delete notifications:
         foreach ($notifications as $notification) {
             $this->assertTrue($notification->delete());
         }
         $this->assertTrue($role2->delete());
         //delete process exec:
         $this->assertTrue($processExecutionService->deleteProcessExecution($proc));
         //delete processdef:
         $this->assertTrue($authoringService->deleteProcess($processDefinition));
         if (!is_null($this->currentUser)) {
             $this->userService->logout();
             $this->assertTrue($this->userService->removeUser($this->currentUser));
         }
     } catch (common_Exception $ce) {
         $this->fail($ce);
     }
 }
 public function createTranslationProperty($type, $countryCode = '', $langCode = '', $class = null)
 {
     $property = null;
     if (is_null($class) && !is_null($this->itemClass)) {
         $class = $this->itemClass;
     }
     if (!is_null($class)) {
         $label = TranslationProcessHelper::getPropertyName($type, $countryCode, $langCode);
         $uri = LOCAL_NAMESPACE . '#' . $label;
         $property = new core_kernel_classes_Property($uri);
         if (!$property->exists()) {
             $propertyClass = new core_kernel_classes_Class(RDF_PROPERTY, __METHOD__);
             $propertyInstance = $propertyClass->createInstance($label, '', $uri);
             $property = new core_kernel_classes_Property($propertyInstance->getUri(), __METHOD__);
         }
         if (!$class->setProperty($property)) {
             throw new common_Exception('problem creating property : cannot set property to class');
         }
         $this->properties[$label] = $property;
     } else {
         throw new common_Exception('problem creating property : no target class given');
     }
     return $property;
 }