public function testEntityAclAllowed() { $attribute = new Attribute(); $this->assertTrue($attribute->isEntityUpdateAllowed()); $this->assertTrue($attribute->isEntityDeleteAllowed()); $attribute->setEntityAcl(array('update' => false, 'delete' => false)); $this->assertFalse($attribute->isEntityUpdateAllowed()); $this->assertFalse($attribute->isEntityDeleteAllowed()); $attribute->setEntityAcl(array('update' => true, 'delete' => true)); $this->assertTrue($attribute->isEntityUpdateAllowed()); $this->assertTrue($attribute->isEntityDeleteAllowed()); }
/** * @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()); } }
/** * @param WorkflowDefinition $definition * @param string $name * @param array $options * @return Attribute */ protected function assembleAttribute(WorkflowDefinition $definition, $name, array $options) { if (!empty($options['property_path'])) { $options = $this->guessOptions($options, $definition->getRelatedEntity(), $options['property_path']); } $this->assertOptions($options, array('label', 'type')); $this->assertAttributeEntityAcl($options); $attribute = new Attribute(); $attribute->setName($name); $attribute->setLabel($options['label']); $attribute->setType($options['type']); $attribute->setEntityAcl($this->getOption($options, 'entity_acl', array())); $attribute->setPropertyPath($this->getOption($options, 'property_path')); $attribute->setOptions($this->getOption($options, 'options', array())); $this->validateAttribute($attribute); return $attribute; }
/** * @param string $name * @param string $label * @param string $type * @param array $options * @param string $propertyPath * @param array $entityAcl * @return Attribute */ protected function getAttribute($name, $label, $type, array $options = array(), $propertyPath = null, array $entityAcl = array()) { $attribute = new Attribute(); $attribute->setName($name); $attribute->setLabel($label); $attribute->setType($type); $attribute->setOptions($options); $attribute->setPropertyPath($propertyPath); $attribute->setEntityAcl($entityAcl); return $attribute; }