示例#1
0
 public function testEntityAclAllowed()
 {
     $this->assertTrue($this->step->isEntityUpdateAllowed('not_existing_attribute'));
     $this->assertTrue($this->step->isEntityDeleteAllowed('not_existing_attribute'));
     $this->step->setEntityAcls(array('existing_attribute' => array('update' => false, 'delete' => false)));
     $this->assertFalse($this->step->isEntityUpdateAllowed('existing_attribute'));
     $this->assertFalse($this->step->isEntityDeleteAllowed('existing_attribute'));
     $this->step->setEntityAcls(array('existing_attribute' => array('update' => true, 'delete' => true)));
     $this->assertTrue($this->step->isEntityUpdateAllowed('existing_attribute'));
     $this->assertTrue($this->step->isEntityDeleteAllowed('existing_attribute'));
 }
 /**
  * @param array $inputData
  * @param array $expectedData
  * @param array $expectedAcls
  * @dataProvider buildFromConfigurationDataProvider
  */
 public function testBuildFromConfiguration(array $inputData, array $expectedData, array $expectedAcls = array())
 {
     $workflowConfiguration = current($inputData);
     $steps = array();
     if (!empty($workflowConfiguration[WorkflowConfiguration::NODE_STEPS])) {
         foreach ($workflowConfiguration[WorkflowConfiguration::NODE_STEPS] as $stepData) {
             $step = new Step();
             $step->setName($stepData['name']);
             if (!empty($stepData['entity_acl'])) {
                 $step->setEntityAcls($stepData['entity_acl']);
             }
             if (array_key_exists('is_final', $stepData)) {
                 $step->setFinal($stepData['is_final']);
             }
             $steps[] = $step;
         }
     }
     if (!empty($workflowConfiguration['start_step'])) {
         $step = new Step();
         $step->setName($workflowConfiguration['start_step']);
         $steps[] = $step;
     }
     $stepManager = new StepManager($steps);
     $attributes = array();
     if (!empty($workflowConfiguration[WorkflowConfiguration::NODE_ATTRIBUTES])) {
         foreach ($workflowConfiguration[WorkflowConfiguration::NODE_ATTRIBUTES] as $attributeData) {
             $attribute = new Attribute();
             $attribute->setName($attributeData['name']);
             $attribute->setType($attributeData['type']);
             if (!empty($attributeData['entity_acl'])) {
                 $attribute->setEntityAcl($attributeData['entity_acl']);
             }
             $attributes[] = $attribute;
         }
     }
     $attributeManager = new AttributeManager($attributes);
     $workflow = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\Workflow')->disableOriginalConstructor()->setMethods(array('getStepManager', 'getAttributeManager'))->getMock();
     $workflow->expects($this->any())->method('getStepManager')->will($this->returnValue($stepManager));
     $workflow->expects($this->any())->method('getAttributeManager')->will($this->returnValue($attributeManager));
     $workflowAssembler = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\WorkflowAssembler')->disableOriginalConstructor()->setMethods(array('assemble'))->getMock();
     $workflowAssembler->expects($this->once())->method('assemble')->with($this->isInstanceOf('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowDefinition'), false)->will($this->returnValue($workflow));
     $fieldGenerator = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Field\\FieldGenerator')->disableOriginalConstructor()->setMethods(array('generateWorkflowFields'))->getMock();
     $fieldGenerator->expects($this->once())->method('generateWorkflowFields')->with($expectedData['entity']);
     $builder = new WorkflowDefinitionConfigurationBuilder($workflowAssembler, $fieldGenerator);
     $workflowDefinitions = $builder->buildFromConfiguration($inputData);
     $this->assertCount(1, $workflowDefinitions);
     /** @var WorkflowDefinition $workflowDefinition */
     $workflowDefinition = current($workflowDefinitions);
     $this->assertEquals($expectedData, $this->getDataAsArray($workflowDefinition));
     $actualAcls = $workflowDefinition->getEntityAcls()->toArray();
     $this->assertSameSize($expectedAcls, $actualAcls);
     foreach ($expectedAcls as $expectedAcl) {
         /** @var WorkflowEntityAcl $actualAcl */
         $actualAcl = array_shift($actualAcls);
         $this->assertEquals($expectedAcl['step'], $actualAcl->getStep()->getName());
         $this->assertEquals($expectedAcl['attribute'], $actualAcl->getAttribute());
         $this->assertEquals($expectedAcl['permissions']['update'], $actualAcl->isUpdatable());
         $this->assertEquals($expectedAcl['permissions']['delete'], $actualAcl->isDeletable());
     }
 }