Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/workflowengine/lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
47 changes: 47 additions & 0 deletions apps/workflowengine/tests/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down