/**
  * @dataProvider workflowNameDataProvider
  * @param string|null $requiredWorkflowName
  */
 public function testGetApplicableWorkflows($requiredWorkflowName)
 {
     // mocks for entity metadata
     $entity = new \DateTime('now');
     $entityClass = get_class($entity);
     $entityId = 1;
     $this->doctrineHelper->expects($this->any())->method('getEntityIdentifier')->with($entity)->will($this->returnValue($entityId));
     // mocks for workflows:
     // - without workflow items
     // - single managed entity with workflow items
     // - multiple managed entity with workflow items
     $singleEntityAttribute = new Attribute();
     $singleEntityAttribute->setOptions(array('class' => $entityClass));
     $multipleEntityAttribute = new Attribute();
     $multipleEntityAttribute->setOptions(array('class' => $entityClass, 'multiple' => true));
     $newWorkflow = $this->createWorkflow('new_workflow', array($singleEntityAttribute));
     $usedSingleWorkflow = $this->createWorkflow('used_single_workflow', array($singleEntityAttribute));
     $usedMultipleWorkflow = $this->createWorkflow('used_multiple_workflow', array($multipleEntityAttribute));
     $allowedWorkflows = array($newWorkflow, $usedSingleWorkflow, $usedMultipleWorkflow);
     if ($requiredWorkflowName) {
         $this->workflowRegistry->expects($this->exactly(2))->method('getWorkflow')->with($requiredWorkflowName)->will($this->returnValue($newWorkflow));
         // expected workflows (single managed entity with existing workflow items is not allowed)
         $expectedWorkflows = array($newWorkflow->getName() => $newWorkflow);
     } else {
         // expected workflows (single managed entity with existing workflow items is not allowed)
         $expectedWorkflows = array($newWorkflow->getName() => $newWorkflow, $usedMultipleWorkflow->getName() => $usedMultipleWorkflow);
         $this->workflowRegistry->expects($this->any())->method('getWorkflowsByEntityClass')->with($entityClass)->will($this->returnValue($allowedWorkflows));
     }
     // mocks for workflow items
     $workflowItems = array($this->createWorkflowItem($usedSingleWorkflow->getName()), $this->createWorkflowItem($usedMultipleWorkflow->getName()));
     $workflowItemsRepository = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\Repository\\WorkflowItemRepository')->disableOriginalConstructor()->setMethods(array('findByEntityMetadata'))->getMock();
     $workflowItemsRepository->expects($this->any())->method('findByEntityMetadata')->with($entityClass, $entityId, $requiredWorkflowName)->will($this->returnValue($workflowItems));
     $this->registry->expects($this->any())->method('getRepository')->with('OroWorkflowBundle:WorkflowItem')->will($this->returnValue($workflowItemsRepository));
     // with automatic workflow item extraction
     $this->assertEquals($expectedWorkflows, $this->workflowManager->getApplicableWorkflows($entity, null, $requiredWorkflowName));
     // with manual workflow item setting
     $this->assertEquals($expectedWorkflows, $this->workflowManager->getApplicableWorkflows($entity, $workflowItems, $requiredWorkflowName));
 }