/** * @param array $fields * @param array $configValues * @param array $expected * * @dataProvider fieldsDataProvider */ public function testGetFields(array $fields, array $configValues, array $expected) { $entity = new \StdClass(); foreach ($fields as $field) { /** @var ConfigInterface $field */ $fieldId = $field->getId(); /** @var FieldConfigId $fieldId */ $fieldName = $fieldId->getFieldName(); $entity->{$fieldName} = $fieldName; } $this->configProvider->expects($this->once())->method('filter')->will($this->returnValue($fields)); $config = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface'); $this->configProvider->expects($this->any())->method('getConfigById')->will($this->returnValue($config)); foreach ($configValues as $key => $configValue) { $config->expects($this->at($key))->method('get')->will($this->returnCallback(function ($value, $strict, $default) use($configValue) { if (!is_null($configValue)) { return $configValue; } return $default; })); } $this->dispatcher->expects($this->exactly(sizeof($fields)))->method('dispatch'); $rows = $this->extension->getFields($entity); $this->assertEquals(json_encode($expected), json_encode($rows)); }
/** * @param object $entity * @param null|string $entityClass * @return array */ public function getFields($entity, $entityClass = null) { $dynamicRows = parent::getFields($entity, $entityClass); if (method_exists($entity, 'getFormType')) { if ($entity->getFormType() != 'diamante_embedded_form.form_type.available_embedded_form') { unset($dynamicRows['branch']); } else { unset($dynamicRows['dataChannel']); } } return $dynamicRows; }