diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php index 184712ef0d08a..e11cdc758c49a 100644 --- a/apps/workflowengine/lib/Manager.php +++ b/apps/workflowengine/lib/Manager.php @@ -693,20 +693,20 @@ public function validateOperation(string $class, string $name, array $checks, st $checkClass = $check['class']; $reflection = new \ReflectionClass($checkClass); if ($checkClass !== ICheck::class && !in_array(ICheck::class, $reflection->getInterfaceNames(), true)) { - throw new \UnexpectedValueException($this->l->t('Check %s is invalid', [$class])); + throw new \UnexpectedValueException($this->l->t('Check %s is invalid', [$checkClass])); } try { /** @var ICheck $instance */ $instance = $this->container->get($checkClass); } catch (ContainerExceptionInterface) { - throw new \UnexpectedValueException($this->l->t('Check %s does not exist', [$class])); + throw new \UnexpectedValueException($this->l->t('Check %s does not exist', [$checkClass])); } if (!empty($instance->supportedEntities()) && !in_array($entity, $instance->supportedEntities(), true) ) { - throw new \UnexpectedValueException($this->l->t('Check %s is not allowed with this entity', [$class])); + throw new \UnexpectedValueException($this->l->t('Check %s is not allowed with this entity', [$checkClass])); } $instance->validateCheck($check['operator'], $check['value']); diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php index c06b702764f4a..2d1ee4157ca7a 100644 --- a/apps/workflowengine/tests/ManagerTest.php +++ b/apps/workflowengine/tests/ManagerTest.php @@ -687,6 +687,53 @@ public function testValidateOperationCheckInputLengthError(): void { } } + public function testValidateOperationInvalidCheckClassError(): void { + $check = [ + 'id' => 1, + 'class' => \stdClass::class, + 'operator' => 'is', + 'value' => 'foo', + 'hash' => 'abc', + ]; + + $operationMock = $this->createMock(IOperation::class); + $entityMock = $this->createMock(IEntity::class); + $eventEntityMock = $this->createMock(IEntityEvent::class); + $scopeMock = $this->createMock(ScopeContext::class); + + $scopeMock->expects($this->any()) + ->method('getScope') + ->willReturn(IManager::SCOPE_ADMIN); + + $operationMock->expects($this->once()) + ->method('isAvailableForScope') + ->with(IManager::SCOPE_ADMIN) + ->willReturn(true); + + $entityMock->expects($this->any()) + ->method('getEvents') + ->willReturn([$eventEntityMock]); + + $eventEntityMock->expects($this->any()) + ->method('getEventName') + ->willReturn('MyEvent'); + + $this->container->expects($this->any()) + ->method('get') + ->willReturnCallback(function ($className) use ($operationMock, $entityMock, $eventEntityMock) { + return match ($className) { + IOperation::class => $operationMock, + IEntity::class => $entityMock, + IEntityEvent::class => $eventEntityMock, + default => $this->createMock($className), + }; + }); + + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Check ' . \stdClass::class . ' is invalid'); + $this->manager->validateOperation(IOperation::class, 'test', [$check], 'operationData', $scopeMock, IEntity::class, ['MyEvent']); + } + public function testValidateOperationDataLengthError(): void { $check = [ 'id' => 1,