/** * Adds required event listeners * * @param FormBuilderInterface $builder * @param array $options */ protected function addEventListeners(FormBuilderInterface $builder, array $options) { if (!empty($options['attribute_default_values'])) { $this->defaultValuesListener->initialize($options['workflow_item'], $options['attribute_default_values']); $builder->addEventSubscriber($this->defaultValuesListener); } if (!empty($options['init_actions'])) { $this->initActionsListener->initialize($options['workflow_item'], $options['init_actions']); $builder->addEventSubscriber($this->initActionsListener); } if (!empty($options['attribute_fields'])) { $this->requiredAttributesListener->initialize(array_keys($options['attribute_fields'])); $builder->addEventSubscriber($this->requiredAttributesListener); } }
public function testEvents() { $attributeNames = array('test'); $values = array('test' => 'value'); $data = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\WorkflowData')->disableOriginalConstructor()->getMock(); $data->expects($this->once())->method('getValues')->with($attributeNames)->will($this->returnValue($values)); $event = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('getData')->will($this->returnValue($data)); $event->expects($this->once())->method('setData')->with($this->isInstanceOf('Oro\\Bundle\\WorkflowBundle\\Model\\WorkflowData')); $this->listener->initialize($attributeNames); $this->listener->onPreSetData($event); // Test submit data $formData = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\WorkflowData')->disableOriginalConstructor()->getMock(); $formData->expects($this->once())->method('getValues')->will($this->returnValue($values)); $data->expects($this->once())->method('add')->with($values); $submitEvent = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock(); $submitEvent->expects($this->once())->method('getData')->will($this->returnValue($formData)); $submitEvent->expects($this->once())->method('setData')->with($this->isInstanceOf('Oro\\Bundle\\WorkflowBundle\\Model\\WorkflowData')); $this->listener->onSubmit($submitEvent); }