public function testTheTester()
 {
     $process1 = $this->createLinearProcess();
     $arr = wfAuthoring_models_classes_ProcessService::singleton()->getInitialSteps($process1);
     $this->assertEquals(count($arr), 1);
     $startP1 = current($arr);
     $arr = wfAuthoring_models_classes_ProcessService::singleton()->getFinalSteps($process1);
     $this->assertEquals(count($arr), 1);
     $endP1 = current($arr);
     $this->assertEquals($startP1, $startP1);
     $final = $this->assertProcessPartCorresponds($startP1, $startP1);
     $arr = wfEngine_models_classes_StepService::singleton()->getNextSteps($final);
     $this->assertTrue(empty($arr));
     $cloner = new wfAuthoring_models_classes_ProcessCloner();
     $clone = $cloner->cloneProcess($process1);
     $arr = wfAuthoring_models_classes_ProcessService::singleton()->getInitialSteps($clone);
     $this->assertEquals(count($arr), 1);
     $startClone = current($arr);
     $this->assertNotEquals($startP1, $startClone);
     $this->assertCorresponds($startP1, $startClone);
     $final = $this->assertProcessPartCorresponds($startP1, $startClone);
     $arr = wfEngine_models_classes_StepService::singleton()->getNextSteps($final);
     $this->assertTrue(empty($arr));
     wfAuthoring_models_classes_ProcessService::singleton()->deleteProcess($clone);
     wfAuthoring_models_classes_ProcessService::singleton()->deleteProcess($process1);
 }
 /**
  * (non-PHPdoc)
  * @see tao_models_classes_Compiler::compile()
  */
 public function compile()
 {
     $report = new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Published test "%s"', $this->getResource()->getLabel()));
     common_ext_ExtensionsManager::singleton()->getExtensionById('taoWfTest');
     // loads the extension
     $test = $this->getResource();
     common_Logger::i('Compiling test ' . $test->getLabel() . ' items');
     $process = $test->getUniquePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP));
     if (count(wfEngine_models_classes_ProcessDefinitionService::singleton()->getAllActivities($process)) == 0) {
         return new common_report_Report(common_report_Report::TYPE_ERROR, __('An empty test cannot be published.'));
     }
     $processCloner = new wfAuthoring_models_classes_ProcessCloner();
     try {
         $processClone = $processCloner->cloneProcess($process);
         $report->add(new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Cloned the process %s', $process->getLabel())));
         $itemsServiceReport = $this->process($processClone);
         foreach ($itemsServiceReport as $subReport) {
             $report->add($subReport);
         }
         if ($itemsServiceReport->getType() == common_report_Report::TYPE_SUCCESS) {
             $serviceCall = new tao_models_classes_service_ServiceCall(new core_kernel_classes_Resource(INSTANCE_SERVICE_PROCESSRUNNER));
             $param = new tao_models_classes_service_ConstantParameter(new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_PROCESSDEFINITION), $processClone->getUri());
             $serviceCall->addInParameter($param);
             $report->setData($serviceCall);
         } else {
             $report->setType(common_report_Report::TYPE_ERROR);
         }
     } catch (common_Exception $e) {
         $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, __('Failed to clone the process')));
         $report->setType(common_report_Report::TYPE_ERROR);
     }
     if ($report->getType() != common_report_Report::TYPE_SUCCESS) {
         $report->setMessage(__('Failed to publish test "%s".', $this->getResource()->getLabel()));
     }
     return $report;
 }
 /**
  * (non-PHPdoc)
  * @see taoTests_models_classes_TestModel::cloneContent()
  */
 public function cloneContent(core_kernel_classes_Resource $source, core_kernel_classes_Resource $destination)
 {
     //clone the process:
     $propInstanceContent = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP);
     try {
         $process = $source->getUniquePropertyValue($propInstanceContent);
         $processCloner = new wfAuthoring_models_classes_ProcessCloner();
         $processClone = $processCloner->cloneProcess($process);
         $destination->editPropertyValues($propInstanceContent, $processClone->getUri());
     } catch (Exception $e) {
         throw new Exception("the test process cannot be found");
     }
 }
 public function __construct(core_kernel_classes_Resource $processDefinition)
 {
     $this->processDefinition = $processDefinition;
     parent::__construct();
 }
 /**
  * Short description of method cloneInstance
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param
  *            Resource instance
  * @param
  *            Class clazz
  * @return core_kernel_classes_Resource
  */
 public function cloneInstance(core_kernel_classes_Resource $instance, core_kernel_classes_Class $clazz = null)
 {
     $returnValue = null;
     // call the parent create instance to prevent useless process test to be created:
     $label = $instance->getLabel();
     $cloneLabel = "{$label} bis";
     $clone = parent::createInstance($clazz, $cloneLabel);
     if (!is_null($clone)) {
         $noCloningProperties = array(TEST_TESTCONTENT_PROP, RDF_TYPE);
         foreach ($clazz->getProperties(true) as $property) {
             if (!in_array($property->getUri(), $noCloningProperties)) {
                 // allow clone of every property value but the deliverycontent, which is a process:
                 foreach ($instance->getPropertyValues($property) as $propertyValue) {
                     $clone->setPropertyValue($property, $propertyValue);
                 }
             }
         }
         // Fix label
         if (preg_match("/bis/", $label)) {
             $cloneNumber = (int) preg_replace("/^(.?)*bis/", "", $label);
             $cloneNumber++;
             $cloneLabel = preg_replace("/bis(.?)*\$/", "", $label) . "bis {$cloneNumber}";
         }
         $clone->setLabel($cloneLabel);
         // clone the process:
         $propInstanceContent = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP);
         try {
             $process = $instance->getUniquePropertyValue($propInstanceContent);
         } catch (Exception $e) {
         }
         if (!is_null($process)) {
             $processCloner = new wfAuthoring_models_classes_ProcessCloner();
             $processClone = $processCloner->cloneProcess($process);
             $clone->editPropertyValues($propInstanceContent, $processClone->getUri());
         } else {
             throw new Exception("the test process cannot be found");
         }
         $this->onChangeTestLabel($clone);
         $returnValue = $clone;
     }
     return $returnValue;
 }
 /**
  * Short description of method cloneProcess
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource instance
  * @param  Class clazz
  * @return core_kernel_classes_Resource
  */
 public function cloneProcess(core_kernel_classes_Resource $instance, core_kernel_classes_Class $clazz)
 {
     $returnValue = null;
     if (!is_null($instance) && !is_null($clazz)) {
         $processCloner = new wfAuthoring_models_classes_ProcessCloner();
         $returnValue = $processCloner->cloneProcess($instance);
     }
     return $returnValue;
 }