/**
  * @expectedException \Oro\Bundle\WorkflowBundle\Exception\UnknownAttributeException
  * @expectedExceptionMessage Can't find attribute for managed entity in workflow "empty_workflow"
  */
 public function testGetWorkflowDataUnknownAttribute()
 {
     $workflowName = 'empty_workflow';
     $transition = 'test_transition';
     $entity = new \DateTime('now');
     $workflow = $this->createWorkflow($workflowName);
     $this->workflowRegistry->expects($this->once())->method('getWorkflow')->with($workflowName)->will($this->returnValue($workflow));
     $this->workflowManager->isStartTransitionAvailable($workflowName, $transition, $entity);
 }
Пример #2
0
 /**
  * @param Lead | Opportunity $entity
  * @param User $owner
  */
 protected function loadSalesFlows($entity, $owner)
 {
     if ($entity instanceof Lead) {
         $step = 'start_from_lead';
         $parameters = array('lead' => $entity);
     } else {
         $step = 'start_from_opportunity';
         $parameters = array('opportunity' => $entity);
     }
     $parameters = array_merge(array('sales_funnel' => null, 'sales_funnel_owner' => $owner, 'sales_funnel_start_date' => new \DateTime('now')), $parameters);
     $salesFunnel = new SalesFunnel();
     $salesFunnel->setDataChannel($this->getReference('default_channel'));
     if (!$this->workflowManager->isStartTransitionAvailable('b2b_flow_sales_funnel', $step, $salesFunnel, $parameters)) {
         return;
     }
     $salesFunnelItem = $this->workflowManager->startWorkflow('b2b_flow_sales_funnel', $salesFunnel, $step, $parameters);
     $salesFunnelItem->getData()->set('new_opportunity_name', $entity->getName())->set('new_company_name', $entity->getName());
     if ($entity instanceof Lead) {
         if ($this->isTransitionAllowed($salesFunnelItem, 'qualify')) {
             $this->workflowManager->transit($salesFunnelItem, 'qualify');
         } else {
             return;
         }
     }
     if (rand(1, 100) > 10) {
         $salesFunnelItem->getData()->set('budget_amount', mt_rand(10, 10000))->set('customer_need', mt_rand(10, 10000))->set('proposed_solution', mt_rand(10, 10000))->set('probability', $this->probabilities[array_rand($this->probabilities)]);
         if ($this->isTransitionAllowed($salesFunnelItem, 'develop')) {
             $this->workflowManager->transit($salesFunnelItem, 'develop');
             if ($this->getRandomBoolean()) {
                 $salesFunnelItem->getData()->set('close_revenue', mt_rand(10, 1000))->set('close_date', new \DateTime());
                 if ($this->getRandomBoolean()) {
                     if ($this->isTransitionAllowed($salesFunnelItem, 'close_as_won')) {
                         $this->workflowManager->transit($salesFunnelItem, 'close_as_won');
                     }
                 } else {
                     $salesFunnelItem->getData()->set('close_reason_name', 'cancelled')->set('close_date', new \DateTime('now', new \DateTimeZone('UTC')));
                     if ($this->isTransitionAllowed($salesFunnelItem, 'close_as_lost')) {
                         $this->workflowManager->transit($salesFunnelItem, 'close_as_lost');
                     }
                 }
             }
         }
     }
 }
Пример #3
0
 public function testIsStartTransitionAvailable()
 {
     $workflowName = 'test_workflow';
     $errors = new ArrayCollection();
     $entity = new \DateTime('now');
     $data = array();
     $entityAttribute = new Attribute();
     $entityAttribute->setName('entity_attribute');
     $entityAttribute->setType('entity');
     $entityAttribute->setOptions(array('class' => 'DateTime'));
     $stringAttribute = new Attribute();
     $stringAttribute->setName('other_attribute');
     $stringAttribute->setType('string');
     $transition = 'test_transition';
     $workflow = $this->createWorkflow($workflowName, array($entityAttribute, $stringAttribute));
     $workflow->expects($this->once())->method('isStartTransitionAvailable')->with($transition, $entity, $data, $errors)->will($this->returnValue(true));
     $this->workflowRegistry->expects($this->once())->method('getWorkflow')->with($workflowName)->will($this->returnValue($workflow));
     $this->assertTrue($this->workflowManager->isStartTransitionAvailable($workflowName, $transition, $entity, $data, $errors));
 }