/**
  * test SetTestItems exception, since we created a new process
  * @depends testInstanceCreate
  * @param \core_kernel_classes_Resource $testInstance
  * @expectedException \common_Exception
  * @return void
  */
 public function testSetTestItemsFailure($testInstance)
 {
     $item = $this->wftService->createInstance($this->wftService->getRootclass(), 'WfTestUnitTestItem');
     $this->assertIsA($item, 'core_kernel_classes_Resource');
     $this->assertEquals('WfTestUnitTestItem', $item->getLabel());
     $this->assertTrue($item->exists());
     $this->assertTrue($this->wftService->setTestItems($testInstance, array($item)));
     $this->assertTrue($item->delete());
     $this->assertFalse($item->exists());
 }
 /**
  * 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;
 }