|
|
|
@ -25,6 +25,7 @@ use OC\L10N\L10N;
|
|
|
|
|
use OCA\WorkflowEngine\Entity\File;
|
|
|
|
|
use OCA\WorkflowEngine\Helper\ScopeContext;
|
|
|
|
|
use OCA\WorkflowEngine\Manager;
|
|
|
|
|
use OCP\AppFramework\QueryException;
|
|
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
|
|
|
|
use OCP\Files\IRootFolder;
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
@ -194,6 +195,32 @@ class ManagerTest extends TestCase {
|
|
|
|
|
$userScope = $this->buildScope('jackie');
|
|
|
|
|
$entity = File::class;
|
|
|
|
|
|
|
|
|
|
$adminOperation = $this->createMock(IOperation::class);
|
|
|
|
|
$adminOperation->expects($this->any())
|
|
|
|
|
->method('isAvailableForScope')
|
|
|
|
|
->willReturnMap([
|
|
|
|
|
[IManager::SCOPE_ADMIN, true],
|
|
|
|
|
[IManager::SCOPE_USER, false],
|
|
|
|
|
]);
|
|
|
|
|
$userOperation = $this->createMock(IOperation::class);
|
|
|
|
|
$userOperation->expects($this->any())
|
|
|
|
|
->method('isAvailableForScope')
|
|
|
|
|
->willReturnMap([
|
|
|
|
|
[IManager::SCOPE_ADMIN, false],
|
|
|
|
|
[IManager::SCOPE_USER, true],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->container->expects($this->any())
|
|
|
|
|
->method('query')
|
|
|
|
|
->willReturnCallback(function ($className) use ($adminOperation, $userOperation) {
|
|
|
|
|
switch ($className) {
|
|
|
|
|
case 'OCA\WFE\TestAdminOp':
|
|
|
|
|
return $adminOperation;
|
|
|
|
|
case 'OCA\WFE\TestUserOp':
|
|
|
|
|
return $userOperation;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$opId1 = $this->invokePrivate(
|
|
|
|
|
$this->manager,
|
|
|
|
|
'insertOperation',
|
|
|
|
@ -214,6 +241,13 @@ class ManagerTest extends TestCase {
|
|
|
|
|
);
|
|
|
|
|
$this->invokePrivate($this->manager, 'addScope', [$opId3, $userScope]);
|
|
|
|
|
|
|
|
|
|
$opId4 = $this->invokePrivate(
|
|
|
|
|
$this->manager,
|
|
|
|
|
'insertOperation',
|
|
|
|
|
['OCA\WFE\TestAdminOp', 'Test04', [41, 10, 4], 'NoBar', $entity, []]
|
|
|
|
|
);
|
|
|
|
|
$this->invokePrivate($this->manager, 'addScope', [$opId4, $userScope]);
|
|
|
|
|
|
|
|
|
|
$adminOps = $this->manager->getAllOperations($adminScope);
|
|
|
|
|
$userOps = $this->manager->getAllOperations($userScope);
|
|
|
|
|
|
|
|
|
@ -264,6 +298,25 @@ class ManagerTest extends TestCase {
|
|
|
|
|
);
|
|
|
|
|
$this->invokePrivate($this->manager, 'addScope', [$opId5, $userScope]);
|
|
|
|
|
|
|
|
|
|
$operation = $this->createMock(IOperation::class);
|
|
|
|
|
$operation->expects($this->any())
|
|
|
|
|
->method('isAvailableForScope')
|
|
|
|
|
->willReturnMap([
|
|
|
|
|
[IManager::SCOPE_ADMIN, true],
|
|
|
|
|
[IManager::SCOPE_USER, true],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->container->expects($this->any())
|
|
|
|
|
->method('query')
|
|
|
|
|
->willReturnCallback(function ($className) use ($operation) {
|
|
|
|
|
switch ($className) {
|
|
|
|
|
case 'OCA\WFE\TestOp':
|
|
|
|
|
return $operation;
|
|
|
|
|
case 'OCA\WFE\OtherTestOp':
|
|
|
|
|
throw new QueryException();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$adminOps = $this->manager->getOperations('OCA\WFE\TestOp', $adminScope);
|
|
|
|
|
$userOps = $this->manager->getOperations('OCA\WFE\TestOp', $userScope);
|
|
|
|
|
|
|
|
|
@ -283,11 +336,20 @@ class ManagerTest extends TestCase {
|
|
|
|
|
$userScope = $this->buildScope('jackie');
|
|
|
|
|
$entity = File::class;
|
|
|
|
|
|
|
|
|
|
$operationMock = $this->createMock(IOperation::class);
|
|
|
|
|
$operationMock->expects($this->any())
|
|
|
|
|
->method('isAvailableForScope')
|
|
|
|
|
->withConsecutive(
|
|
|
|
|
[IManager::SCOPE_ADMIN],
|
|
|
|
|
[IManager::SCOPE_USER]
|
|
|
|
|
)
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$this->container->expects($this->any())
|
|
|
|
|
->method('query')
|
|
|
|
|
->willReturnCallback(function ($class) {
|
|
|
|
|
->willReturnCallback(function ($class) use ($operationMock) {
|
|
|
|
|
if (substr($class, -2) === 'Op') {
|
|
|
|
|
return $this->createMock(IOperation::class);
|
|
|
|
|
return $operationMock;
|
|
|
|
|
} elseif ($class === File::class) {
|
|
|
|
|
return $this->getMockBuilder(File::class)
|
|
|
|
|
->setConstructorArgs([
|
|
|
|
@ -448,6 +510,16 @@ class ManagerTest extends TestCase {
|
|
|
|
|
$entityMock = $this->createMock(IEntity::class);
|
|
|
|
|
$eventEntityMock = $this->createMock(IEntityEvent::class);
|
|
|
|
|
$checkMock = $this->createMock(ICheck::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);
|
|
|
|
|
|
|
|
|
|
$operationMock->expects($this->once())
|
|
|
|
|
->method('validateOperation')
|
|
|
|
@ -484,7 +556,7 @@ class ManagerTest extends TestCase {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$this->manager->validateOperation(IOperation::class, 'test', [$check], 'operationData', IEntity::class, ['MyEvent']);
|
|
|
|
|
$this->manager->validateOperation(IOperation::class, 'test', [$check], 'operationData', $scopeMock, IEntity::class, ['MyEvent']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testValidateOperationCheckInputLengthError() {
|
|
|
|
@ -498,6 +570,16 @@ class ManagerTest extends TestCase {
|
|
|
|
|
$entityMock = $this->createMock(IEntity::class);
|
|
|
|
|
$eventEntityMock = $this->createMock(IEntityEvent::class);
|
|
|
|
|
$checkMock = $this->createMock(ICheck::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);
|
|
|
|
|
|
|
|
|
|
$operationMock->expects($this->once())
|
|
|
|
|
->method('validateOperation')
|
|
|
|
@ -535,7 +617,7 @@ class ManagerTest extends TestCase {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->manager->validateOperation(IOperation::class, 'test', [$check], 'operationData', IEntity::class, ['MyEvent']);
|
|
|
|
|
$this->manager->validateOperation(IOperation::class, 'test', [$check], 'operationData', $scopeMock, IEntity::class, ['MyEvent']);
|
|
|
|
|
} catch (\UnexpectedValueException $e) {
|
|
|
|
|
$this->assertSame('The provided check value is too long', $e->getMessage());
|
|
|
|
|
}
|
|
|
|
@ -553,6 +635,16 @@ class ManagerTest extends TestCase {
|
|
|
|
|
$entityMock = $this->createMock(IEntity::class);
|
|
|
|
|
$eventEntityMock = $this->createMock(IEntityEvent::class);
|
|
|
|
|
$checkMock = $this->createMock(ICheck::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);
|
|
|
|
|
|
|
|
|
|
$operationMock->expects($this->never())
|
|
|
|
|
->method('validateOperation');
|
|
|
|
@ -589,9 +681,73 @@ class ManagerTest extends TestCase {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->manager->validateOperation(IOperation::class, 'test', [$check], $operationData, IEntity::class, ['MyEvent']);
|
|
|
|
|
$this->manager->validateOperation(IOperation::class, 'test', [$check], $operationData, $scopeMock, IEntity::class, ['MyEvent']);
|
|
|
|
|
} catch (\UnexpectedValueException $e) {
|
|
|
|
|
$this->assertSame('The provided operation data is too long', $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testValidateOperationScopeNotAvailable() {
|
|
|
|
|
$check = [
|
|
|
|
|
'class' => ICheck::class,
|
|
|
|
|
'operator' => 'is',
|
|
|
|
|
'value' => 'barfoo',
|
|
|
|
|
];
|
|
|
|
|
$operationData = str_pad('', IManager::MAX_OPERATION_VALUE_BYTES + 1, 'FooBar');
|
|
|
|
|
|
|
|
|
|
$operationMock = $this->createMock(IOperation::class);
|
|
|
|
|
$entityMock = $this->createMock(IEntity::class);
|
|
|
|
|
$eventEntityMock = $this->createMock(IEntityEvent::class);
|
|
|
|
|
$checkMock = $this->createMock(ICheck::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(false);
|
|
|
|
|
|
|
|
|
|
$operationMock->expects($this->never())
|
|
|
|
|
->method('validateOperation');
|
|
|
|
|
|
|
|
|
|
$entityMock->expects($this->any())
|
|
|
|
|
->method('getEvents')
|
|
|
|
|
->willReturn([$eventEntityMock]);
|
|
|
|
|
|
|
|
|
|
$eventEntityMock->expects($this->any())
|
|
|
|
|
->method('getEventName')
|
|
|
|
|
->willReturn('MyEvent');
|
|
|
|
|
|
|
|
|
|
$checkMock->expects($this->any())
|
|
|
|
|
->method('supportedEntities')
|
|
|
|
|
->willReturn([IEntity::class]);
|
|
|
|
|
$checkMock->expects($this->never())
|
|
|
|
|
->method('validateCheck');
|
|
|
|
|
|
|
|
|
|
$this->container->expects($this->any())
|
|
|
|
|
->method('query')
|
|
|
|
|
->willReturnCallback(function ($className) use ($operationMock, $entityMock, $eventEntityMock, $checkMock) {
|
|
|
|
|
switch ($className) {
|
|
|
|
|
case IOperation::class:
|
|
|
|
|
return $operationMock;
|
|
|
|
|
case IEntity::class:
|
|
|
|
|
return $entityMock;
|
|
|
|
|
case IEntityEvent::class:
|
|
|
|
|
return $eventEntityMock;
|
|
|
|
|
case ICheck::class:
|
|
|
|
|
return $checkMock;
|
|
|
|
|
default:
|
|
|
|
|
return $this->createMock($className);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->manager->validateOperation(IOperation::class, 'test', [$check], $operationData, $scopeMock, IEntity::class, ['MyEvent']);
|
|
|
|
|
} catch (\UnexpectedValueException $e) {
|
|
|
|
|
$this->assertSame('Operation OCP\WorkflowEngine\IOperation is invalid', $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|