diff --git a/src/bundle/ParamConverter/ContentInfoParamConverter.php b/src/bundle/ParamConverter/ContentInfoParamConverter.php deleted file mode 100644 index 1f5abcc105..0000000000 --- a/src/bundle/ParamConverter/ContentInfoParamConverter.php +++ /dev/null @@ -1,57 +0,0 @@ -contentService = $contentTypeService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - $id = (int)$request->get(self::PARAMETER_CONTENT_INFO_ID); - $contentInfo = $this->contentService->loadContentInfo($id); - - if (!$contentInfo) { - throw new NotFoundHttpException("Content Info $id not found."); - } - - $request->attributes->set($configuration->getName(), $contentInfo); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return ContentInfo::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/ContentParamConverter.php b/src/bundle/ParamConverter/ContentParamConverter.php deleted file mode 100644 index 5cf9dd513a..0000000000 --- a/src/bundle/ParamConverter/ContentParamConverter.php +++ /dev/null @@ -1,69 +0,0 @@ -contentService = $contentService; - } - - /** - * {@inheritdoc} - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException - */ - public function apply(Request $request, ParamConverter $configuration): bool - { - $contentId = $request->get(self::PARAMETER_CONTENT_ID); - $versionNo = $request->get(self::PARAMETER_VERSION_NO); - $languageCode = $request->get(self::PARAMETER_LANGUAGE_CODE); - - if (null === $contentId || !\is_array($languageCode)) { - return false; - } - - $content = $this->contentService->loadContent($contentId, $languageCode, $versionNo); - - $request->attributes->set($configuration->getName(), $content); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration): bool - { - return Content::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/ContentTypeDraftParamConverter.php b/src/bundle/ParamConverter/ContentTypeDraftParamConverter.php deleted file mode 100644 index 93a2a0d932..0000000000 --- a/src/bundle/ParamConverter/ContentTypeDraftParamConverter.php +++ /dev/null @@ -1,53 +0,0 @@ -contentTypeService = $contentTypeGroupService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - if (!$request->get(self::PARAMETER_CONTENT_TYPE_ID)) { - return false; - } - - $id = (int)$request->get(self::PARAMETER_CONTENT_TYPE_ID); - - $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($id); - - $request->attributes->set($configuration->getName(), $contentTypeDraft); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return ContentTypeDraft::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/ContentTypeGroupParamConverter.php b/src/bundle/ParamConverter/ContentTypeGroupParamConverter.php deleted file mode 100644 index f51b982ceb..0000000000 --- a/src/bundle/ParamConverter/ContentTypeGroupParamConverter.php +++ /dev/null @@ -1,65 +0,0 @@ -contentTypeService = $contentTypeService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - if (!$request->get(self::PARAMETER_CONTENT_TYPE_GROUP_ID)) { - return false; - } - - $id = (int)$request->get(self::PARAMETER_CONTENT_TYPE_GROUP_ID); - - try { - $group = $this->contentTypeService->loadContentTypeGroup($id); - } catch (NotFoundException $e) { - throw new NotFoundHttpException("Content type group $id not found."); - } - - $request->attributes->set($configuration->getName(), $group); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return ContentTypeGroup::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/ContentTypeParamConverter.php b/src/bundle/ParamConverter/ContentTypeParamConverter.php deleted file mode 100644 index 4decf2136e..0000000000 --- a/src/bundle/ParamConverter/ContentTypeParamConverter.php +++ /dev/null @@ -1,78 +0,0 @@ -contentTypeService = $contentTypeGroupService; - $this->languagePreferenceProvider = $languagePreferenceProvider; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - if (!$request->get(self::PARAMETER_CONTENT_TYPE_ID) && !$request->get(self::PARAMETER_CONTENT_TYPE_IDENTIFIER)) { - return false; - } - - $prioritizedLanguages = $this->languagePreferenceProvider->getPreferredLanguages(); - - try { - if ($request->get(self::PARAMETER_CONTENT_TYPE_ID)) { - $id = (int)$request->get(self::PARAMETER_CONTENT_TYPE_ID); - $contentType = $this->contentTypeService->loadContentType($id, $prioritizedLanguages); - } elseif ($request->get(self::PARAMETER_CONTENT_TYPE_IDENTIFIER)) { - $identifier = $request->get(self::PARAMETER_CONTENT_TYPE_IDENTIFIER); - $contentType = $this->contentTypeService->loadContentTypeByIdentifier($identifier, $prioritizedLanguages); - } - } catch (NotFoundException $e) { - throw new NotFoundHttpException('Content type ' . ($id ?? $identifier) . ' not found.'); - } - - $request->attributes->set($configuration->getName(), $contentType); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return ContentType::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/LanguageParamConverter.php b/src/bundle/ParamConverter/LanguageParamConverter.php deleted file mode 100644 index 4aa93a3ac2..0000000000 --- a/src/bundle/ParamConverter/LanguageParamConverter.php +++ /dev/null @@ -1,74 +0,0 @@ -languageService = $languageService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - if (!$request->get(self::PARAMETER_LANGUAGE_ID) && !$request->get(self::PARAMETER_LANGUAGE_CODE)) { - return false; - } - - if ($request->get(self::PARAMETER_LANGUAGE_ID)) { - $id = (int)$request->get(self::PARAMETER_LANGUAGE_ID); - - try { - $language = $this->languageService->loadLanguageById($id); - } catch (NotFoundException $e) { - throw new NotFoundHttpException("Language $id not found."); - } - } elseif ($request->get(self::PARAMETER_LANGUAGE_CODE)) { - $languageCode = $request->get(self::PARAMETER_LANGUAGE_CODE); - - try { - $language = $this->languageService->loadLanguage($languageCode); - } catch (NotFoundException $e) { - throw new NotFoundHttpException("Language $languageCode not found."); - } - } - - $request->attributes->set($configuration->getName(), $language); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return Language::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/ObjectStateGroupParamConverter.php b/src/bundle/ParamConverter/ObjectStateGroupParamConverter.php deleted file mode 100644 index 3c561c063f..0000000000 --- a/src/bundle/ParamConverter/ObjectStateGroupParamConverter.php +++ /dev/null @@ -1,64 +0,0 @@ -objectStateService = $objectStateService; - } - - /** - * @param \Symfony\Component\HttpFoundation\Request $request - * @param \Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter $configuration - * - * @return bool - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException - */ - public function apply(Request $request, ParamConverter $configuration) - { - $id = (int)$request->get(self::PARAMETER_OBJECT_STATE_GROUP_ID); - $objectStateGroup = $this->objectStateService->loadObjectStateGroup($id); - - if (!$objectStateGroup) { - throw new NotFoundHttpException("Object state group $id not found."); - } - - $request->attributes->set($configuration->getName(), $objectStateGroup); - - return true; - } - - /** - * @param \Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter $configuration - * - * @return bool - */ - public function supports(ParamConverter $configuration) - { - return ObjectStateGroup::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/ObjectStateParamConverter.php b/src/bundle/ParamConverter/ObjectStateParamConverter.php deleted file mode 100644 index db9322ed00..0000000000 --- a/src/bundle/ParamConverter/ObjectStateParamConverter.php +++ /dev/null @@ -1,64 +0,0 @@ -objectStateService = $objectStateService; - } - - /** - * @param \Symfony\Component\HttpFoundation\Request $request - * @param \Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter $configuration - * - * @return bool - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException - */ - public function apply(Request $request, ParamConverter $configuration) - { - $id = (int)$request->get(self::PARAMETER_OBJECT_STATE_ID); - $objectState = $this->objectStateService->loadObjectState($id); - - if (!$objectState) { - throw new NotFoundHttpException("Object state $id not found."); - } - - $request->attributes->set($configuration->getName(), $objectState); - - return true; - } - - /** - * @param \Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter $configuration - * - * @return bool - */ - public function supports(ParamConverter $configuration) - { - return ObjectState::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/PolicyDraftParamConverter.php b/src/bundle/ParamConverter/PolicyDraftParamConverter.php deleted file mode 100644 index 3145642648..0000000000 --- a/src/bundle/ParamConverter/PolicyDraftParamConverter.php +++ /dev/null @@ -1,79 +0,0 @@ -roleService = $roleService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - if (!$request->get(self::PARAMETER_ROLE_ID) || !$request->get(self::PARAMETER_POLICY_ID)) { - return false; - } - - $roleId = (int)$request->get(self::PARAMETER_ROLE_ID); - - $roleDraft = $this->roleService->loadRoleDraftByRoleId($roleId); - - if (!$roleDraft) { - throw new NotFoundHttpException("Role $roleId not found."); - } - - $policyId = (int)$request->get(self::PARAMETER_POLICY_ID); - - $policyDraft = null; - foreach ($roleDraft->getPolicies() as $item) { - if ($item->originalId === $policyId) { - $policyDraft = $item; - break; - } - } - - if (!$policyDraft) { - throw new NotFoundHttpException("Policy draft $policyId not found."); - } - - $request->attributes->set($configuration->getName(), $policyDraft); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return PolicyDraft::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/PolicyParamConverter.php b/src/bundle/ParamConverter/PolicyParamConverter.php deleted file mode 100644 index a3bbc96958..0000000000 --- a/src/bundle/ParamConverter/PolicyParamConverter.php +++ /dev/null @@ -1,74 +0,0 @@ -roleService = $roleService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - if (!$request->get(self::PARAMETER_ROLE_ID) || !$request->get(self::PARAMETER_POLICY_ID)) { - return false; - } - - $roleId = (int)$request->get(self::PARAMETER_ROLE_ID); - - try { - $role = $this->roleService->loadRole($roleId); - } catch (NotFoundException $e) { - throw new NotFoundHttpException("Role $roleId not found."); - } - - $policyId = (int)$request->get(self::PARAMETER_POLICY_ID); - - foreach ($role->getPolicies() as $item) { - if ($item->id === $policyId) { - $request->attributes->set($configuration->getName(), $item); - - return true; - } - } - - throw new NotFoundHttpException("Policy $policyId not found."); - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return Policy::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/RoleAssignmentParamConverter.php b/src/bundle/ParamConverter/RoleAssignmentParamConverter.php deleted file mode 100644 index d0673b1669..0000000000 --- a/src/bundle/ParamConverter/RoleAssignmentParamConverter.php +++ /dev/null @@ -1,64 +0,0 @@ -roleService = $roleService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - if (!$request->get(self::PRAMETER_ROLE_ASSIGNMENT_ID)) { - return false; - } - - $roleAssigmentId = (int)$request->get(self::PRAMETER_ROLE_ASSIGNMENT_ID); - - try { - $roleAssigment = $this->roleService->loadRoleAssignment($roleAssigmentId); - } catch (NotFoundException $e) { - throw new NotFoundHttpException("Role assignment $roleAssigmentId not found."); - } - - $request->attributes->set($configuration->getName(), $roleAssigment); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return RoleAssignment::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/RoleParamConverter.php b/src/bundle/ParamConverter/RoleParamConverter.php deleted file mode 100644 index e5ec8f9f53..0000000000 --- a/src/bundle/ParamConverter/RoleParamConverter.php +++ /dev/null @@ -1,65 +0,0 @@ -roleService = $roleService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - if (!$request->get(self::PARAMETER_ROLE_ID)) { - return false; - } - - $id = (int)$request->get(self::PARAMETER_ROLE_ID); - - try { - $role = $this->roleService->loadRole($id); - } catch (NotFoundException $e) { - throw new NotFoundHttpException("Role $id not found."); - } - - $request->attributes->set($configuration->getName(), $role); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return Role::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/SectionParamConverter.php b/src/bundle/ParamConverter/SectionParamConverter.php deleted file mode 100644 index 45db845c3c..0000000000 --- a/src/bundle/ParamConverter/SectionParamConverter.php +++ /dev/null @@ -1,67 +0,0 @@ -sectionService = $sectionService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - if (!$request->get(self::PARAMETER_SECTION_ID)) { - return false; - } - - $id = (int)$request->get(self::PARAMETER_SECTION_ID); - - try { - $section = $this->sectionService->loadSection($id); - } catch (NotFoundException $e) { - throw new NotFoundHttpException("Section $id not found."); - } - - $request->attributes->set($configuration->getName(), $section); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return Section::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/TranslationLanguageParamConverter.php b/src/bundle/ParamConverter/TranslationLanguageParamConverter.php deleted file mode 100644 index b4f5b407b3..0000000000 --- a/src/bundle/ParamConverter/TranslationLanguageParamConverter.php +++ /dev/null @@ -1,76 +0,0 @@ -languageService = $languageService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - if ($request->get(self::PARAMETER_LANGUAGE_CODE_TO) && 'language' === $configuration->getName()) { - $languageCode = $request->get(self::PARAMETER_LANGUAGE_CODE_TO); - } elseif ($request->get(self::PARAMETER_LANGUAGE_CODE_FROM) && 'baseLanguage' === $configuration->getName()) { - $languageCode = $request->get(self::PARAMETER_LANGUAGE_CODE_FROM); - } else { - return false; - } - - $request->attributes->set($configuration->getName(), $this->getLanguage($languageCode)); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return Language::class === $configuration->getClass(); - } - - /** - * @param string $languageCode - * - * @return \Ibexa\Contracts\Core\Repository\Values\Content\Language - */ - private function getLanguage(string $languageCode): Language - { - try { - $language = $this->languageService->loadLanguage($languageCode); - } catch (NotFoundException $e) { - throw new NotFoundHttpException("Language $languageCode not found."); - } - - return $language; - } -} diff --git a/src/bundle/ParamConverter/URLWildcardParamConverter.php b/src/bundle/ParamConverter/URLWildcardParamConverter.php deleted file mode 100644 index 6bc48f13cc..0000000000 --- a/src/bundle/ParamConverter/URLWildcardParamConverter.php +++ /dev/null @@ -1,63 +0,0 @@ -urlWildcardService = $urlWildcardService; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration): bool - { - if (empty($request->get(self::PARAMETER_URL_WILDCARD_ID))) { - return false; - } - - $id = (int) $request->get(self::PARAMETER_URL_WILDCARD_ID); - - try { - $urlWildcard = $this->urlWildcardService->load($id); - } catch (NotFoundException $e) { - throw new NotFoundHttpException("URLWildcard {$id} not found."); - } - - $request->attributes->set($configuration->getName(), $urlWildcard); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration): bool - { - return URLWildcard::class === $configuration->getClass(); - } -} diff --git a/src/bundle/ParamConverter/VersionInfoParamConverter.php b/src/bundle/ParamConverter/VersionInfoParamConverter.php deleted file mode 100644 index a1415fb272..0000000000 --- a/src/bundle/ParamConverter/VersionInfoParamConverter.php +++ /dev/null @@ -1,65 +0,0 @@ -contentService = $contentService; - } - - /** - * {@inheritdoc} - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException - */ - public function apply(Request $request, ParamConverter $configuration): bool - { - if (!$request->get(self::PARAMETER_VERSION_NO) || !$request->get(self::PARAMETER_CONTENT_ID)) { - return false; - } - - $versionNo = (int)$request->get(self::PARAMETER_VERSION_NO); - $contentId = (int)$request->get(self::PARAMETER_CONTENT_ID); - - $contentInfo = $this->contentService->loadContentInfo($contentId); - $versionInfo = $this->contentService->loadVersionInfo($contentInfo, $versionNo); - - $request->attributes->set($configuration->getName(), $versionInfo); - - return true; - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration): bool - { - return VersionInfo::class === $configuration->getClass(); - } -} diff --git a/src/bundle/Resources/config/services.yaml b/src/bundle/Resources/config/services.yaml index f6c8b94b25..3b4e07f8c2 100644 --- a/src/bundle/Resources/config/services.yaml +++ b/src/bundle/Resources/config/services.yaml @@ -50,16 +50,11 @@ services: tags: - name: controller.service_arguments - Ibexa\Bundle\AdminUi\ParamConverter\: - resource: "../../ParamConverter/*" - public: true + Ibexa\Bundle\AdminUi\ValueResolver\: + resource: "../../ValueResolver/*" tags: - - { name: 'request.param_converter' } - - Ibexa\Bundle\AdminUi\ParamConverter\ContentTypeParamConverter: - public: true - tags: - - { name: 'request.param_converter' } + - name: controller.argument_value_resolver + priority: 150 Ibexa\AdminUi\UI\Dataset\DatasetFactory: lazy: true diff --git a/src/bundle/ValueResolver/AbstractValueResolver.php b/src/bundle/ValueResolver/AbstractValueResolver.php new file mode 100644 index 0000000000..28ff959577 --- /dev/null +++ b/src/bundle/ValueResolver/AbstractValueResolver.php @@ -0,0 +1,98 @@ + + */ + final public function resolve(Request $request, ArgumentMetadata $argument): iterable + { + if (!$this->supports($argument)) { + return []; + } + + $key = $this->getKey($request); + if (!$this->validateKey($key)) { + return []; + } + + yield $this->load($key); + } + + protected function supports(ArgumentMetadata $argument): bool + { + $argumentType = $argument->getType(); + if ($argumentType === null) { + return false; + } + + return is_a($argumentType, $this->getClass(), true); + } + + /** + * @phpstan-return array + */ + protected function getKey(Request $request): array + { + $key = []; + foreach ($this->getRequestAttributes() as $name) { + if (!$request->attributes->has($name)) { + continue; + } + + $key[$name] = $request->attributes->get($name); + } + + return $key; + } + + /** + * @phpstan-param array $key + */ + protected function validateKey(array $key): bool + { + foreach ($this->getRequestAttributes() as $name) { + if (!isset($key[$name])) { + return false; + } + + if (!is_string($key[$name])) { + return false; + } + } + + return true; + } + + /** + * @phpstan-return string[] + */ + abstract protected function getRequestAttributes(): array; + + /** + * @phpstan-return class-string + */ + abstract protected function getClass(): string; + + /** + * @phpstan-param array $key + * + * @phpstan-return TValue + */ + abstract protected function load(array $key): object; +} diff --git a/src/bundle/ValueResolver/ContentInfoValueResolver.php b/src/bundle/ValueResolver/ContentInfoValueResolver.php new file mode 100644 index 0000000000..5ac93ebef8 --- /dev/null +++ b/src/bundle/ValueResolver/ContentInfoValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class ContentInfoValueResolver extends AbstractValueResolver +{ + public const string ATTRIBUTE_CONTENT_INFO_ID = 'contentInfoId'; + + public function __construct( + private readonly ContentService $contentService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_CONTENT_INFO_ID]; + } + + protected function getClass(): string + { + return ContentInfo::class; + } + + protected function load(array $key): object + { + return $this->contentService->loadContentInfo( + (int)$key[self::ATTRIBUTE_CONTENT_INFO_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/ContentTypeDraftValueResolver.php b/src/bundle/ValueResolver/ContentTypeDraftValueResolver.php new file mode 100644 index 0000000000..07f3186de6 --- /dev/null +++ b/src/bundle/ValueResolver/ContentTypeDraftValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class ContentTypeDraftValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_CONTENT_TYPE_ID = 'contentTypeId'; + + public function __construct( + private readonly ContentTypeService $contentTypeService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_CONTENT_TYPE_ID]; + } + + protected function getClass(): string + { + return ContentTypeDraft::class; + } + + protected function load(array $key): object + { + return $this->contentTypeService->loadContentTypeDraft( + (int)$key[self::ATTRIBUTE_CONTENT_TYPE_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/ContentTypeFromIdValueResolver.php b/src/bundle/ValueResolver/ContentTypeFromIdValueResolver.php new file mode 100644 index 0000000000..630baecb9b --- /dev/null +++ b/src/bundle/ValueResolver/ContentTypeFromIdValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class ContentTypeFromIdValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_CONTENT_TYPE_ID = 'contentTypeId'; + + public function __construct( + private readonly ContentTypeService $contentTypeService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_CONTENT_TYPE_ID]; + } + + protected function getClass(): string + { + return ContentType::class; + } + + protected function load(array $key): object + { + return $this->contentTypeService->loadContentType( + (int)$key[self::ATTRIBUTE_CONTENT_TYPE_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/ContentTypeFromIdentifierValueResolver.php b/src/bundle/ValueResolver/ContentTypeFromIdentifierValueResolver.php new file mode 100644 index 0000000000..cd29842783 --- /dev/null +++ b/src/bundle/ValueResolver/ContentTypeFromIdentifierValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class ContentTypeFromIdentifierValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_CONTENT_TYPE_IDENTIFIER = 'contentTypeIdentifier'; + + public function __construct( + private readonly ContentTypeService $contentTypeService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_CONTENT_TYPE_IDENTIFIER]; + } + + protected function getClass(): string + { + return ContentType::class; + } + + protected function load(array $key): object + { + return $this->contentTypeService->loadContentTypeByIdentifier( + $key[self::ATTRIBUTE_CONTENT_TYPE_IDENTIFIER] + ); + } +} diff --git a/src/bundle/ValueResolver/ContentTypeGroupValueResolver.php b/src/bundle/ValueResolver/ContentTypeGroupValueResolver.php new file mode 100644 index 0000000000..e941a7a449 --- /dev/null +++ b/src/bundle/ValueResolver/ContentTypeGroupValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class ContentTypeGroupValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_CONTENT_TYPE_GROUP_ID = 'contentTypeGroupId'; + + public function __construct( + private readonly ContentTypeService $contentTypeService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_CONTENT_TYPE_GROUP_ID]; + } + + protected function getClass(): string + { + return ContentTypeGroup::class; + } + + protected function load(array $key): object + { + return $this->contentTypeService->loadContentTypeGroup( + (int) $key[self::ATTRIBUTE_CONTENT_TYPE_GROUP_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/ContentValueResolver.php b/src/bundle/ValueResolver/ContentValueResolver.php new file mode 100644 index 0000000000..27c3a6e609 --- /dev/null +++ b/src/bundle/ValueResolver/ContentValueResolver.php @@ -0,0 +1,66 @@ + + */ +final class ContentValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_CONTENT_ID = 'contentId'; + private const string ATTRIBUTE_VERSION_NO = 'versionNo'; + private const string ATTRIBUTE_LANGUAGE_CODE = 'languageCode'; + + public function __construct( + private readonly ContentService $contentService + ) { + } + + protected function getRequestAttributes(): array + { + return [ + self::ATTRIBUTE_CONTENT_ID, + self::ATTRIBUTE_VERSION_NO, + self::ATTRIBUTE_LANGUAGE_CODE, + ]; + } + + protected function getClass(): string + { + return Content::class; + } + + protected function validateKey(array $key): bool + { + if ($key[self::ATTRIBUTE_CONTENT_ID] === null) { + return false; + } + + if (!is_array($key[self::ATTRIBUTE_LANGUAGE_CODE])) { + return false; + } + + return true; + } + + protected function load(array $key): object + { + $contentId = (int)$key[self::ATTRIBUTE_CONTENT_ID]; + $languages = $key[self::ATTRIBUTE_LANGUAGE_CODE]; + $versionNo = $key[self::ATTRIBUTE_VERSION_NO]; + if ($versionNo !== null) { + $versionNo = (int)$versionNo; + } + + return $this->contentService->loadContent($contentId, $languages, $versionNo); + } +} diff --git a/src/bundle/ValueResolver/LanguageFromCodeValueResolver.php b/src/bundle/ValueResolver/LanguageFromCodeValueResolver.php new file mode 100644 index 0000000000..83274baa2a --- /dev/null +++ b/src/bundle/ValueResolver/LanguageFromCodeValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class LanguageFromCodeValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_LANGUAGE_CORE = 'languageCode'; + + public function __construct( + private readonly LanguageService $languageService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_LANGUAGE_CORE]; + } + + protected function getClass(): string + { + return Language::class; + } + + protected function load(array $key): object + { + return $this->languageService->loadLanguage( + $key[self::ATTRIBUTE_LANGUAGE_CORE] + ); + } +} diff --git a/src/bundle/ValueResolver/LanguageFromIdValueResolver.php b/src/bundle/ValueResolver/LanguageFromIdValueResolver.php new file mode 100644 index 0000000000..df1128e203 --- /dev/null +++ b/src/bundle/ValueResolver/LanguageFromIdValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class LanguageFromIdValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_LANGUAGE_ID = 'languageId'; + + public function __construct( + private readonly LanguageService $languageService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_LANGUAGE_ID]; + } + + protected function getClass(): string + { + return Language::class; + } + + protected function load(array $key): object + { + return $this->languageService->loadLanguageById( + (int) $key[self::ATTRIBUTE_LANGUAGE_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/ObjectStateGroupValueResolver.php b/src/bundle/ValueResolver/ObjectStateGroupValueResolver.php new file mode 100644 index 0000000000..192580caad --- /dev/null +++ b/src/bundle/ValueResolver/ObjectStateGroupValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class ObjectStateGroupValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_OBJECT_STATE_GROUP_ID = 'objectStateGroupId'; + + public function __construct( + private readonly ObjectStateService $objectStateService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_OBJECT_STATE_GROUP_ID]; + } + + protected function getClass(): string + { + return ObjectStateGroup::class; + } + + protected function load(array $key): object + { + return $this->objectStateService->loadObjectStateGroup( + (int)$key[self::ATTRIBUTE_OBJECT_STATE_GROUP_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/ObjectStateValueResolver.php b/src/bundle/ValueResolver/ObjectStateValueResolver.php new file mode 100644 index 0000000000..b68d126b95 --- /dev/null +++ b/src/bundle/ValueResolver/ObjectStateValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class ObjectStateValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_OBJECT_STATE_ID = 'objectStateId'; + + public function __construct( + private readonly ObjectStateService $objectStateService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_OBJECT_STATE_ID]; + } + + protected function getClass(): string + { + return ObjectState::class; + } + + protected function load(array $key): object + { + return $this->objectStateService->loadObjectState( + (int)$key[self::ATTRIBUTE_OBJECT_STATE_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/PolicyDraftValueResolver.php b/src/bundle/ValueResolver/PolicyDraftValueResolver.php new file mode 100644 index 0000000000..a5595063db --- /dev/null +++ b/src/bundle/ValueResolver/PolicyDraftValueResolver.php @@ -0,0 +1,56 @@ + + */ +final class PolicyDraftValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_ROLE_ID = 'roleId'; + private const string ATTRIBUTE_POLICY_ID = 'policyId'; + + public function __construct( + private readonly RoleService $roleService + ) { + } + + protected function getRequestAttributes(): array + { + return [ + self::ATTRIBUTE_ROLE_ID, + self::ATTRIBUTE_POLICY_ID, + ]; + } + + protected function getClass(): string + { + return PolicyDraft::class; + } + + protected function load(array $key): object + { + $roleId = (int)$key[self::ATTRIBUTE_ROLE_ID]; + $policyId = (int)$key[self::ATTRIBUTE_POLICY_ID]; + + $roleDraft = $this->roleService->loadRoleDraftByRoleId($roleId); + foreach ($roleDraft->getPolicies() as $policy) { + /** @var \Ibexa\Contracts\Core\Repository\Values\User\PolicyDraft $policy */ + if ($policy->originalId === $policyId) { + return $policy; + } + } + + throw new NotFoundHttpException("Policy draft $policyId not found."); + } +} diff --git a/src/bundle/ValueResolver/PolicyValueResolver.php b/src/bundle/ValueResolver/PolicyValueResolver.php new file mode 100644 index 0000000000..84f6f5539a --- /dev/null +++ b/src/bundle/ValueResolver/PolicyValueResolver.php @@ -0,0 +1,57 @@ + + */ +final class PolicyValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_ROLE_ID = 'roleId'; + private const string ATTRIBUTE_POLICY_ID = 'policyId'; + + public function __construct( + private readonly RoleService $roleService + ) { + } + + protected function getRequestAttributes(): array + { + return [ + self::ATTRIBUTE_ROLE_ID, + self::ATTRIBUTE_POLICY_ID, + ]; + } + + protected function getClass(): string + { + return Policy::class; + } + + protected function load(array $key): object + { + $roleId = (int)$key[self::ATTRIBUTE_ROLE_ID]; + $policyId = (int)$key[self::ATTRIBUTE_POLICY_ID]; + + $roleDraft = $this->roleService->loadRole($roleId); + foreach ($roleDraft->getPolicies() as $policy) { + /** @var \Ibexa\Contracts\Core\Repository\Values\User\PolicyDraft $policy */ + if ($policy->originalId === $policyId) { + return $policy; + } + } + + throw new NotFoundHttpException("Policy draft $policyId not found."); + } +} diff --git a/src/bundle/ValueResolver/RoleAssignmentValueResolver.php b/src/bundle/ValueResolver/RoleAssignmentValueResolver.php new file mode 100644 index 0000000000..a17f237be0 --- /dev/null +++ b/src/bundle/ValueResolver/RoleAssignmentValueResolver.php @@ -0,0 +1,44 @@ + + */ +final class RoleAssignmentValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_ROLE_ASSIGNMENT_ID = 'roleAssignmentId'; + + public function __construct( + private readonly RoleService $roleService + ) { + } + + protected function getRequestAttributes(): array + { + return [ + self::ATTRIBUTE_ROLE_ASSIGNMENT_ID, + ]; + } + + protected function getClass(): string + { + return RoleAssignment::class; + } + + protected function load(array $key): object + { + return $this->roleService->loadRoleAssignment( + (int)$key[self::ATTRIBUTE_ROLE_ASSIGNMENT_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/RoleValueResolver.php b/src/bundle/ValueResolver/RoleValueResolver.php new file mode 100644 index 0000000000..45e8d17160 --- /dev/null +++ b/src/bundle/ValueResolver/RoleValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class RoleValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_ROLE_ID = 'roleId'; + + public function __construct( + private readonly RoleService $roleService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_ROLE_ID]; + } + + protected function getClass(): string + { + return Role::class; + } + + protected function load(array $key): object + { + return $this->roleService->loadRole( + (int)$key[self::ATTRIBUTE_ROLE_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/SectionValueResolver.php b/src/bundle/ValueResolver/SectionValueResolver.php new file mode 100644 index 0000000000..f39aeb8a11 --- /dev/null +++ b/src/bundle/ValueResolver/SectionValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class SectionValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_SECTION_ID = 'sectionId'; + + public function __construct( + private readonly SectionService $sectionService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_SECTION_ID]; + } + + protected function getClass(): string + { + return Section::class; + } + + protected function load(array $key): object + { + return $this->sectionService->loadSection( + (int)$key[self::ATTRIBUTE_SECTION_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/SourceLanguageValueResolver.php b/src/bundle/ValueResolver/SourceLanguageValueResolver.php new file mode 100644 index 0000000000..e9e2aa5acd --- /dev/null +++ b/src/bundle/ValueResolver/SourceLanguageValueResolver.php @@ -0,0 +1,53 @@ + + */ +final class SourceLanguageValueResolver extends AbstractValueResolver +{ + private const string ARGUMENT_NAME = 'language'; + private const string ATTRIBUTE_LANGUAGE_CODE_FROM = 'fromLanguageCode'; + + public function __construct( + private readonly LanguageService $languageService + ) { + } + + protected function supports(ArgumentMetadata $argument): bool + { + if ($argument->getName() !== self::ARGUMENT_NAME) { + return false; + } + + return parent::supports($argument); + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_LANGUAGE_CODE_FROM]; + } + + protected function getClass(): string + { + return Language::class; + } + + protected function load(array $key): object + { + return $this->languageService->loadLanguage( + $key[self::ATTRIBUTE_LANGUAGE_CODE_FROM] + ); + } +} diff --git a/src/bundle/ValueResolver/TargetLanguageValueResolver.php b/src/bundle/ValueResolver/TargetLanguageValueResolver.php new file mode 100644 index 0000000000..5f3d37adbb --- /dev/null +++ b/src/bundle/ValueResolver/TargetLanguageValueResolver.php @@ -0,0 +1,53 @@ + + */ +final class TargetLanguageValueResolver extends AbstractValueResolver +{ + private const string ARGUMENT_NAME = 'language'; + private const string ATTRIBUTE_LANGUAGE_CODE_TO = 'toLanguageCode'; + + public function __construct( + private readonly LanguageService $languageService + ) { + } + + protected function supports(ArgumentMetadata $argument): bool + { + if ($argument->getName() !== self::ARGUMENT_NAME) { + return false; + } + + return parent::supports($argument); + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_LANGUAGE_CODE_TO]; + } + + protected function getClass(): string + { + return Language::class; + } + + protected function load(array $key): object + { + return $this->languageService->loadLanguage( + $key[self::ATTRIBUTE_LANGUAGE_CODE_TO] + ); + } +} diff --git a/src/bundle/ValueResolver/URLWildcardValueResolver.php b/src/bundle/ValueResolver/URLWildcardValueResolver.php new file mode 100644 index 0000000000..5e92b38bbb --- /dev/null +++ b/src/bundle/ValueResolver/URLWildcardValueResolver.php @@ -0,0 +1,42 @@ + + */ +final class URLWildcardValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_URL_WILDCARD_ID = 'urlWildcardId'; + + public function __construct( + private readonly URLWildcardService $urlWildcardService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_URL_WILDCARD_ID]; + } + + protected function getClass(): string + { + return URLWildcard::class; + } + + protected function load(array $key): object + { + return $this->urlWildcardService->load( + (int)$key[self::ATTRIBUTE_URL_WILDCARD_ID] + ); + } +} diff --git a/src/bundle/ValueResolver/VersionInfoValueResolver.php b/src/bundle/ValueResolver/VersionInfoValueResolver.php new file mode 100644 index 0000000000..b6aa5a0b3c --- /dev/null +++ b/src/bundle/ValueResolver/VersionInfoValueResolver.php @@ -0,0 +1,47 @@ + + */ +final class VersionInfoValueResolver extends AbstractValueResolver +{ + private const string ATTRIBUTE_VERSION_NO = 'versionNo'; + private const string ATTRIBUTE_CONTENT_ID = 'contentId'; + + public function __construct( + private readonly ContentService $contentService + ) { + } + + protected function getRequestAttributes(): array + { + return [self::ATTRIBUTE_VERSION_NO, self::ATTRIBUTE_CONTENT_ID]; + } + + protected function getClass(): string + { + return VersionInfo::class; + } + + protected function load(array $key): object + { + $contentId = (int)$key[self::ATTRIBUTE_CONTENT_ID]; + $versionNo = (int)$key[self::ATTRIBUTE_VERSION_NO]; + + $contentInfo = $this->contentService->loadContentInfo($contentId); + $versionInfo = $this->contentService->loadVersionInfo($contentInfo, $versionNo); + + return $versionInfo; + } +} diff --git a/tests/bundle/ParamConverter/AbstractParamConverterTest.php b/tests/bundle/ParamConverter/AbstractParamConverterTest.php deleted file mode 100644 index ad41daa19f..0000000000 --- a/tests/bundle/ParamConverter/AbstractParamConverterTest.php +++ /dev/null @@ -1,23 +0,0 @@ -createConfiguration(static::SUPPORTED_CLASS); - - self::assertTrue($this->converter->supports($config)); - } -} diff --git a/tests/bundle/ParamConverter/ContentParamConverterTest.php b/tests/bundle/ParamConverter/ContentParamConverterTest.php deleted file mode 100644 index e76a07a383..0000000000 --- a/tests/bundle/ParamConverter/ContentParamConverterTest.php +++ /dev/null @@ -1,96 +0,0 @@ -contentServiceMock = $this->createMock(ContentService::class); - - $this->converter = new ContentParamConverter($this->contentServiceMock); - } - - public function testApply() - { - $contentId = 42; - $languageCode = ['language_code']; - $versionNo = 53; - $valueObject = $this->createMock(Content::class); - - $this->contentServiceMock - ->expects(self::once()) - ->method('loadContent') - ->with($contentId, $languageCode, $versionNo) - ->willReturn($valueObject); - - $requestAttributes = [ - ContentParamConverter::PARAMETER_CONTENT_ID => $contentId, - ContentParamConverter::PARAMETER_LANGUAGE_CODE => $languageCode, - ContentParamConverter::PARAMETER_VERSION_NO => $versionNo, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertTrue($this->converter->apply($request, $config)); - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - /** - * @dataProvider attributeProvider - * - * @param $contentId - * @param $languageCode - */ - public function testApplyWithWrongAttribute($contentId, $languageCode) - { - $versionNo = 53; - - $requestAttributes = [ - ContentParamConverter::PARAMETER_CONTENT_ID => $contentId, - ContentParamConverter::PARAMETER_LANGUAGE_CODE => $languageCode, - ContentParamConverter::PARAMETER_VERSION_NO => $versionNo, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - /** - * @return array - */ - public function attributeProvider(): array - { - return [ - 'empty_content_id' => [null, ['language_code']], - 'language_code_as_string' => [42, 'string'], - ]; - } -} diff --git a/tests/bundle/ParamConverter/ContentTypeDraftParamConverterTest.php b/tests/bundle/ParamConverter/ContentTypeDraftParamConverterTest.php deleted file mode 100644 index 4f1b389ccd..0000000000 --- a/tests/bundle/ParamConverter/ContentTypeDraftParamConverterTest.php +++ /dev/null @@ -1,81 +0,0 @@ -contentTypeServiceMock = $this->createMock(ContentTypeService::class); - - $this->converter = new ContentTypeDraftParamConverter($this->contentTypeServiceMock); - } - - /** - * @dataProvider dataProvider - * - * @param mixed $contentTypeId The content type identifier fetched from the request - * @param int $contentTypeIdToLoad The content type identifier used to load the content type draft - */ - public function testApply($contentTypeId, int $contentTypeIdToLoad) - { - $valueObject = $this->createMock(ContentTypeDraft::class); - - $this->contentTypeServiceMock - ->expects(self::once()) - ->method('loadContentTypeDraft') - ->with($contentTypeIdToLoad) - ->willReturn($valueObject); - - $requestAttributes = [ - ContentTypeDraftParamConverter::PARAMETER_CONTENT_TYPE_ID => $contentTypeId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertTrue($this->converter->apply($request, $config)); - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyWithWrongAttribute() - { - $requestAttributes = [ - ContentTypeDraftParamConverter::PARAMETER_CONTENT_TYPE_ID => null, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - public function dataProvider(): array - { - return [ - 'integer' => [42, 42], - 'number_as_string' => ['42', 42], - 'string' => ['42k', 42], - ]; - } -} diff --git a/tests/bundle/ParamConverter/ContentTypeGroupParamConverterTest.php b/tests/bundle/ParamConverter/ContentTypeGroupParamConverterTest.php deleted file mode 100644 index a6c4e21c0e..0000000000 --- a/tests/bundle/ParamConverter/ContentTypeGroupParamConverterTest.php +++ /dev/null @@ -1,110 +0,0 @@ -serviceMock = $this->createMock(ContentTypeService::class); - - $this->converter = new ContentTypeGroupParamConverter($this->serviceMock); - } - - /** - * @dataProvider dataProvider - * - * @param mixed $contentTypeGroupId The identifier fetched from the request - * @param int $contentTypeGroupIdToLoad The identifier used to load the content type Group - */ - public function testApply($contentTypeGroupId, int $contentTypeGroupIdToLoad) - { - $valueObject = $this->createMock(ContentTypeGroup::class); - - $this->serviceMock - ->expects(self::once()) - ->method('loadContentTypeGroup') - ->with($contentTypeGroupIdToLoad) - ->willReturn($valueObject); - - $requestAttributes = [ - ContentTypeGroupParamConverter::PARAMETER_CONTENT_TYPE_GROUP_ID => $contentTypeGroupId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertTrue($this->converter->apply($request, $config)); - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyWithWrongAttribute() - { - $requestAttributes = [ - ContentTypeGroupParamConverter::PARAMETER_CONTENT_TYPE_GROUP_ID => null, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyWhenNotFound() - { - $contentTypeGroupId = 42; - - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage( - sprintf('Content type group %s not found.', $contentTypeGroupId) - ); - - $this->serviceMock - ->expects(self::once()) - ->method('loadContentTypeGroup') - ->with($contentTypeGroupId) - ->willThrowException( - $this->createMock(NotFoundException::class) - ); - - $requestAttributes = [ - ContentTypeGroupParamConverter::PARAMETER_CONTENT_TYPE_GROUP_ID => $contentTypeGroupId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - } - - public function dataProvider(): array - { - return [ - 'integer' => [42, 42], - 'number_as_string' => ['42', 42], - 'string' => ['42k', 42], - ]; - } -} diff --git a/tests/bundle/ParamConverter/ContentTypeParamConverterTest.php b/tests/bundle/ParamConverter/ContentTypeParamConverterTest.php deleted file mode 100644 index 1aff74f548..0000000000 --- a/tests/bundle/ParamConverter/ContentTypeParamConverterTest.php +++ /dev/null @@ -1,167 +0,0 @@ -serviceMock = $this->createMock(ContentTypeService::class); - - $userLanguagePreferenceProvider = $this->createMock(UserLanguagePreferenceProviderInterface::class); - $this->converter = new ContentTypeParamConverter($this->serviceMock, $userLanguagePreferenceProvider); - } - - /** - * @dataProvider dataProvider - * - * @param mixed $contentTypeId The content type identifier fetched from the request - * @param int $contentTypeIdToLoad The content type identifier used to load the content type draft - */ - public function testApplyId($contentTypeId, int $contentTypeIdLoad) - { - $valueObject = $this->createMock(ContentType::class); - - $this->serviceMock - ->expects(self::once()) - ->method('loadContentType') - ->with($contentTypeIdLoad) - ->willReturn($valueObject); - - $requestAttributes = [ - ContentTypeParamConverter::PARAMETER_CONTENT_TYPE_ID => $contentTypeId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertTrue($this->converter->apply($request, $config)); - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyIdWithWrongValue() - { - $requestAttributes = [ - ContentTypeParamConverter::PARAMETER_CONTENT_TYPE_ID => null, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyIdWhenNotFound() - { - $contentTypeId = 42; - - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage(sprintf('Content type %s not found.', $contentTypeId)); - - $this->serviceMock - ->expects(self::once()) - ->method('loadContentType') - ->with($contentTypeId) - ->willThrowException($this->createMock(NotFoundException::class)); - - $requestAttributes = [ - ContentTypeParamConverter::PARAMETER_CONTENT_TYPE_ID => $contentTypeId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - } - - public function testApplyIdentifier() - { - $contentTypeIdentifier = 'test_identifier'; - $valueObject = $this->createMock(ContentType::class); - - $this->serviceMock - ->expects(self::once()) - ->method('loadContentTypeByIdentifier') - ->with($contentTypeIdentifier) - ->willReturn($valueObject); - - $requestAttributes = [ - ContentTypeParamConverter::PARAMETER_CONTENT_TYPE_IDENTIFIER => $contentTypeIdentifier, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyIdentifierWithWrongValue() - { - $requestAttributes = [ - ContentTypeParamConverter::PARAMETER_CONTENT_TYPE_IDENTIFIER => null, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyIdentifierWhenNotFound() - { - $contentTypeIdentifier = 'test_identifier'; - - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage(sprintf('Content type %s not found.', $contentTypeIdentifier)); - - $this->serviceMock - ->expects(self::once()) - ->method('loadContentTypeByIdentifier') - ->with($contentTypeIdentifier) - ->willThrowException($this->createMock(NotFoundException::class)); - - $requestAttributes = [ - ContentTypeParamConverter::PARAMETER_CONTENT_TYPE_IDENTIFIER => $contentTypeIdentifier, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - } - - public function dataProvider(): array - { - return [ - 'integer' => [42, 42], - 'number_as_string' => ['42', 42], - 'string' => ['42k', 42], - ]; - } -} diff --git a/tests/bundle/ParamConverter/LanguageParamConverterTest.php b/tests/bundle/ParamConverter/LanguageParamConverterTest.php deleted file mode 100644 index 8cffccc87e..0000000000 --- a/tests/bundle/ParamConverter/LanguageParamConverterTest.php +++ /dev/null @@ -1,196 +0,0 @@ -serviceMock = $this->createMock(LanguageService::class); - $this->converter = new LanguageParamConverter($this->serviceMock); - } - - /** - * @covers \Ibexa\Bundle\AdminUi\ParamConverter\LanguageParamConverter::apply - * - * @dataProvider dataProvider - * - * @param mixed $languageId The language identifier fetched from the request - * @param int $languageIdToLoad The language identifier used to load the language - */ - public function testApplyForLanguageId($languageId, int $languageIdToLoad) - { - $valueObject = $this->createMock(Language::class); - - $this->serviceMock - ->expects(self::once()) - ->method('loadLanguageById') - ->with($languageIdToLoad) - ->willReturn($valueObject); - - $requestAttributes = [ - LanguageParamConverter::PARAMETER_LANGUAGE_ID => $languageId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertTrue($this->converter->apply($request, $config)); - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - /** - * @covers \Ibexa\Bundle\AdminUi\ParamConverter\LanguageParamConverter::apply - */ - public function testApplyForLanguageCode() - { - $languageCode = 'eng-GB'; - $valueObject = $this->createMock(Language::class); - - $this->serviceMock - ->expects(self::once()) - ->method('loadLanguage') - ->with($languageCode) - ->willReturn($valueObject); - - $request = new Request([], [], [ - LanguageParamConverter::PARAMETER_LANGUAGE_CODE => $languageCode, - ]); - - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - /** - * @covers \Ibexa\Bundle\AdminUi\ParamConverter\LanguageParamConverter::apply - * - * @dataProvider dataProviderForApplyWithWrongAttribute - */ - public function testApplyWithWrongAttribute(array $attributes) - { - $request = new Request([], [], $attributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - /** - * @covers \Ibexa\Bundle\AdminUi\ParamConverter\LanguageParamConverter::apply - */ - public function testApplyWithNonExistingLanguageId() - { - $languageId = 42; - - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage(sprintf('Language %s not found.', $languageId)); - - $this->serviceMock - ->expects(self::once()) - ->method('loadLanguageById') - ->with($languageId) - ->willThrowException($this->createMock(NotFoundException::class)); - - $requestAttributes = [ - LanguageParamConverter::PARAMETER_LANGUAGE_ID => $languageId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - } - - /** - * @covers \Ibexa\Bundle\AdminUi\ParamConverter\LanguageParamConverter::apply - */ - public function testApplyWithNonExistingLanguageCode() - { - $languageCode = 'eng-Gb'; - - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage(sprintf('Language %s not found.', $languageCode)); - - $this->serviceMock - ->expects(self::once()) - ->method('loadLanguage') - ->with($languageCode) - ->willThrowException($this->createMock(NotFoundException::class)); - - $requestAttributes = [ - LanguageParamConverter::PARAMETER_LANGUAGE_CODE => $languageCode, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - } - - /** - * @covers \Ibexa\Bundle\AdminUi\ParamConverter\LanguageParamConverter::supports - * - * @dataProvider dataProviderForSupport - */ - public function testSupport(string $class, bool $expected) - { - self::assertEquals($expected, $this->converter->supports($this->createConfiguration($class))); - } - - public function dataProviderForSupport(): array - { - return [ - [self::SUPPORTED_CLASS, true], - [stdClass::class, false], - ]; - } - - public function dataProviderForApplyWithWrongAttribute(): array - { - return [ - [ - [LanguageParamConverter::PARAMETER_LANGUAGE_ID => null], - ], - [ - [LanguageParamConverter::PARAMETER_LANGUAGE_CODE => null], - ], - [ - [], - ], - ]; - } - - public function dataProvider(): array - { - return [ - 'integer' => [42, 42], - 'number_as_string' => ['42', 42], - 'string' => ['42k', 42], - ]; - } -} diff --git a/tests/bundle/ParamConverter/PolicyParamConverterTest.php b/tests/bundle/ParamConverter/PolicyParamConverterTest.php deleted file mode 100644 index 9a48eae247..0000000000 --- a/tests/bundle/ParamConverter/PolicyParamConverterTest.php +++ /dev/null @@ -1,166 +0,0 @@ -serviceMock = $this->createMock(RoleService::class); - - $this->converter = new PolicyParamConverter($this->serviceMock); - } - - /** - * @dataProvider dataProvider - * - * @param mixed $policyId The policy identifier fetched from the request - * @param mixed $roleId The role identifier fetched from the request - * @param int $roleIdToLoad The role identifier used to load the role - */ - public function testApply($policyId, $roleId, int $roleIdToLoad) - { - $matchingPolicyId = 53; - $valueObject = $this->createMock(Role::class); - $valueObject->expects(self::once()) - ->method('getPolicies') - ->willReturn([new UserPolicy(['id' => $matchingPolicyId]), new UserPolicy(['id' => 444])]); - - $this->serviceMock - ->expects(self::once()) - ->method('loadRole') - ->with($roleIdToLoad) - ->willReturn($valueObject); - - $requestAttributes = [ - PolicyParamConverter::PARAMETER_ROLE_ID => $roleId, - PolicyParamConverter::PARAMETER_POLICY_ID => $policyId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertTrue($this->converter->apply($request, $config)); - $policy = $request->attributes->get(self::PARAMETER_NAME); - self::assertInstanceOf(self::SUPPORTED_CLASS, $policy); - self::assertSame($matchingPolicyId, $policy->id); - } - - /** - * @dataProvider attributeProvider - * - * @param $roleId - * @param $policyId - */ - public function testApplyWithWrongAttribute($roleId, $policyId) - { - $requestAttributes = [ - PolicyParamConverter::PARAMETER_ROLE_ID => $roleId, - PolicyParamConverter::PARAMETER_POLICY_ID => $policyId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyWhenRoleNotFound() - { - $roleId = 42; - $policyId = 53; - - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage(sprintf('Role %s not found.', $roleId)); - - $this->serviceMock - ->expects(self::once()) - ->method('loadRole') - ->with($roleId) - ->willThrowException($this->createMock(NotFoundException::class)); - - $requestAttributes = [ - PolicyParamConverter::PARAMETER_ROLE_ID => $roleId, - PolicyParamConverter::PARAMETER_POLICY_ID => $policyId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - } - - public function testApplyWhenPolicyNotFound() - { - $roleId = 42; - $policyId = 53; - - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage(sprintf('Policy %s not found.', $policyId)); - - $valueObject = $this->createMock(Role::class); - $valueObject->expects(self::once()) - ->method('getPolicies') - ->willReturn([new UserPolicy(['id' => 123])]); - - $this->serviceMock - ->expects(self::once()) - ->method('loadRole') - ->with($roleId) - ->willReturn($valueObject); - - $requestAttributes = [ - PolicyParamConverter::PARAMETER_ROLE_ID => $roleId, - PolicyParamConverter::PARAMETER_POLICY_ID => $policyId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - } - - /** - * @return array - */ - public function attributeProvider(): array - { - return [ - 'empty_role_id' => [null, 53], - 'empty_policy_id' => [42, null], - ]; - } - - public function dataProvider(): array - { - return [ - 'integer' => [53, 42, 42], - 'number_as_string' => ['53', '42', 42], - 'string' => ['53k', '42k', 42], - ]; - } -} diff --git a/tests/bundle/ParamConverter/RoleAssignmentParamConverterTest.php b/tests/bundle/ParamConverter/RoleAssignmentParamConverterTest.php deleted file mode 100644 index 89e7ad7f7e..0000000000 --- a/tests/bundle/ParamConverter/RoleAssignmentParamConverterTest.php +++ /dev/null @@ -1,106 +0,0 @@ -serviceMock = $this->createMock(RoleService::class); - - $this->converter = new RoleAssignmentParamConverter($this->serviceMock); - } - - /** - * @dataProvider dataProvider - * - * @param mixed $roleAssignmentId The role assignment identifier fetched from the request - * @param int $roleAssignmentIdToLoad The role assignment identifier used to load the role assignment - */ - public function testApply($roleAssignmentId, int $roleAssignmentIdToLoad) - { - $valueObject = $this->createMock(RoleAssignment::class); - - $this->serviceMock - ->expects(self::once()) - ->method('loadRoleAssignment') - ->with($roleAssignmentIdToLoad) - ->willReturn($valueObject); - - $requestAttributes = [ - RoleAssignmentParamConverter::PRAMETER_ROLE_ASSIGNMENT_ID => $roleAssignmentId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertTrue($this->converter->apply($request, $config)); - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyWithWrongAttribute() - { - $requestAttributes = [ - RoleAssignmentParamConverter::PRAMETER_ROLE_ASSIGNMENT_ID => null, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyWhenNotFound() - { - $roleAssignmentId = 42; - - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage(sprintf('Role assignment %s not found.', $roleAssignmentId)); - - $this->serviceMock - ->expects(self::once()) - ->method('loadRoleAssignment') - ->with($roleAssignmentId) - ->willThrowException($this->createMock(NotFoundException::class)); - - $requestAttributes = [ - RoleAssignmentParamConverter::PRAMETER_ROLE_ASSIGNMENT_ID => $roleAssignmentId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - } - - public function dataProvider(): array - { - return [ - 'integer' => [42, 42], - 'number_as_string' => ['42', 42], - 'string' => ['42k', 42], - ]; - } -} diff --git a/tests/bundle/ParamConverter/RoleParamConverterTest.php b/tests/bundle/ParamConverter/RoleParamConverterTest.php deleted file mode 100644 index 9bd2258681..0000000000 --- a/tests/bundle/ParamConverter/RoleParamConverterTest.php +++ /dev/null @@ -1,106 +0,0 @@ -serviceMock = $this->createMock(RoleService::class); - - $this->converter = new RoleParamConverter($this->serviceMock); - } - - /** - * @dataProvider dataProvider - * - * @param mixed $roleId The role identifier fetched from the request - * @param int $roleIdToLoad The role identifier used to load the role - */ - public function testApply($roleId, int $roleIdToLoad) - { - $valueObject = $this->createMock(Role::class); - - $this->serviceMock - ->expects(self::once()) - ->method('loadRole') - ->with($roleIdToLoad) - ->willReturn($valueObject); - - $requestAttributes = [ - RoleParamConverter::PARAMETER_ROLE_ID => $roleId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertTrue($this->converter->apply($request, $config)); - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyWithWrongAttribute() - { - $requestAttributes = [ - RoleParamConverter::PARAMETER_ROLE_ID => null, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyWhenNotFound() - { - $roleId = 42; - - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage(sprintf('Role %s not found.', $roleId)); - - $this->serviceMock - ->expects(self::once()) - ->method('loadRole') - ->with($roleId) - ->willThrowException($this->createMock(NotFoundException::class)); - - $requestAttributes = [ - RoleParamConverter::PARAMETER_ROLE_ID => $roleId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - } - - public function dataProvider(): array - { - return [ - 'integer' => [42, 42], - 'number_as_string' => ['42', 42], - 'string' => ['42k', 42], - ]; - } -} diff --git a/tests/bundle/ParamConverter/SectionParamConverterTest.php b/tests/bundle/ParamConverter/SectionParamConverterTest.php deleted file mode 100644 index c004c396fa..0000000000 --- a/tests/bundle/ParamConverter/SectionParamConverterTest.php +++ /dev/null @@ -1,106 +0,0 @@ -serviceMock = $this->createMock(SectionService::class); - - $this->converter = new SectionParamConverter($this->serviceMock); - } - - /** - * @dataProvider dataProvider - * - * @param mixed $sectionId The section identifier fetched from the request - * @param int $sectionIdToLoad The section identifier used to load the section - */ - public function testApply($sectionId, int $sectionIdToLoad) - { - $valueObject = $this->createMock(Section::class); - - $this->serviceMock - ->expects(self::once()) - ->method('loadSection') - ->with($sectionIdToLoad) - ->willReturn($valueObject); - - $requestAttributes = [ - SectionParamConverter::PARAMETER_SECTION_ID => $sectionId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertTrue($this->converter->apply($request, $config)); - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyWithWrongAttribute() - { - $requestAttributes = [ - SectionParamConverter::PARAMETER_SECTION_ID => null, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - public function testApplyWhenNotFound() - { - $sectionId = 42; - - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage(sprintf('Section %s not found.', $sectionId)); - - $this->serviceMock - ->expects(self::once()) - ->method('loadSection') - ->with($sectionId) - ->willThrowException($this->createMock(NotFoundException::class)); - - $requestAttributes = [ - SectionParamConverter::PARAMETER_SECTION_ID => $sectionId, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - $this->converter->apply($request, $config); - } - - public function dataProvider(): array - { - return [ - 'integer' => [42, 42], - 'number_as_string' => ['42', 42], - 'string' => ['42k', 42], - ]; - } -} diff --git a/tests/bundle/ParamConverter/VersionInfoParamConverterTest.php b/tests/bundle/ParamConverter/VersionInfoParamConverterTest.php deleted file mode 100644 index 5512d4ddf3..0000000000 --- a/tests/bundle/ParamConverter/VersionInfoParamConverterTest.php +++ /dev/null @@ -1,113 +0,0 @@ -serviceMock = $this->createMock(ContentService::class); - - $this->converter = new VersionInfoParamConverter($this->serviceMock); - } - - /** - * @dataProvider dataProvider - * - * @param mixed $versionNo - * @param int $versionNoToload - * @param mixed $contentId - * @param int $contentIdToLoad - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException - */ - public function testApply($versionNo, int $versionNoToload, $contentId, int $contentIdToLoad) - { - $valueObject = $this->createMock(ContentInfo::class); - $versionInfo = $this->createMock(VersionInfo::class); - - $this->serviceMock - ->expects(self::once()) - ->method('loadContentInfo') - ->with($contentIdToLoad) - ->willReturn($valueObject); - - $this->serviceMock - ->expects(self::once()) - ->method('loadVersionInfo') - ->with($valueObject, $versionNoToload) - ->willReturn($versionInfo); - - $requestAttributes = [ - VersionInfoParamConverter::PARAMETER_CONTENT_ID => $contentId, - VersionInfoParamConverter::PARAMETER_VERSION_NO => $versionNo, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertTrue($this->converter->apply($request, $config)); - self::assertInstanceOf(self::SUPPORTED_CLASS, $request->attributes->get(self::PARAMETER_NAME)); - } - - /** - * @dataProvider attributeProvider - * - * @param $contentId - * @param $versionNo - */ - public function testApplyWithWrongAttribute($contentId, $versionNo) - { - $requestAttributes = [ - VersionInfoParamConverter::PARAMETER_CONTENT_ID => $contentId, - VersionInfoParamConverter::PARAMETER_VERSION_NO => $versionNo, - ]; - - $request = new Request([], [], $requestAttributes); - $config = $this->createConfiguration(self::SUPPORTED_CLASS, self::PARAMETER_NAME); - - self::assertFalse($this->converter->apply($request, $config)); - self::assertNull($request->attributes->get(self::PARAMETER_NAME)); - } - - /** - * @return array - */ - public function attributeProvider(): array - { - return [ - 'empty_content_id' => [null, 53], - 'empty_version_no' => [42, null], - ]; - } - - public function dataProvider(): array - { - return [ - 'integer' => [53, 53, 42, 42], - 'number_as_string' => ['53', 53, '42', 42], - 'string' => ['53k', 53, '42k', 42], - ]; - } -}