aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/tests/ManagerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/workflowengine/tests/ManagerTest.php')
-rw-r--r--apps/workflowengine/tests/ManagerTest.php85
1 files changed, 36 insertions, 49 deletions
diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php
index 890eba99dac..56e45936b82 100644
--- a/apps/workflowengine/tests/ManagerTest.php
+++ b/apps/workflowengine/tests/ManagerTest.php
@@ -1,28 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\WorkflowEngine\Tests;
@@ -45,6 +25,7 @@ use OCP\IServerContainer;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\Server;
use OCP\SystemTag\ISystemTagManager;
use OCP\WorkflowEngine\Events\RegisterEntitiesEvent;
use OCP\WorkflowEngine\ICheck;
@@ -79,13 +60,13 @@ class ManagerTest extends TestCase {
protected $dispatcher;
/** @var MockObject|IConfig */
protected $config;
- /** @var MockObject|ICacheFactory */
+ /** @var MockObject|ICacheFactory */
protected $cacheFactory;
protected function setUp(): void {
parent::setUp();
- $this->db = \OC::$server->getDatabaseConnection();
+ $this->db = Server::get(IDBConnection::class);
$this->container = $this->createMock(IServerContainer::class);
/** @var IL10N|MockObject $l */
$this->l = $this->createMock(IL10N::class);
@@ -101,7 +82,7 @@ class ManagerTest extends TestCase {
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->manager = new Manager(
- \OC::$server->getDatabaseConnection(),
+ Server::get(IDBConnection::class),
$this->container,
$this->l,
$this->logger,
@@ -144,7 +125,7 @@ class ManagerTest extends TestCase {
}
}
- public function testChecks() {
+ public function testChecks(): void {
$check1 = $this->invokePrivate($this->manager, 'addCheck', ['Test', 'equal', 1]);
$check2 = $this->invokePrivate($this->manager, 'addCheck', ['Test', '!equal', 2]);
@@ -165,7 +146,7 @@ class ManagerTest extends TestCase {
$this->assertArrayHasKey($check2, $data);
}
- public function testScope() {
+ public function testScope(): void {
$adminScope = $this->buildScope();
$userScope = $this->buildScope('jackie');
$entity = File::class;
@@ -199,7 +180,7 @@ class ManagerTest extends TestCase {
$this->assertTrue($this->invokePrivate($this->manager, 'canModify', [$opId3, $userScope]));
}
- public function testGetAllOperations() {
+ public function testGetAllOperations(): void {
$adminScope = $this->buildScope();
$userScope = $this->buildScope('jackie');
$entity = File::class;
@@ -270,7 +251,7 @@ class ManagerTest extends TestCase {
$this->assertSame(2, count($userOps['OCA\WFE\TestUserOp']));
}
- public function testGetOperations() {
+ public function testGetOperations(): void {
$adminScope = $this->buildScope();
$userScope = $this->buildScope('jackie');
$entity = File::class;
@@ -330,17 +311,17 @@ class ManagerTest extends TestCase {
$userOps = $this->manager->getOperations('OCA\WFE\TestOp', $userScope);
$this->assertSame(1, count($adminOps));
- array_walk($adminOps, function ($op) {
+ array_walk($adminOps, function ($op): void {
$this->assertTrue($op['class'] === 'OCA\WFE\TestOp');
});
$this->assertSame(2, count($userOps));
- array_walk($userOps, function ($op) {
+ array_walk($userOps, function ($op): void {
$this->assertTrue($op['class'] === 'OCA\WFE\TestOp');
});
}
- public function testGetAllConfiguredEvents() {
+ public function testGetAllConfiguredEvents(): void {
$adminScope = $this->buildScope();
$userScope = $this->buildScope('jackie');
$entity = File::class;
@@ -374,7 +355,7 @@ class ManagerTest extends TestCase {
$this->assertEquals($allOperationsCached, $allOperations);
}
- public function testUpdateOperation() {
+ public function testUpdateOperation(): void {
$adminScope = $this->buildScope();
$userScope = $this->buildScope('jackie');
$entity = File::class;
@@ -383,16 +364,22 @@ class ManagerTest extends TestCase {
$cache->expects($this->exactly(4))
->method('remove')
->with('events');
- $this->cacheFactory->method('createDistributed')->willReturn($cache);
+ $this->cacheFactory->method('createDistributed')
+ ->willReturn($cache);
+ $expectedCalls = [
+ [IManager::SCOPE_ADMIN],
+ [IManager::SCOPE_USER],
+ ];
+ $i = 0;
$operationMock = $this->createMock(IOperation::class);
$operationMock->expects($this->any())
->method('isAvailableForScope')
- ->withConsecutive(
- [IManager::SCOPE_ADMIN],
- [IManager::SCOPE_USER]
- )
- ->willReturn(true);
+ ->willReturnCallback(function () use (&$expectedCalls, &$i): bool {
+ $this->assertEquals($expectedCalls[$i], func_get_args());
+ $i++;
+ return true;
+ });
$this->container->expects($this->any())
->method('query')
@@ -411,7 +398,7 @@ class ManagerTest extends TestCase {
$this->createMock(UserMountCache::class),
$this->createMock(IMountManager::class),
])
- ->setMethodsExcept(['getEvents'])
+ ->onlyMethods($this->filterClassMethods(File::class, ['getEvents']))
->getMock();
}
return $this->createMock(ICheck::class);
@@ -455,7 +442,7 @@ class ManagerTest extends TestCase {
}
}
- public function testDeleteOperation() {
+ public function testDeleteOperation(): void {
$adminScope = $this->buildScope();
$userScope = $this->buildScope('jackie');
$entity = File::class;
@@ -505,7 +492,7 @@ class ManagerTest extends TestCase {
}
}
- public function testGetEntitiesListBuildInOnly() {
+ public function testGetEntitiesListBuildInOnly(): void {
$fileEntityMock = $this->createMock(File::class);
$this->container->expects($this->once())
@@ -519,7 +506,7 @@ class ManagerTest extends TestCase {
$this->assertInstanceOf(IEntity::class, $entities[0]);
}
- public function testGetEntitiesList() {
+ public function testGetEntitiesList(): void {
$fileEntityMock = $this->createMock(File::class);
$this->container->expects($this->once())
@@ -532,7 +519,7 @@ class ManagerTest extends TestCase {
$this->dispatcher->expects($this->once())
->method('dispatchTyped')
- ->willReturnCallback(function (RegisterEntitiesEvent $e) use ($extraEntity) {
+ ->willReturnCallback(function (RegisterEntitiesEvent $e) use ($extraEntity): void {
$this->manager->registerEntity($extraEntity);
});
@@ -553,7 +540,7 @@ class ManagerTest extends TestCase {
$this->assertSame(1, $entityTypeCounts[1]);
}
- public function testValidateOperationOK() {
+ public function testValidateOperationOK(): void {
$check = [
'class' => ICheck::class,
'operator' => 'is',
@@ -613,7 +600,7 @@ class ManagerTest extends TestCase {
$this->manager->validateOperation(IOperation::class, 'test', [$check], 'operationData', $scopeMock, IEntity::class, ['MyEvent']);
}
- public function testValidateOperationCheckInputLengthError() {
+ public function testValidateOperationCheckInputLengthError(): void {
$check = [
'class' => ICheck::class,
'operator' => 'is',
@@ -677,7 +664,7 @@ class ManagerTest extends TestCase {
}
}
- public function testValidateOperationDataLengthError() {
+ public function testValidateOperationDataLengthError(): void {
$check = [
'class' => ICheck::class,
'operator' => 'is',
@@ -741,7 +728,7 @@ class ManagerTest extends TestCase {
}
}
- public function testValidateOperationScopeNotAvailable() {
+ public function testValidateOperationScopeNotAvailable(): void {
$check = [
'class' => ICheck::class,
'operator' => 'is',