diff --git a/bundle/DependencyInjection/Compiler/LimitationFormMapperPass.php b/bundle/DependencyInjection/Compiler/LimitationFormMapperPass.php new file mode 100644 index 000000000..c22dbe224 --- /dev/null +++ b/bundle/DependencyInjection/Compiler/LimitationFormMapperPass.php @@ -0,0 +1,43 @@ +hasDefinition('ezrepoforms.limitation_form_mapper.registry')) { + return; + } + + $registry = $container->findDefinition('ezrepoforms.limitation_form_mapper.registry'); + + foreach ($container->findTaggedServiceIds('ez.limitation.formMapper') as $id => $attributes) { + foreach ($attributes as $attribute) { + if (!isset($attribute['limitationType'])) { + throw new LogicException( + 'ez.limitation.formMapper service tag needs a "limitationType" attribute to identify which LimitationType the mapper is for. None given.' + ); + } + + $registry->addMethodCall('addMapper', [new Reference($id), $attribute['limitationType']]); + } + } + } +} diff --git a/bundle/EzSystemsRepositoryFormsBundle.php b/bundle/EzSystemsRepositoryFormsBundle.php index 82e33ad1b..a8c615495 100644 --- a/bundle/EzSystemsRepositoryFormsBundle.php +++ b/bundle/EzSystemsRepositoryFormsBundle.php @@ -11,6 +11,7 @@ namespace EzSystems\RepositoryFormsBundle; use EzSystems\RepositoryFormsBundle\DependencyInjection\Compiler\FieldTypeFormMapperPass; +use EzSystems\RepositoryFormsBundle\DependencyInjection\Compiler\LimitationFormMapperPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -20,5 +21,6 @@ public function build(ContainerBuilder $container) { parent::build($container); $container->addCompilerPass(new FieldTypeFormMapperPass()); + $container->addCompilerPass(new LimitationFormMapperPass()); } } diff --git a/bundle/Resources/config/role.yml b/bundle/Resources/config/role.yml index c22e84266..e6de7544d 100644 --- a/bundle/Resources/config/role.yml +++ b/bundle/Resources/config/role.yml @@ -1,6 +1,7 @@ parameters: # Form types ezrepoforms.policy.edit.form.class: EzSystems\RepositoryForms\Form\Type\Role\PolicyType + ezrepoforms.policy.limitation.form.class: EzSystems\RepositoryForms\Form\Type\Role\LimitationType # Validators ezrepoforms.validator.unique_role_identifier.class: EzSystems\RepositoryForms\Validator\Constraints\UniqueRoleIdentifierValidator @@ -13,14 +14,29 @@ parameters: ezrepoforms.form_processor.role.class: EzSystems\RepositoryForms\Form\Processor\RoleFormProcessor ezrepoforms.form_processor.policy.class: EzSystems\RepositoryForms\Form\Processor\PolicyFormProcessor + # Limitation mappers + ezrepoforms.limitation_form_mapper.registry.class: EzSystems\RepositoryForms\Limitation\LimitationFormMapperRegistry + ezrepoforms.limitation.null.template: "EzSystemsRepositoryFormsBundle:Limitation:null_limitation_values.html.twig" + ezrepoforms.limitation.form_mapper.null.class: EzSystems\RepositoryForms\Limitation\Mapper\NullLimitationMapper + ezrepoforms.limitation.multiple_selection.template: "EzSystemsRepositoryFormsBundle:Limitation:base_limitation_values.html.twig" + ezrepoforms.limitation.form_mapper.siteaccess.class: EzSystems\RepositoryForms\Limitation\Mapper\SiteAccessLimitationMapper + ezrepoforms.limitation.form_mapper.contenttype.class: EzSystems\RepositoryForms\Limitation\Mapper\ContentTypeLimitationMapper + ezrepoforms.limitation.form_mapper.section.class: EzSystems\RepositoryForms\Limitation\Mapper\SectionLimitationMapper + services: # Form types ezrepoforms.policy.edit.form: class: %ezrepoforms.policy.edit.form.class% - arguments: [%ezpublish.api.role.policy_map%, @translator] + arguments: [%ezpublish.api.role.policy_map%, @translator, @ezpublish.api.service.role] tags: - { name: form.type, alias: ezrepoforms_policy_edit } + ezrepoforms.policy.limitation.form: + class: %ezrepoforms.policy.limitation.form.class% + arguments: [@ezrepoforms.limitation_form_mapper.registry, @ezrepoforms.limitation.form_mapper.null] + tags: + - { name: form.type, alias: ezrepoforms_policy_limitation_edit } + # Validators ezrepoforms.validator.unique_role_identifier: class: %ezrepoforms.validator.unique_role_identifier.class% @@ -49,3 +65,39 @@ services: arguments: [@ezpublish.api.service.role] tags: - { name: kernel.event_subscriber } + + ezrepoforms.limitation_form_mapper.registry: + class: %ezrepoforms.limitation_form_mapper.registry.class% + + ezrepoforms.limitation.form_mapper.multiple_selection: + class: EzSystems\RepositoryForms\Limitation\Mapper\MultipleSelectionBasedMapper + abstract: true + calls: + - [setFormTemplate, [%ezrepoforms.limitation.multiple_selection.template%]] + + ezrepoforms.limitation.form_mapper.siteaccess: + parent: ezrepoforms.limitation.form_mapper.multiple_selection + class: %ezrepoforms.limitation.form_mapper.siteaccess.class% + arguments: [%ezpublish.siteaccess.list%] + tags: + - { name: ez.limitation.formMapper, limitationType: SiteAccess } + + ezrepoforms.limitation.form_mapper.null: + class: %ezrepoforms.limitation.form_mapper.null.class% + arguments: [%ezrepoforms.limitation.null.template%] + tags: + - { name: ez.limitation.formMapper, limitationType: "Null" } + + ezrepoforms.limitation.form_mapper.contenttype: + parent: ezrepoforms.limitation.form_mapper.multiple_selection + class: %ezrepoforms.limitation.form_mapper.contenttype.class% + arguments: [@ezpublish.api.service.content_type] + tags: + - { name: ez.limitation.formMapper, limitationType: Class } + + ezrepoforms.limitation.form_mapper.section: + parent: ezrepoforms.limitation.form_mapper.multiple_selection + class: %ezrepoforms.limitation.form_mapper.section.class% + arguments: [@ezpublish.api.service.section] + tags: + - { name: ez.limitation.formMapper, limitationType: Section } diff --git a/bundle/Resources/translations/ezrepoforms_role.en.xlf b/bundle/Resources/translations/ezrepoforms_role.en.xlf index 6535c2fa0..2ba060f68 100644 --- a/bundle/Resources/translations/ezrepoforms_role.en.xlf +++ b/bundle/Resources/translations/ezrepoforms_role.en.xlf @@ -50,10 +50,42 @@ role.policy.form.delete Delete policy + + role.policy.limitation.none + No limitations available + + + role.policy.save_and_add_limitation + Save and add limitations + + + role.policy.available_limitations + Limitations + + + role.policy.save + Save + + + Class + ContentType + + + Node + Location + role.assignment.form.delete Delete assignment + + role.policy.limitation.any + Any + + + role.policy.limitation.not_implemented + Limitation edition for '%limitationTypeIdentifier%' is not implemented yet. + diff --git a/bundle/Resources/views/Limitation/base_limitation_values.html.twig b/bundle/Resources/views/Limitation/base_limitation_values.html.twig new file mode 100644 index 000000000..ce24156fa --- /dev/null +++ b/bundle/Resources/views/Limitation/base_limitation_values.html.twig @@ -0,0 +1,3 @@ +{{ form_label(form.limitationValues) }} +{{ form_errors(form.limitationValues) }} +{{ form_widget(form.limitationValues) }} diff --git a/bundle/Resources/views/Limitation/null_limitation_values.html.twig b/bundle/Resources/views/Limitation/null_limitation_values.html.twig new file mode 100644 index 000000000..aa323c9d2 --- /dev/null +++ b/bundle/Resources/views/Limitation/null_limitation_values.html.twig @@ -0,0 +1,3 @@ +{% do form.setRendered() %} +{{ form_label(form) }} +{{ "role.policy.limitation.not_implemented"|trans({"%limitationTypeIdentifier%": form.vars.data.identifier}, 'ezrepoforms_role') }} diff --git a/lib/Data/Mapper/PolicyMapper.php b/lib/Data/Mapper/PolicyMapper.php index 2d0831fc0..d85ef3181 100644 --- a/lib/Data/Mapper/PolicyMapper.php +++ b/lib/Data/Mapper/PolicyMapper.php @@ -36,6 +36,7 @@ public function mapToFormData(ValueObject $policyDraft, array $params = []) 'roleDraft' => $params['roleDraft'], 'initialRole' => $params['initialRole'], 'moduleFunction' => "{$policyDraft->module}|{$policyDraft->function}", + 'limitationsData' => $this->generateLimitationList($policyDraft->getLimitations(), $params['availableLimitationTypes']), ]); } else { $data = new PolicyCreateData([ @@ -51,7 +52,7 @@ public function mapToFormData(ValueObject $policyDraft, array $params = []) private function configureOptions(OptionsResolver $optionsResolver) { $optionsResolver - ->setRequired(['roleDraft', 'initialRole']) + ->setRequired(['roleDraft', 'initialRole', 'availableLimitationTypes']) ->setAllowedTypes('roleDraft', '\eZ\Publish\API\Repository\Values\User\RoleDraft') ->setAllowedTypes('initialRole', '\eZ\Publish\API\Repository\Values\User\Role'); } @@ -60,4 +61,33 @@ private function isPolicyNew(PolicyDraft $policy) { return $policy->id === null; } + + /** + * Generates the limitation list from existing limitations (already configured for current policy) and + * available limitation types available for current policy (i.e. current module/function combination). + * + * @param \eZ\Publish\API\Repository\Values\User\Limitation[] $existingLimitations + * @param \eZ\Publish\SPI\Limitation\Type[] $availableLimitationTypes + * + * @return array|\eZ\Publish\API\Repository\Values\User\Limitation[] + */ + private function generateLimitationList(array $existingLimitations, array $availableLimitationTypes) + { + $limitations = []; + foreach ($existingLimitations as $limitation) { + $limitations[$limitation->getIdentifier()] = $limitation; + } + + foreach ($availableLimitationTypes as $identifier => $limitationType) { + if (isset($limitations[$identifier])) { + continue; + } + + $limitations[$identifier] = $limitationType->buildValue([]); + } + + ksort($limitations); + + return $limitations; + } } diff --git a/lib/Data/Role/PolicyCreateData.php b/lib/Data/Role/PolicyCreateData.php index 559a43abf..963d80e4c 100644 --- a/lib/Data/Role/PolicyCreateData.php +++ b/lib/Data/Role/PolicyCreateData.php @@ -15,6 +15,7 @@ * @property-read \eZ\Publish\API\Repository\Values\User\PolicyDraft $policyDraft * @property-read \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft * @property-read \eZ\Publish\API\Repository\Values\User\Role $initialRole + * @property-read \eZ\Publish\API\Repository\Values\User\Limitation[] $limitationsData */ class PolicyCreateData extends PolicyCreateStruct implements NewsnessCheckable { @@ -24,4 +25,14 @@ public function isNew() { return true; } + + public function getModule() + { + return $this->module; + } + + public function getFunction() + { + return $this->function; + } } diff --git a/lib/Data/Role/PolicyDataTrait.php b/lib/Data/Role/PolicyDataTrait.php index 8ab0dcc76..d01a8d612 100644 --- a/lib/Data/Role/PolicyDataTrait.php +++ b/lib/Data/Role/PolicyDataTrait.php @@ -29,6 +29,13 @@ trait PolicyDataTrait */ protected $initialRole; + /** + * List of limitations that were posted. + * + * @var \eZ\Publish\API\Repository\Values\User\Limitation[] + */ + protected $limitationsData; + /** * Combination of module + function as a single string. * Example: "content|read". @@ -46,4 +53,8 @@ public function getId() { return $this->policyDraft ? $this->policyDraft->id : null; } + + abstract public function getModule(); + + abstract public function getFunction(); } diff --git a/lib/Data/Role/PolicyUpdateData.php b/lib/Data/Role/PolicyUpdateData.php index 12f163399..986b1cb1b 100644 --- a/lib/Data/Role/PolicyUpdateData.php +++ b/lib/Data/Role/PolicyUpdateData.php @@ -15,6 +15,7 @@ * @property-read \eZ\Publish\API\Repository\Values\User\PolicyDraft $policyDraft * @property-read \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft * @property-read \eZ\Publish\API\Repository\Values\User\Role $initialRole + * @property-read \eZ\Publish\API\Repository\Values\User\Limitation[] $limitationsData */ class PolicyUpdateData extends PolicyUpdateStruct { diff --git a/lib/Form/Processor/PolicyFormProcessor.php b/lib/Form/Processor/PolicyFormProcessor.php index 0a95de536..02b84e070 100644 --- a/lib/Form/Processor/PolicyFormProcessor.php +++ b/lib/Form/Processor/PolicyFormProcessor.php @@ -49,7 +49,16 @@ public function processUpdatePolicy(FormActionEvent $event) $data->function = $function; $this->roleService->addPolicyByRoleDraft($data->roleDraft, $data); } else { - // TODO: Save limitations. It's not possible by design to update policy module/function. + // Only save limitations on update. + // It is not possible by design to update policy module/function. + foreach ($data->limitationsData as $limitation) { + // Add posted limitations as valid ones, recognized by RoleService. + if (!empty($limitation->limitationValues)) { + $data->addLimitation($limitation); + } + } + + $this->roleService->updatePolicyByRoleDraft($data->roleDraft, $data->policyDraft, $data); } } diff --git a/lib/Form/Type/Role/LimitationType.php b/lib/Form/Type/Role/LimitationType.php new file mode 100644 index 000000000..1fa1748ce --- /dev/null +++ b/lib/Form/Type/Role/LimitationType.php @@ -0,0 +1,89 @@ +limitationFormMapperRegistry = $limitationFormMapperRegistry; + $this->nullMapper = $nullMapper; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { + /** @var \eZ\Publish\API\Repository\Values\User\Limitation $data */ + $data = $event->getData(); + $form = $event->getForm(); + + if ($this->limitationFormMapperRegistry->hasMapper($data->getIdentifier())) { + $this->limitationFormMapperRegistry->getMapper($data->getIdentifier())->mapLimitationForm($form, $data); + } + }); + + $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { + /** @var \eZ\Publish\API\Repository\Values\User\Limitation $data */ + $data = $event->getData(); + if ($this->limitationFormMapperRegistry->hasMapper($data->getIdentifier())) { + $this->limitationFormMapperRegistry->getMapper($data->getIdentifier())->filterLimitationValues($data); + } + }); + } + + public function buildView(FormView $view, FormInterface $form, array $options) + { + $data = $view->vars['value']; + if (!$data instanceof Limitation) { + return; + } + + if ($this->limitationFormMapperRegistry->hasMapper($data->getIdentifier())) { + $mapper = $this->limitationFormMapperRegistry->getMapper($data->getIdentifier()); + } else { + $mapper = $this->nullMapper; + } + $view->vars['mapper'] = $mapper; + $view->vars['template'] = $mapper->getFormTemplate(); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => '\eZ\Publish\API\Repository\Values\User\Limitation', + 'translation_domain' => 'ezrepoforms_role', + ]); + } + + public function getName() + { + return 'ezrepoforms_policy_limitation_edit'; + } +} diff --git a/lib/Form/Type/Role/PolicyType.php b/lib/Form/Type/Role/PolicyType.php index 4d2bbfb55..16ab66b26 100644 --- a/lib/Form/Type/Role/PolicyType.php +++ b/lib/Form/Type/Role/PolicyType.php @@ -8,8 +8,11 @@ */ namespace EzSystems\RepositoryForms\Form\Type\Role; +use eZ\Publish\API\Repository\RoleService; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormEvent; +use Symfony\Component\Form\FormEvents; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Translation\TranslatorInterface; @@ -25,10 +28,16 @@ class PolicyType extends AbstractType */ private $translator; - public function __construct(array $policyMap, TranslatorInterface $translator) + /** + * @var RoleService + */ + private $roleService; + + public function __construct(array $policyMap, TranslatorInterface $translator, RoleService $roleService) { $this->translator = $translator; $this->policyChoices = $this->buildPolicyChoicesFromMap($policyMap); + $this->roleService = $roleService; } /** @@ -83,7 +92,23 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'placeholder' => 'role.policy.type.choose', ]) ->add('removeDraft', 'submit', ['label' => 'role.cancel', 'validation_groups' => false]) - ->add('savePolicy', 'submit', ['label' => 'role.save']); + ->add('savePolicy', 'submit', ['label' => 'role.policy.save']); + + $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { + /** @var \EzSystems\RepositoryForms\Data\Role\PolicyCreateData|\EzSystems\RepositoryForms\Data\Role\PolicyUpdateData $data */ + $data = $event->getData(); + $form = $event->getForm(); + + if ($module = $data->getModule()) { + $form + ->add('limitationsData', 'collection', [ + 'type' => 'ezrepoforms_policy_limitation_edit', + 'label' => 'role.policy.available_limitations', + ]); + } else { + $form->add('saveAndAddLimitation', 'submit', ['label' => 'role.policy.save_and_add_limitation']); + } + }); } public function getName() diff --git a/lib/Limitation/LimitationFormMapperInterface.php b/lib/Limitation/LimitationFormMapperInterface.php new file mode 100644 index 000000000..7ae91da54 --- /dev/null +++ b/lib/Limitation/LimitationFormMapperInterface.php @@ -0,0 +1,48 @@ +limitationFormMappers; + } + + public function addMapper(LimitationFormMapperInterface $mapper, $fieldTypeIdentifier) + { + $this->limitationFormMappers[$fieldTypeIdentifier] = $mapper; + } + + /** + * Returns mapper corresponding to given Limitation identifier. + * + * @param string $limitationIdentifier + * + * @throws \InvalidArgumentException If no mapper exists for $fieldTypeIdentifier. + * + * @return LimitationFormMapperInterface + */ + public function getMapper($limitationIdentifier) + { + if (!$this->hasMapper($limitationIdentifier)) { + throw new InvalidArgumentException("No LimitationFormMapper found for '$limitationIdentifier'"); + } + + return $this->limitationFormMappers[$limitationIdentifier]; + } + + /** + * Checks if a mapper exists for given Limitation identifier. + * + * @param string $limitationIdentifier + * + * @return bool + */ + public function hasMapper($limitationIdentifier) + { + return isset($this->limitationFormMappers[$limitationIdentifier]); + } +} diff --git a/lib/Limitation/LimitationFormMapperRegistryInterface.php b/lib/Limitation/LimitationFormMapperRegistryInterface.php new file mode 100644 index 000000000..c64937983 --- /dev/null +++ b/lib/Limitation/LimitationFormMapperRegistryInterface.php @@ -0,0 +1,46 @@ +contentTypeService = $contentTypeService; + } + + protected function getSelectionChoices() + { + $contentTypeChoices = []; + foreach ($this->contentTypeService->loadContentTypeGroups() as $group) { + foreach ($this->contentTypeService->loadContentTypes($group) as $contentType) { + $contentTypeChoices[$contentType->id] = $contentType->getName($contentType->mainLanguageCode); + } + } + + return $contentTypeChoices; + } +} diff --git a/lib/Limitation/Mapper/MultipleSelectionBasedMapper.php b/lib/Limitation/Mapper/MultipleSelectionBasedMapper.php new file mode 100644 index 000000000..11d8e6bb4 --- /dev/null +++ b/lib/Limitation/Mapper/MultipleSelectionBasedMapper.php @@ -0,0 +1,68 @@ +getChoiceFieldOptions() + [ + 'multiple' => true, + 'label' => $data->getIdentifier(), + ]; + $choices = $this->getSelectionChoices(); + asort($choices, SORT_NATURAL | SORT_FLAG_CASE); + $form->add('limitationValues', 'choice', $options); + } + + /** + * Returns value choices to display, as expected by the "choices" option from Choice field. + * + * @return array + */ + abstract protected function getSelectionChoices(); + + /** + * Returns custom options. + * + * @return array + */ + protected function getChoiceFieldOptions() + { + return []; + } + + public function setFormTemplate($template) + { + $this->template = $template; + } + + public function getFormTemplate() + { + return $this->template; + } + + public function filterLimitationValues(Limitation $limitation) + { + } +} diff --git a/lib/Limitation/Mapper/NullLimitationMapper.php b/lib/Limitation/Mapper/NullLimitationMapper.php new file mode 100644 index 000000000..f16634859 --- /dev/null +++ b/lib/Limitation/Mapper/NullLimitationMapper.php @@ -0,0 +1,39 @@ +template = $template; + } + + public function mapLimitationForm(FormInterface $form, Limitation $data) + { + } + + public function getFormTemplate() + { + return $this->template; + } + + public function filterLimitationValues(Limitation $limitation) + { + } +} diff --git a/lib/Limitation/Mapper/SectionLimitationMapper.php b/lib/Limitation/Mapper/SectionLimitationMapper.php new file mode 100644 index 000000000..17cdfeb7c --- /dev/null +++ b/lib/Limitation/Mapper/SectionLimitationMapper.php @@ -0,0 +1,34 @@ +sectionService = $sectionService; + } + + protected function getSelectionChoices() + { + $choices = []; + foreach ($this->sectionService->loadSections() as $section) { + $choices[$section->id] = $section->name; + } + + return $choices; + } +} diff --git a/lib/Limitation/Mapper/SiteAccessLimitationMapper.php b/lib/Limitation/Mapper/SiteAccessLimitationMapper.php new file mode 100644 index 000000000..202f16266 --- /dev/null +++ b/lib/Limitation/Mapper/SiteAccessLimitationMapper.php @@ -0,0 +1,37 @@ +siteAccessList = $siteAccessList; + } + + protected function getSelectionChoices() + { + $siteAccesses = []; + foreach ($this->siteAccessList as $sa) { + $siteAccesses[sprintf('%u', crc32($sa))] = $sa; + } + + return $siteAccesses; + } + + protected function getChoiceFieldOptions() + { + return ['required' => false]; + } +} diff --git a/tests/RepositoryForms/Data/Mapper/PolicyMapperTest.php b/tests/RepositoryForms/Data/Mapper/PolicyMapperTest.php index 75d421ec1..5923958c8 100644 --- a/tests/RepositoryForms/Data/Mapper/PolicyMapperTest.php +++ b/tests/RepositoryForms/Data/Mapper/PolicyMapperTest.php @@ -32,7 +32,7 @@ public function testMapToCreateNoRoleDraft() public function testMapToCreateNoInitialRole() { $policy = new PolicyDraft(); - (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => new RoleDraft()]); + (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => new RoleDraft(), 'availableLimitationTypes' => []]); } public function testMapToCreate() @@ -40,7 +40,11 @@ public function testMapToCreate() $policy = new PolicyDraft(['innerPolicy' => new Policy()]); $roleDraft = new RoleDraft(); $initialRole = new Role(); - $data = (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => $roleDraft, 'initialRole' => $initialRole]); + $data = (new PolicyMapper())->mapToFormData($policy, [ + 'roleDraft' => $roleDraft, + 'initialRole' => $initialRole, + 'availableLimitationTypes' => [], + ]); self::assertInstanceOf('\EzSystems\RepositoryForms\Data\Role\PolicyCreateData', $data); self::assertSame($policy, $data->policyDraft); self::assertSame($roleDraft, $data->roleDraft); @@ -64,7 +68,7 @@ public function testMapToUpdateNoInitialRole() { $policy = new PolicyDraft(['innerPolicy' => new Policy(['id' => 123])]); $roleDraft = new RoleDraft(); - (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => $roleDraft]); + (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => $roleDraft, 'availableLimitationTypes' => []]); } public function testMapToUpdate() @@ -79,7 +83,11 @@ public function testMapToUpdate() ]); $roleDraft = new RoleDraft(); $initialRole = new Role(); - $data = (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => $roleDraft, 'initialRole' => $initialRole]); + $data = (new PolicyMapper())->mapToFormData($policy, [ + 'roleDraft' => $roleDraft, + 'initialRole' => $initialRole, + 'availableLimitationTypes' => [], + ]); self::assertInstanceOf('\EzSystems\RepositoryForms\Data\Role\PolicyUpdateData', $data); self::assertSame($policy, $data->policyDraft); self::assertSame($roleDraft, $data->roleDraft); diff --git a/tests/RepositoryForms/Form/Processor/PolicyFormProcessorTest.php b/tests/RepositoryForms/Form/Processor/PolicyFormProcessorTest.php index a5fcb3a92..a989d6e27 100644 --- a/tests/RepositoryForms/Form/Processor/PolicyFormProcessorTest.php +++ b/tests/RepositoryForms/Form/Processor/PolicyFormProcessorTest.php @@ -54,7 +54,11 @@ public function testProcessCreate() $policy = new PolicyDraft(['innerPolicy' => new Policy()]); $roleDraft = new RoleDraft(); $initialRole = new Role(); - $data = (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => $roleDraft, 'initialRole' => $initialRole]); + $data = (new PolicyMapper())->mapToFormData($policy, [ + 'roleDraft' => $roleDraft, + 'initialRole' => $initialRole, + 'availableLimitationTypes' => [], + ]); $module = 'foo'; $function = 'bar'; $data->moduleFunction = "$module|$function"; @@ -73,7 +77,11 @@ public function testSavePolicy() $policy = new PolicyDraft(['innerPolicy' => new Policy()]); $roleDraft = new RoleDraft(); $initialRole = new Role(); - $data = (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => $roleDraft, 'initialRole' => $initialRole]); + $data = (new PolicyMapper())->mapToFormData($policy, [ + 'roleDraft' => $roleDraft, + 'initialRole' => $initialRole, + 'availableLimitationTypes' => [], + ]); $module = 'foo'; $function = 'bar'; $data->moduleFunction = "$module|$function"; @@ -92,7 +100,11 @@ public function testRemoveDraftOnCreateData() $policy = new PolicyDraft(['innerPolicy' => new Policy()]); $roleDraft = new RoleDraft(); $initialRole = new Role(); - $data = (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => $roleDraft, 'initialRole' => $initialRole]); + $data = (new PolicyMapper())->mapToFormData($policy, [ + 'roleDraft' => $roleDraft, + 'initialRole' => $initialRole, + 'availableLimitationTypes' => [], + ]); $module = 'foo'; $function = 'bar'; $data->moduleFunction = "$module|$function"; @@ -115,7 +127,11 @@ public function testRemoveDraftOnUpdateData() $policy = new PolicyDraft(['innerPolicy' => new Policy(['id' => 123])]); $roleDraft = new RoleDraft(); $initialRole = new Role(); - $data = (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => $roleDraft, 'initialRole' => $initialRole]); + $data = (new PolicyMapper())->mapToFormData($policy, [ + 'roleDraft' => $roleDraft, + 'initialRole' => $initialRole, + 'availableLimitationTypes' => [], + ]); $module = 'foo'; $function = 'bar'; $data->moduleFunction = "$module|$function";