diff --git a/src/Oro/Bundle/ApiBundle/Tests/Functional/HateoasMetadataTrait.php b/src/Oro/Bundle/ApiBundle/Tests/Functional/HateoasMetadataTrait.php index d49d6737064..c988a0a2758 100644 --- a/src/Oro/Bundle/ApiBundle/Tests/Functional/HateoasMetadataTrait.php +++ b/src/Oro/Bundle/ApiBundle/Tests/Functional/HateoasMetadataTrait.php @@ -77,6 +77,9 @@ private function assertHateoasLinksForAssociations(array $metadata, string $enti if (null === $subresource) { continue; } + if ($subresource->isExcludedAction(ApiAction::GET_SUBRESOURCE)) { + continue; + } self::assertArrayHasKey( 'relationship_links', $association, diff --git a/src/Oro/Bundle/WorkflowBundle/Resources/config/validator.yml b/src/Oro/Bundle/WorkflowBundle/Resources/config/validator.yml index bf1dfc7a914..ab47aeaeddb 100644 --- a/src/Oro/Bundle/WorkflowBundle/Resources/config/validator.yml +++ b/src/Oro/Bundle/WorkflowBundle/Resources/config/validator.yml @@ -3,6 +3,7 @@ services: class: Oro\Bundle\WorkflowBundle\Validator\Constraints\TransitionIsAllowedValidator arguments: - '@oro_workflow.registry' + - '@translator' tags: - { name: validator.constraint_validator } diff --git a/src/Oro/Bundle/WorkflowBundle/Tests/Unit/Validator/Constraints/TransitionIsAllowedValidatorTest.php b/src/Oro/Bundle/WorkflowBundle/Tests/Unit/Validator/Constraints/TransitionIsAllowedValidatorTest.php index a95fec277e1..63d14476ff2 100644 --- a/src/Oro/Bundle/WorkflowBundle/Tests/Unit/Validator/Constraints/TransitionIsAllowedValidatorTest.php +++ b/src/Oro/Bundle/WorkflowBundle/Tests/Unit/Validator/Constraints/TransitionIsAllowedValidatorTest.php @@ -13,22 +13,25 @@ use Oro\Bundle\WorkflowBundle\Validator\Constraints\TransitionIsAllowedValidator; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; +use Symfony\Contracts\Translation\TranslatorInterface; class TransitionIsAllowedValidatorTest extends ConstraintValidatorTestCase { private WorkflowRegistry|MockObject $workflowRegistry; + private TranslatorInterface|MockObject $translator; #[\Override] protected function setUp(): void { $this->workflowRegistry = $this->createMock(WorkflowRegistry::class); + $this->translator = $this->createMock(TranslatorInterface::class); parent::setUp(); } #[\Override] protected function createValidator(): TransitionIsAllowedValidator { - return new TransitionIsAllowedValidator($this->workflowRegistry); + return new TransitionIsAllowedValidator($this->workflowRegistry, $this->translator); } private function getWorkflowStep(string $name): WorkflowStep @@ -103,20 +106,26 @@ public function testValidateExceptions( ->method('getWorkflow') ->with($workflowName) ->willReturn($workflow); + $this->translator->expects(self::any()) + ->method('trans') + ->with($expectedMessage, $expectedMessageParameters) + ->willReturn($expectedMessage . ' TR'); $value = new WorkflowData(); $constraint = new TransitionIsAllowed($workflowItem, $transitionName); $this->validator->validate($value, $constraint); + $expectedTranslatedMessage = $expectedMessage === $constraint->someConditionsNotMetMessage + ? $expectedMessage + : $expectedMessage . ' TR'; + if ($expectedMessage !== $constraint->someConditionsNotMetMessage) { $this->buildViolation($constraint->someConditionsNotMetMessage) - ->buildNextViolation($expectedMessage) - ->setParameters($expectedMessageParameters) + ->buildNextViolation($expectedTranslatedMessage) ->assertRaised(); } else { - $this->buildViolation($expectedMessage) - ->setParameters($expectedMessageParameters) + $this->buildViolation($expectedTranslatedMessage) ->assertRaised(); } } @@ -152,7 +161,7 @@ public function validateExceptionsDataProvider(): array 'workflowException' => new InvalidTransitionException(), 'expectedMessage' => $constraint->someConditionsNotMetMessage, 'expectedMessageParameters' => [] - ], + ] ]; } } diff --git a/src/Oro/Bundle/WorkflowBundle/Validator/Constraints/TransitionIsAllowedValidator.php b/src/Oro/Bundle/WorkflowBundle/Validator/Constraints/TransitionIsAllowedValidator.php index 1265c706c28..dc2766ffb67 100644 --- a/src/Oro/Bundle/WorkflowBundle/Validator/Constraints/TransitionIsAllowedValidator.php +++ b/src/Oro/Bundle/WorkflowBundle/Validator/Constraints/TransitionIsAllowedValidator.php @@ -10,6 +10,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; +use Symfony\Contracts\Translation\TranslatorInterface; /** * Validate that workflow transition is allowed. @@ -17,7 +18,8 @@ class TransitionIsAllowedValidator extends ConstraintValidator { public function __construct( - private readonly WorkflowRegistry $workflowRegistry + private readonly WorkflowRegistry $workflowRegistry, + private readonly TranslatorInterface $translator ) { } @@ -51,7 +53,11 @@ public function validate($value, Constraint $constraint): void $this->context->addViolation($constraint->someConditionsNotMetMessage); if ($errors->count()) { foreach ($errors as $error) { - $this->context->addViolation($error['message'], $error['parameters'] ?? []); + // Translate errors here to use "messages" translation domains, because if we will add raw + // key to the constraint violation object it will be later translated with the "validation" domain + $this->context->addViolation( + $this->translator->trans($error['message'], $error['parameters'] ?? []) + ); } } }