Completed
Push — master ( 621b67...33412e )
by
unknown
29:54 queued 14s
created
apps/files_external/tests/Controller/GlobalStoragesControllerTest.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -19,41 +19,41 @@
 block discarded – undo
19 19
 use Psr\Log\LoggerInterface;
20 20
 
21 21
 class GlobalStoragesControllerTest extends StoragesControllerTestCase {
22
-	protected function setUp(): void {
23
-		parent::setUp();
24
-
25
-		$this->service = $this->createMock(GlobalStoragesService::class);
26
-
27
-		$this->service->method('getVisibilityType')
28
-			->willReturn(BackendService::VISIBILITY_ADMIN);
29
-
30
-		$this->controller = $this->createController(true);
31
-	}
32
-
33
-	private function createController(bool $allowCreateLocal = true): GlobalStoragesController {
34
-		$session = $this->createMock(IUserSession::class);
35
-		$session->method('getUser')
36
-			->willReturn(new User('test', null, $this->createMock(IEventDispatcher::class)));
37
-
38
-		$config = $this->createMock(IConfig::class);
39
-		$config->method('getSystemValue')
40
-			->with('files_external_allow_create_new_local', true)
41
-			->willReturn($allowCreateLocal);
42
-
43
-		return new GlobalStoragesController(
44
-			'files_external',
45
-			$this->createMock(IRequest::class),
46
-			$this->createMock(IL10N::class),
47
-			$this->service,
48
-			$this->createMock(LoggerInterface::class),
49
-			$session,
50
-			$this->createMock(IGroupManager::class),
51
-			$config
52
-		);
53
-	}
54
-
55
-	public function testAddLocalStorageWhenDisabled(): void {
56
-		$this->controller = $this->createController(false);
57
-		parent::testAddLocalStorageWhenDisabled();
58
-	}
22
+    protected function setUp(): void {
23
+        parent::setUp();
24
+
25
+        $this->service = $this->createMock(GlobalStoragesService::class);
26
+
27
+        $this->service->method('getVisibilityType')
28
+            ->willReturn(BackendService::VISIBILITY_ADMIN);
29
+
30
+        $this->controller = $this->createController(true);
31
+    }
32
+
33
+    private function createController(bool $allowCreateLocal = true): GlobalStoragesController {
34
+        $session = $this->createMock(IUserSession::class);
35
+        $session->method('getUser')
36
+            ->willReturn(new User('test', null, $this->createMock(IEventDispatcher::class)));
37
+
38
+        $config = $this->createMock(IConfig::class);
39
+        $config->method('getSystemValue')
40
+            ->with('files_external_allow_create_new_local', true)
41
+            ->willReturn($allowCreateLocal);
42
+
43
+        return new GlobalStoragesController(
44
+            'files_external',
45
+            $this->createMock(IRequest::class),
46
+            $this->createMock(IL10N::class),
47
+            $this->service,
48
+            $this->createMock(LoggerInterface::class),
49
+            $session,
50
+            $this->createMock(IGroupManager::class),
51
+            $config
52
+        );
53
+    }
54
+
55
+    public function testAddLocalStorageWhenDisabled(): void {
56
+        $this->controller = $this->createController(false);
57
+        parent::testAddLocalStorageWhenDisabled();
58
+    }
59 59
 }
Please login to merge, or discard this patch.
apps/files_external/tests/Controller/AjaxControllerTest.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -20,133 +20,133 @@
 block discarded – undo
20 20
 use Test\TestCase;
21 21
 
22 22
 class AjaxControllerTest extends TestCase {
23
-	private IRequest&MockObject $request;
24
-	private RSA&MockObject $rsa;
25
-	private GlobalAuth&MockObject $globalAuth;
26
-	private IUserSession&MockObject $userSession;
27
-	private IGroupManager&MockObject $groupManager;
28
-	private IL10N&MockObject $l10n;
29
-	private AjaxController $ajaxController;
30
-
31
-	protected function setUp(): void {
32
-		$this->request = $this->createMock(IRequest::class);
33
-		$this->rsa = $this->createMock(RSA::class);
34
-		$this->globalAuth = $this->createMock(GlobalAuth::class);
35
-		$this->userSession = $this->createMock(IUserSession::class);
36
-		$this->groupManager = $this->createMock(IGroupManager::class);
37
-		$this->l10n = $this->createMock(IL10N::class);
38
-
39
-		$this->ajaxController = new AjaxController(
40
-			'files_external',
41
-			$this->request,
42
-			$this->rsa,
43
-			$this->globalAuth,
44
-			$this->userSession,
45
-			$this->groupManager,
46
-			$this->l10n,
47
-		);
48
-
49
-		$this->l10n->expects($this->any())
50
-			->method('t')
51
-			->willReturnCallback(function ($string, $args) {
52
-				if (!is_array($args)) {
53
-					$args = [$args];
54
-				}
55
-				return vsprintf($string, $args);
56
-			});
57
-
58
-		parent::setUp();
59
-	}
60
-
61
-	public function testGetSshKeys(): void {
62
-		$this->rsa
63
-			->expects($this->once())
64
-			->method('createKey')
65
-			->willReturn([
66
-				'privatekey' => 'MyPrivateKey',
67
-				'publickey' => 'MyPublicKey',
68
-			]);
69
-
70
-		$expected = new JSONResponse(
71
-			[
72
-				'data' => [
73
-					'private_key' => 'MyPrivateKey',
74
-					'public_key' => 'MyPublicKey',
75
-				],
76
-				'status' => 'success',
77
-			]
78
-		);
79
-		$this->assertEquals($expected, $this->ajaxController->getSshKeys());
80
-	}
81
-
82
-	public function testSaveGlobalCredentialsAsAdminForAnotherUser(): void {
83
-		$user = $this->createMock(IUser::class);
84
-		$user
85
-			->expects($this->once())
86
-			->method('getUID')
87
-			->willReturn('MyAdminUid');
88
-		$this->userSession
89
-			->expects($this->once())
90
-			->method('getUser')
91
-			->willReturn($user);
92
-		$this->globalAuth
93
-			->expects($this->never())
94
-			->method('saveAuth');
95
-
96
-		$response = $this->ajaxController->saveGlobalCredentials('UidOfTestUser', 'test', 'password');
97
-		$this->assertSame($response->getStatus(), 403);
98
-		$this->assertSame('Permission denied', $response->getData()['message']);
99
-	}
100
-
101
-	public function testSaveGlobalCredentialsAsAdminForSelf(): void {
102
-		$user = $this->createMock(IUser::class);
103
-		$user
104
-			->expects($this->once())
105
-			->method('getUID')
106
-			->willReturn('MyAdminUid');
107
-		$this->userSession
108
-			->expects($this->once())
109
-			->method('getUser')
110
-			->willReturn($user);
111
-		$this->globalAuth
112
-			->expects($this->once())
113
-			->method('saveAuth')
114
-			->with('MyAdminUid', 'test', 'password');
115
-
116
-		$response = $this->ajaxController->saveGlobalCredentials('MyAdminUid', 'test', 'password');
117
-		$this->assertSame($response->getStatus(), 200);
118
-	}
119
-
120
-	public function testSaveGlobalCredentialsAsNormalUserForSelf(): void {
121
-		$user = $this->createMock(IUser::class);
122
-		$user
123
-			->method('getUID')
124
-			->willReturn('MyUserUid');
125
-		$this->userSession
126
-			->method('getUser')
127
-			->willReturn($user);
128
-		$this->globalAuth
129
-			->method('saveAuth')
130
-			->with('MyUserUid', 'test', 'password');
131
-
132
-		$response = $this->ajaxController->saveGlobalCredentials('MyUserUid', 'test', 'password');
133
-		$this->assertSame($response->getStatus(), 200);
134
-	}
135
-
136
-	public function testSaveGlobalCredentialsAsNormalUserForAnotherUser(): void {
137
-		$user = $this->createMock(IUser::class);
138
-		$user
139
-			->method('getUID')
140
-			->willReturn('MyUserUid');
141
-		$this->userSession
142
-			->method('getUser')
143
-			->willReturn($user);
144
-		$this->globalAuth
145
-			->expects($this->never())
146
-			->method('saveAuth');
147
-
148
-		$response = $this->ajaxController->saveGlobalCredentials('AnotherUserUid', 'test', 'password');
149
-		$this->assertSame($response->getStatus(), 403);
150
-		$this->assertSame('Permission denied', $response->getData()['message']);
151
-	}
23
+    private IRequest&MockObject $request;
24
+    private RSA&MockObject $rsa;
25
+    private GlobalAuth&MockObject $globalAuth;
26
+    private IUserSession&MockObject $userSession;
27
+    private IGroupManager&MockObject $groupManager;
28
+    private IL10N&MockObject $l10n;
29
+    private AjaxController $ajaxController;
30
+
31
+    protected function setUp(): void {
32
+        $this->request = $this->createMock(IRequest::class);
33
+        $this->rsa = $this->createMock(RSA::class);
34
+        $this->globalAuth = $this->createMock(GlobalAuth::class);
35
+        $this->userSession = $this->createMock(IUserSession::class);
36
+        $this->groupManager = $this->createMock(IGroupManager::class);
37
+        $this->l10n = $this->createMock(IL10N::class);
38
+
39
+        $this->ajaxController = new AjaxController(
40
+            'files_external',
41
+            $this->request,
42
+            $this->rsa,
43
+            $this->globalAuth,
44
+            $this->userSession,
45
+            $this->groupManager,
46
+            $this->l10n,
47
+        );
48
+
49
+        $this->l10n->expects($this->any())
50
+            ->method('t')
51
+            ->willReturnCallback(function ($string, $args) {
52
+                if (!is_array($args)) {
53
+                    $args = [$args];
54
+                }
55
+                return vsprintf($string, $args);
56
+            });
57
+
58
+        parent::setUp();
59
+    }
60
+
61
+    public function testGetSshKeys(): void {
62
+        $this->rsa
63
+            ->expects($this->once())
64
+            ->method('createKey')
65
+            ->willReturn([
66
+                'privatekey' => 'MyPrivateKey',
67
+                'publickey' => 'MyPublicKey',
68
+            ]);
69
+
70
+        $expected = new JSONResponse(
71
+            [
72
+                'data' => [
73
+                    'private_key' => 'MyPrivateKey',
74
+                    'public_key' => 'MyPublicKey',
75
+                ],
76
+                'status' => 'success',
77
+            ]
78
+        );
79
+        $this->assertEquals($expected, $this->ajaxController->getSshKeys());
80
+    }
81
+
82
+    public function testSaveGlobalCredentialsAsAdminForAnotherUser(): void {
83
+        $user = $this->createMock(IUser::class);
84
+        $user
85
+            ->expects($this->once())
86
+            ->method('getUID')
87
+            ->willReturn('MyAdminUid');
88
+        $this->userSession
89
+            ->expects($this->once())
90
+            ->method('getUser')
91
+            ->willReturn($user);
92
+        $this->globalAuth
93
+            ->expects($this->never())
94
+            ->method('saveAuth');
95
+
96
+        $response = $this->ajaxController->saveGlobalCredentials('UidOfTestUser', 'test', 'password');
97
+        $this->assertSame($response->getStatus(), 403);
98
+        $this->assertSame('Permission denied', $response->getData()['message']);
99
+    }
100
+
101
+    public function testSaveGlobalCredentialsAsAdminForSelf(): void {
102
+        $user = $this->createMock(IUser::class);
103
+        $user
104
+            ->expects($this->once())
105
+            ->method('getUID')
106
+            ->willReturn('MyAdminUid');
107
+        $this->userSession
108
+            ->expects($this->once())
109
+            ->method('getUser')
110
+            ->willReturn($user);
111
+        $this->globalAuth
112
+            ->expects($this->once())
113
+            ->method('saveAuth')
114
+            ->with('MyAdminUid', 'test', 'password');
115
+
116
+        $response = $this->ajaxController->saveGlobalCredentials('MyAdminUid', 'test', 'password');
117
+        $this->assertSame($response->getStatus(), 200);
118
+    }
119
+
120
+    public function testSaveGlobalCredentialsAsNormalUserForSelf(): void {
121
+        $user = $this->createMock(IUser::class);
122
+        $user
123
+            ->method('getUID')
124
+            ->willReturn('MyUserUid');
125
+        $this->userSession
126
+            ->method('getUser')
127
+            ->willReturn($user);
128
+        $this->globalAuth
129
+            ->method('saveAuth')
130
+            ->with('MyUserUid', 'test', 'password');
131
+
132
+        $response = $this->ajaxController->saveGlobalCredentials('MyUserUid', 'test', 'password');
133
+        $this->assertSame($response->getStatus(), 200);
134
+    }
135
+
136
+    public function testSaveGlobalCredentialsAsNormalUserForAnotherUser(): void {
137
+        $user = $this->createMock(IUser::class);
138
+        $user
139
+            ->method('getUID')
140
+            ->willReturn('MyUserUid');
141
+        $this->userSession
142
+            ->method('getUser')
143
+            ->willReturn($user);
144
+        $this->globalAuth
145
+            ->expects($this->never())
146
+            ->method('saveAuth');
147
+
148
+        $response = $this->ajaxController->saveGlobalCredentials('AnotherUserUid', 'test', 'password');
149
+        $this->assertSame($response->getStatus(), 403);
150
+        $this->assertSame('Permission denied', $response->getData()['message']);
151
+    }
152 152
 }
Please login to merge, or discard this patch.
apps/files_external/tests/Settings/AdminTest.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -18,77 +18,77 @@
 block discarded – undo
18 18
 use Test\TestCase;
19 19
 
20 20
 class AdminTest extends TestCase {
21
-	private IManager&MockObject $encryptionManager;
22
-	private GlobalStoragesService&MockObject $globalStoragesService;
23
-	private BackendService&MockObject $backendService;
24
-	private GlobalAuth&MockObject $globalAuth;
25
-	private Admin $admin;
21
+    private IManager&MockObject $encryptionManager;
22
+    private GlobalStoragesService&MockObject $globalStoragesService;
23
+    private BackendService&MockObject $backendService;
24
+    private GlobalAuth&MockObject $globalAuth;
25
+    private Admin $admin;
26 26
 
27
-	protected function setUp(): void {
28
-		parent::setUp();
29
-		$this->encryptionManager = $this->createMock(IManager::class);
30
-		$this->globalStoragesService = $this->createMock(GlobalStoragesService::class);
31
-		$this->backendService = $this->createMock(BackendService::class);
32
-		$this->globalAuth = $this->createMock(GlobalAuth::class);
27
+    protected function setUp(): void {
28
+        parent::setUp();
29
+        $this->encryptionManager = $this->createMock(IManager::class);
30
+        $this->globalStoragesService = $this->createMock(GlobalStoragesService::class);
31
+        $this->backendService = $this->createMock(BackendService::class);
32
+        $this->globalAuth = $this->createMock(GlobalAuth::class);
33 33
 
34
-		$this->admin = new Admin(
35
-			$this->encryptionManager,
36
-			$this->globalStoragesService,
37
-			$this->backendService,
38
-			$this->globalAuth
39
-		);
40
-	}
34
+        $this->admin = new Admin(
35
+            $this->encryptionManager,
36
+            $this->globalStoragesService,
37
+            $this->backendService,
38
+            $this->globalAuth
39
+        );
40
+    }
41 41
 
42
-	public function testGetForm(): void {
43
-		$this->encryptionManager
44
-			->expects($this->once())
45
-			->method('isEnabled')
46
-			->willReturn(false);
47
-		$this->globalStoragesService
48
-			->expects($this->once())
49
-			->method('getStorages')
50
-			->willReturn(['a', 'b', 'c']);
51
-		$this->backendService
52
-			->expects($this->once())
53
-			->method('getAvailableBackends')
54
-			->willReturn(['d', 'e', 'f']);
55
-		$this->backendService
56
-			->expects($this->once())
57
-			->method('getAuthMechanisms')
58
-			->willReturn(['g', 'h', 'i']);
59
-		$this->backendService
60
-			->expects($this->once())
61
-			->method('isUserMountingAllowed')
62
-			->willReturn(true);
63
-		$this->backendService
64
-			->expects($this->exactly(2))
65
-			->method('getBackends')
66
-			->willReturn([]);
67
-		$this->globalAuth
68
-			->expects($this->once())
69
-			->method('getAuth')
70
-			->with('')
71
-			->willReturn('asdf:asdf');
72
-		$params = [
73
-			'encryptionEnabled' => false,
74
-			'visibilityType' => BackendService::VISIBILITY_ADMIN,
75
-			'storages' => ['a', 'b', 'c'],
76
-			'backends' => ['d', 'e', 'f'],
77
-			'authMechanisms' => ['g', 'h', 'i'],
78
-			'dependencies' => MountConfig::dependencyMessage($this->backendService->getBackends()),
79
-			'allowUserMounting' => true,
80
-			'globalCredentials' => 'asdf:asdf',
81
-			'globalCredentialsUid' => '',
82
-		];
83
-		$expected = new TemplateResponse('files_external', 'settings', $params, '');
84
-		$this->assertEquals($expected, $this->admin->getForm());
85
-	}
42
+    public function testGetForm(): void {
43
+        $this->encryptionManager
44
+            ->expects($this->once())
45
+            ->method('isEnabled')
46
+            ->willReturn(false);
47
+        $this->globalStoragesService
48
+            ->expects($this->once())
49
+            ->method('getStorages')
50
+            ->willReturn(['a', 'b', 'c']);
51
+        $this->backendService
52
+            ->expects($this->once())
53
+            ->method('getAvailableBackends')
54
+            ->willReturn(['d', 'e', 'f']);
55
+        $this->backendService
56
+            ->expects($this->once())
57
+            ->method('getAuthMechanisms')
58
+            ->willReturn(['g', 'h', 'i']);
59
+        $this->backendService
60
+            ->expects($this->once())
61
+            ->method('isUserMountingAllowed')
62
+            ->willReturn(true);
63
+        $this->backendService
64
+            ->expects($this->exactly(2))
65
+            ->method('getBackends')
66
+            ->willReturn([]);
67
+        $this->globalAuth
68
+            ->expects($this->once())
69
+            ->method('getAuth')
70
+            ->with('')
71
+            ->willReturn('asdf:asdf');
72
+        $params = [
73
+            'encryptionEnabled' => false,
74
+            'visibilityType' => BackendService::VISIBILITY_ADMIN,
75
+            'storages' => ['a', 'b', 'c'],
76
+            'backends' => ['d', 'e', 'f'],
77
+            'authMechanisms' => ['g', 'h', 'i'],
78
+            'dependencies' => MountConfig::dependencyMessage($this->backendService->getBackends()),
79
+            'allowUserMounting' => true,
80
+            'globalCredentials' => 'asdf:asdf',
81
+            'globalCredentialsUid' => '',
82
+        ];
83
+        $expected = new TemplateResponse('files_external', 'settings', $params, '');
84
+        $this->assertEquals($expected, $this->admin->getForm());
85
+    }
86 86
 
87
-	public function testGetSection(): void {
88
-		$this->assertSame('externalstorages', $this->admin->getSection());
89
-	}
87
+    public function testGetSection(): void {
88
+        $this->assertSame('externalstorages', $this->admin->getSection());
89
+    }
90 90
 
91
-	public function testGetPriority(): void {
92
-		$this->assertSame(40, $this->admin->getPriority());
93
-	}
91
+    public function testGetPriority(): void {
92
+        $this->assertSame(40, $this->admin->getPriority());
93
+    }
94 94
 }
Please login to merge, or discard this patch.
apps/files_external/tests/Settings/SectionTest.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -14,36 +14,36 @@
 block discarded – undo
14 14
 use Test\TestCase;
15 15
 
16 16
 class SectionTest extends TestCase {
17
-	private IL10N&MockObject $l;
18
-	private IURLGenerator&MockObject $urlGenerator;
19
-	private Section $section;
20
-
21
-	protected function setUp(): void {
22
-		parent::setUp();
23
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
24
-		$this->l = $this->createMock(IL10N::class);
25
-
26
-		$this->section = new Section(
27
-			$this->urlGenerator,
28
-			$this->l
29
-		);
30
-	}
31
-
32
-	public function testGetID(): void {
33
-		$this->assertSame('externalstorages', $this->section->getID());
34
-	}
35
-
36
-	public function testGetName(): void {
37
-		$this->l
38
-			->expects($this->once())
39
-			->method('t')
40
-			->with('External storage')
41
-			->willReturn('External storage');
42
-
43
-		$this->assertSame('External storage', $this->section->getName());
44
-	}
45
-
46
-	public function testGetPriority(): void {
47
-		$this->assertSame(10, $this->section->getPriority());
48
-	}
17
+    private IL10N&MockObject $l;
18
+    private IURLGenerator&MockObject $urlGenerator;
19
+    private Section $section;
20
+
21
+    protected function setUp(): void {
22
+        parent::setUp();
23
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
24
+        $this->l = $this->createMock(IL10N::class);
25
+
26
+        $this->section = new Section(
27
+            $this->urlGenerator,
28
+            $this->l
29
+        );
30
+    }
31
+
32
+    public function testGetID(): void {
33
+        $this->assertSame('externalstorages', $this->section->getID());
34
+    }
35
+
36
+    public function testGetName(): void {
37
+        $this->l
38
+            ->expects($this->once())
39
+            ->method('t')
40
+            ->with('External storage')
41
+            ->willReturn('External storage');
42
+
43
+        $this->assertSame('External storage', $this->section->getName());
44
+    }
45
+
46
+    public function testGetPriority(): void {
47
+        $this->assertSame(10, $this->section->getPriority());
48
+    }
49 49
 }
Please login to merge, or discard this patch.
apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php 1 patch
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -23,321 +23,321 @@
 block discarded – undo
23 23
  * @group DB
24 24
  */
25 25
 class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
26
-	use UserTrait;
27
-
28
-	protected IGroupManager&MockObject $groupManager;
29
-	protected StoragesService $globalStoragesService;
30
-	protected User $user;
31
-
32
-	public const USER_ID = 'test_user';
33
-	public const GROUP_ID = 'test_group';
34
-	public const GROUP_ID2 = 'test_group2';
35
-
36
-	protected function setUp(): void {
37
-		parent::setUp();
38
-
39
-		$this->globalStoragesService = $this->service;
40
-
41
-		$this->user = new User(self::USER_ID, null, Server::get(IEventDispatcher::class));
42
-		/** @var IUserSession&MockObject $userSession */
43
-		$userSession = $this->createMock(IUserSession::class);
44
-		$userSession
45
-			->expects($this->any())
46
-			->method('getUser')
47
-			->willReturn($this->user);
48
-
49
-		$this->groupManager = $this->createMock(IGroupManager::class);
50
-		$this->groupManager->method('isInGroup')
51
-			->willReturnCallback(function ($userId, $groupId) {
52
-				if ($userId === self::USER_ID) {
53
-					switch ($groupId) {
54
-						case self::GROUP_ID:
55
-						case self::GROUP_ID2:
56
-							return true;
57
-					}
58
-				}
59
-				return false;
60
-			});
61
-		$this->groupManager->method('getUserGroupIds')
62
-			->willReturnCallback(function (IUser $user) {
63
-				if ($user->getUID() === self::USER_ID) {
64
-					return [self::GROUP_ID, self::GROUP_ID2];
65
-				} else {
66
-					return [];
67
-				}
68
-			});
69
-
70
-		$this->service = new UserGlobalStoragesService(
71
-			$this->backendService,
72
-			$this->dbConfig,
73
-			$userSession,
74
-			$this->groupManager,
75
-			$this->mountCache,
76
-			$this->eventDispatcher,
77
-		);
78
-	}
79
-
80
-	public static function applicableStorageProvider(): array {
81
-		return [
82
-			[[], [], true],
83
-
84
-			// not applicable cases
85
-			[['user1'], [], false],
86
-			[[], ['group1'], false],
87
-			[['user1'], ['group1'], false],
88
-
89
-			// applicable cases
90
-			[[self::USER_ID], [], true],
91
-			[[], [self::GROUP_ID], true],
92
-			[[self::USER_ID], ['group1'], true],
93
-			[['user1'], [self::GROUP_ID], true],
94
-
95
-			// sanity checks
96
-			[['user1', 'user2', self::USER_ID, 'user3'], [], true],
97
-		];
98
-	}
99
-
100
-	/**
101
-	 * @dataProvider applicableStorageProvider
102
-	 */
103
-	public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible): void {
104
-		$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
105
-		$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
106
-
107
-		$storage = new StorageConfig();
108
-		$storage->setMountPoint('mountpoint');
109
-		$storage->setBackend($backend);
110
-		$storage->setAuthMechanism($authMechanism);
111
-		$storage->setBackendOptions(['password' => 'testPassword']);
112
-		$storage->setApplicableUsers($applicableUsers);
113
-		$storage->setApplicableGroups($applicableGroups);
114
-
115
-		$newStorage = $this->globalStoragesService->addStorage($storage);
116
-
117
-		$storages = $this->service->getAllStorages();
118
-		if ($isVisible) {
119
-			$this->assertEquals(1, count($storages));
120
-			$retrievedStorage = $this->service->getStorage($newStorage->getId());
121
-			$this->assertEquals('/mountpoint', $retrievedStorage->getMountPoint());
122
-		} else {
123
-			$this->assertEquals(0, count($storages));
124
-
125
-			try {
126
-				$this->service->getStorage($newStorage->getId());
127
-				$this->fail('Failed asserting that storage can\'t be accessed by id');
128
-			} catch (NotFoundException $e) {
129
-			}
130
-		}
131
-	}
132
-
133
-
134
-	public function testAddStorage($storageParams = null): void {
135
-		$this->expectException(\DomainException::class);
136
-
137
-		$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
138
-		$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
139
-
140
-		$storage = new StorageConfig(255);
141
-		$storage->setMountPoint('mountpoint');
142
-		$storage->setBackend($backend);
143
-		$storage->setAuthMechanism($authMechanism);
144
-		$storage->setBackendOptions(['password' => 'testPassword']);
145
-
146
-		$this->service->addStorage($storage);
147
-	}
148
-
149
-
150
-	public function testUpdateStorage($storageParams = null): void {
151
-		$this->expectException(\DomainException::class);
152
-
153
-		$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
154
-		$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
155
-
156
-		$storage = new StorageConfig(255);
157
-		$storage->setMountPoint('mountpoint');
158
-		$storage->setBackend($backend);
159
-		$storage->setAuthMechanism($authMechanism);
160
-		$storage->setBackendOptions(['password' => 'testPassword']);
161
-
162
-		$newStorage = $this->globalStoragesService->addStorage($storage);
163
-
164
-		$retrievedStorage = $this->service->getStorage($newStorage->getId());
165
-		$retrievedStorage->setMountPoint('abc');
166
-		$this->service->updateStorage($retrievedStorage);
167
-	}
168
-
169
-
170
-	public function testNonExistingStorage(): void {
171
-		$this->expectException(\DomainException::class);
172
-
173
-		$this->ActualNonExistingStorageTest();
174
-	}
175
-
176
-	/**
177
-	 * @dataProvider deleteStorageDataProvider
178
-	 */
179
-	public function testDeleteStorage($backendOptions, $rustyStorageId): void {
180
-		$this->expectException(\DomainException::class);
181
-
182
-		$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
183
-		$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
184
-
185
-		$storage = new StorageConfig(255);
186
-		$storage->setMountPoint('mountpoint');
187
-		$storage->setBackend($backend);
188
-		$storage->setAuthMechanism($authMechanism);
189
-		$storage->setBackendOptions($backendOptions);
190
-
191
-		$newStorage = $this->globalStoragesService->addStorage($storage);
192
-		$id = $newStorage->getId();
193
-
194
-		$this->service->removeStorage($id);
195
-	}
196
-
197
-
198
-	public function testDeleteUnexistingStorage(): void {
199
-		$this->expectException(\DomainException::class);
200
-
201
-		$this->actualDeletedUnexistingStorageTest();
202
-	}
203
-
204
-	public static function getUniqueStoragesProvider(): array {
205
-		return [
206
-			// 'all' vs group
207
-			[100, [], [], 100, [], [self::GROUP_ID], 2],
208
-			[100, [], [self::GROUP_ID], 100, [], [], 1],
209
-
210
-			// 'all' vs user
211
-			[100, [], [], 100, [self::USER_ID], [], 2],
212
-			[100, [self::USER_ID], [], 100, [], [], 1],
213
-
214
-			// group vs user
215
-			[100, [], [self::GROUP_ID], 100, [self::USER_ID], [], 2],
216
-			[100, [self::USER_ID], [], 100, [], [self::GROUP_ID], 1],
217
-
218
-			// group+user vs group
219
-			[100, [], [self::GROUP_ID2], 100, [self::USER_ID], [self::GROUP_ID], 2],
220
-			[100, [self::USER_ID], [self::GROUP_ID], 100, [], [self::GROUP_ID2], 1],
221
-
222
-			// user vs 'all' (higher priority)
223
-			[200, [], [], 100, [self::USER_ID], [], 2],
224
-			[100, [self::USER_ID], [], 200, [], [], 1],
225
-
226
-			// group vs group (higher priority)
227
-			[100, [], [self::GROUP_ID2], 200, [], [self::GROUP_ID], 2],
228
-			[200, [], [self::GROUP_ID], 100, [], [self::GROUP_ID2], 1],
229
-		];
230
-	}
231
-
232
-	/**
233
-	 * @dataProvider getUniqueStoragesProvider
234
-	 */
235
-	public function testGetUniqueStorages(
236
-		$priority1, $applicableUsers1, $applicableGroups1,
237
-		$priority2, $applicableUsers2, $applicableGroups2,
238
-		$expectedPrecedence,
239
-	): void {
240
-		$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
241
-		$backend->method('isVisibleFor')
242
-			->willReturn(true);
243
-		$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
244
-		$authMechanism->method('isVisibleFor')
245
-			->willReturn(true);
246
-
247
-		$storage1 = new StorageConfig();
248
-		$storage1->setMountPoint('mountpoint');
249
-		$storage1->setBackend($backend);
250
-		$storage1->setAuthMechanism($authMechanism);
251
-		$storage1->setBackendOptions(['password' => 'testPassword']);
252
-		$storage1->setPriority($priority1);
253
-		$storage1->setApplicableUsers($applicableUsers1);
254
-		$storage1->setApplicableGroups($applicableGroups1);
255
-
256
-		$storage1 = $this->globalStoragesService->addStorage($storage1);
257
-
258
-		$storage2 = new StorageConfig();
259
-		$storage2->setMountPoint('mountpoint');
260
-		$storage2->setBackend($backend);
261
-		$storage2->setAuthMechanism($authMechanism);
262
-		$storage2->setBackendOptions(['password' => 'testPassword']);
263
-		$storage2->setPriority($priority2);
264
-		$storage2->setApplicableUsers($applicableUsers2);
265
-		$storage2->setApplicableGroups($applicableGroups2);
266
-
267
-		$storage2 = $this->globalStoragesService->addStorage($storage2);
268
-
269
-		$storages = $this->service->getUniqueStorages();
270
-		$this->assertCount(1, $storages);
271
-
272
-		if ($expectedPrecedence === 1) {
273
-			$this->assertArrayHasKey($storage1->getID(), $storages);
274
-		} elseif ($expectedPrecedence === 2) {
275
-			$this->assertArrayHasKey($storage2->getID(), $storages);
276
-		}
277
-	}
278
-
279
-	public function testGetStoragesBackendNotVisible(): void {
280
-		// we don't test this here
281
-		$this->addToAssertionCount(1);
282
-	}
283
-
284
-	public function testGetStoragesAuthMechanismNotVisible(): void {
285
-		// we don't test this here
286
-		$this->addToAssertionCount(1);
287
-	}
288
-
289
-	public function testHooksAddStorage($a = null, $b = null, $c = null): void {
290
-		// we don't test this here
291
-		$this->addToAssertionCount(1);
292
-	}
293
-
294
-	public function testHooksUpdateStorage($a = null, $b = null, $c = null, $d = null, $e = null): void {
295
-		// we don't test this here
296
-		$this->addToAssertionCount(1);
297
-	}
298
-
299
-	public function testHooksRenameMountPoint(): void {
300
-		// we don't test this here
301
-		$this->addToAssertionCount(1);
302
-	}
303
-
304
-	public function testHooksDeleteStorage($a = null, $b = null, $c = null): void {
305
-		// we don't test this here
306
-		$this->addToAssertionCount(1);
307
-	}
308
-
309
-	public function testLegacyConfigConversionApplicableAll(): void {
310
-		// we don't test this here
311
-		$this->addToAssertionCount(1);
312
-	}
313
-
314
-	public function testLegacyConfigConversionApplicableUserAndGroup(): void {
315
-		// we don't test this here
316
-		$this->addToAssertionCount(1);
317
-	}
318
-
319
-	public function testReadLegacyConfigAndGenerateConfigId(): void {
320
-		// we don't test this here
321
-		$this->addToAssertionCount(1);
322
-	}
323
-
324
-	public function testReadLegacyConfigNoAuthMechanism(): void {
325
-		// we don't test this here
326
-		$this->addToAssertionCount(1);
327
-	}
328
-
329
-	public function testReadLegacyConfigClass(): void {
330
-		// we don't test this here
331
-		$this->addToAssertionCount(1);
332
-	}
333
-
334
-	public function testReadEmptyMountPoint(): void {
335
-		// we don't test this here
336
-		$this->addToAssertionCount(1);
337
-	}
338
-
339
-	public function testUpdateStorageMountPoint(): void {
340
-		// we don't test this here
341
-		$this->addToAssertionCount(1);
342
-	}
26
+    use UserTrait;
27
+
28
+    protected IGroupManager&MockObject $groupManager;
29
+    protected StoragesService $globalStoragesService;
30
+    protected User $user;
31
+
32
+    public const USER_ID = 'test_user';
33
+    public const GROUP_ID = 'test_group';
34
+    public const GROUP_ID2 = 'test_group2';
35
+
36
+    protected function setUp(): void {
37
+        parent::setUp();
38
+
39
+        $this->globalStoragesService = $this->service;
40
+
41
+        $this->user = new User(self::USER_ID, null, Server::get(IEventDispatcher::class));
42
+        /** @var IUserSession&MockObject $userSession */
43
+        $userSession = $this->createMock(IUserSession::class);
44
+        $userSession
45
+            ->expects($this->any())
46
+            ->method('getUser')
47
+            ->willReturn($this->user);
48
+
49
+        $this->groupManager = $this->createMock(IGroupManager::class);
50
+        $this->groupManager->method('isInGroup')
51
+            ->willReturnCallback(function ($userId, $groupId) {
52
+                if ($userId === self::USER_ID) {
53
+                    switch ($groupId) {
54
+                        case self::GROUP_ID:
55
+                        case self::GROUP_ID2:
56
+                            return true;
57
+                    }
58
+                }
59
+                return false;
60
+            });
61
+        $this->groupManager->method('getUserGroupIds')
62
+            ->willReturnCallback(function (IUser $user) {
63
+                if ($user->getUID() === self::USER_ID) {
64
+                    return [self::GROUP_ID, self::GROUP_ID2];
65
+                } else {
66
+                    return [];
67
+                }
68
+            });
69
+
70
+        $this->service = new UserGlobalStoragesService(
71
+            $this->backendService,
72
+            $this->dbConfig,
73
+            $userSession,
74
+            $this->groupManager,
75
+            $this->mountCache,
76
+            $this->eventDispatcher,
77
+        );
78
+    }
79
+
80
+    public static function applicableStorageProvider(): array {
81
+        return [
82
+            [[], [], true],
83
+
84
+            // not applicable cases
85
+            [['user1'], [], false],
86
+            [[], ['group1'], false],
87
+            [['user1'], ['group1'], false],
88
+
89
+            // applicable cases
90
+            [[self::USER_ID], [], true],
91
+            [[], [self::GROUP_ID], true],
92
+            [[self::USER_ID], ['group1'], true],
93
+            [['user1'], [self::GROUP_ID], true],
94
+
95
+            // sanity checks
96
+            [['user1', 'user2', self::USER_ID, 'user3'], [], true],
97
+        ];
98
+    }
99
+
100
+    /**
101
+     * @dataProvider applicableStorageProvider
102
+     */
103
+    public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible): void {
104
+        $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
105
+        $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
106
+
107
+        $storage = new StorageConfig();
108
+        $storage->setMountPoint('mountpoint');
109
+        $storage->setBackend($backend);
110
+        $storage->setAuthMechanism($authMechanism);
111
+        $storage->setBackendOptions(['password' => 'testPassword']);
112
+        $storage->setApplicableUsers($applicableUsers);
113
+        $storage->setApplicableGroups($applicableGroups);
114
+
115
+        $newStorage = $this->globalStoragesService->addStorage($storage);
116
+
117
+        $storages = $this->service->getAllStorages();
118
+        if ($isVisible) {
119
+            $this->assertEquals(1, count($storages));
120
+            $retrievedStorage = $this->service->getStorage($newStorage->getId());
121
+            $this->assertEquals('/mountpoint', $retrievedStorage->getMountPoint());
122
+        } else {
123
+            $this->assertEquals(0, count($storages));
124
+
125
+            try {
126
+                $this->service->getStorage($newStorage->getId());
127
+                $this->fail('Failed asserting that storage can\'t be accessed by id');
128
+            } catch (NotFoundException $e) {
129
+            }
130
+        }
131
+    }
132
+
133
+
134
+    public function testAddStorage($storageParams = null): void {
135
+        $this->expectException(\DomainException::class);
136
+
137
+        $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
138
+        $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
139
+
140
+        $storage = new StorageConfig(255);
141
+        $storage->setMountPoint('mountpoint');
142
+        $storage->setBackend($backend);
143
+        $storage->setAuthMechanism($authMechanism);
144
+        $storage->setBackendOptions(['password' => 'testPassword']);
145
+
146
+        $this->service->addStorage($storage);
147
+    }
148
+
149
+
150
+    public function testUpdateStorage($storageParams = null): void {
151
+        $this->expectException(\DomainException::class);
152
+
153
+        $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
154
+        $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
155
+
156
+        $storage = new StorageConfig(255);
157
+        $storage->setMountPoint('mountpoint');
158
+        $storage->setBackend($backend);
159
+        $storage->setAuthMechanism($authMechanism);
160
+        $storage->setBackendOptions(['password' => 'testPassword']);
161
+
162
+        $newStorage = $this->globalStoragesService->addStorage($storage);
163
+
164
+        $retrievedStorage = $this->service->getStorage($newStorage->getId());
165
+        $retrievedStorage->setMountPoint('abc');
166
+        $this->service->updateStorage($retrievedStorage);
167
+    }
168
+
169
+
170
+    public function testNonExistingStorage(): void {
171
+        $this->expectException(\DomainException::class);
172
+
173
+        $this->ActualNonExistingStorageTest();
174
+    }
175
+
176
+    /**
177
+     * @dataProvider deleteStorageDataProvider
178
+     */
179
+    public function testDeleteStorage($backendOptions, $rustyStorageId): void {
180
+        $this->expectException(\DomainException::class);
181
+
182
+        $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
183
+        $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
184
+
185
+        $storage = new StorageConfig(255);
186
+        $storage->setMountPoint('mountpoint');
187
+        $storage->setBackend($backend);
188
+        $storage->setAuthMechanism($authMechanism);
189
+        $storage->setBackendOptions($backendOptions);
190
+
191
+        $newStorage = $this->globalStoragesService->addStorage($storage);
192
+        $id = $newStorage->getId();
193
+
194
+        $this->service->removeStorage($id);
195
+    }
196
+
197
+
198
+    public function testDeleteUnexistingStorage(): void {
199
+        $this->expectException(\DomainException::class);
200
+
201
+        $this->actualDeletedUnexistingStorageTest();
202
+    }
203
+
204
+    public static function getUniqueStoragesProvider(): array {
205
+        return [
206
+            // 'all' vs group
207
+            [100, [], [], 100, [], [self::GROUP_ID], 2],
208
+            [100, [], [self::GROUP_ID], 100, [], [], 1],
209
+
210
+            // 'all' vs user
211
+            [100, [], [], 100, [self::USER_ID], [], 2],
212
+            [100, [self::USER_ID], [], 100, [], [], 1],
213
+
214
+            // group vs user
215
+            [100, [], [self::GROUP_ID], 100, [self::USER_ID], [], 2],
216
+            [100, [self::USER_ID], [], 100, [], [self::GROUP_ID], 1],
217
+
218
+            // group+user vs group
219
+            [100, [], [self::GROUP_ID2], 100, [self::USER_ID], [self::GROUP_ID], 2],
220
+            [100, [self::USER_ID], [self::GROUP_ID], 100, [], [self::GROUP_ID2], 1],
221
+
222
+            // user vs 'all' (higher priority)
223
+            [200, [], [], 100, [self::USER_ID], [], 2],
224
+            [100, [self::USER_ID], [], 200, [], [], 1],
225
+
226
+            // group vs group (higher priority)
227
+            [100, [], [self::GROUP_ID2], 200, [], [self::GROUP_ID], 2],
228
+            [200, [], [self::GROUP_ID], 100, [], [self::GROUP_ID2], 1],
229
+        ];
230
+    }
231
+
232
+    /**
233
+     * @dataProvider getUniqueStoragesProvider
234
+     */
235
+    public function testGetUniqueStorages(
236
+        $priority1, $applicableUsers1, $applicableGroups1,
237
+        $priority2, $applicableUsers2, $applicableGroups2,
238
+        $expectedPrecedence,
239
+    ): void {
240
+        $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
241
+        $backend->method('isVisibleFor')
242
+            ->willReturn(true);
243
+        $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
244
+        $authMechanism->method('isVisibleFor')
245
+            ->willReturn(true);
246
+
247
+        $storage1 = new StorageConfig();
248
+        $storage1->setMountPoint('mountpoint');
249
+        $storage1->setBackend($backend);
250
+        $storage1->setAuthMechanism($authMechanism);
251
+        $storage1->setBackendOptions(['password' => 'testPassword']);
252
+        $storage1->setPriority($priority1);
253
+        $storage1->setApplicableUsers($applicableUsers1);
254
+        $storage1->setApplicableGroups($applicableGroups1);
255
+
256
+        $storage1 = $this->globalStoragesService->addStorage($storage1);
257
+
258
+        $storage2 = new StorageConfig();
259
+        $storage2->setMountPoint('mountpoint');
260
+        $storage2->setBackend($backend);
261
+        $storage2->setAuthMechanism($authMechanism);
262
+        $storage2->setBackendOptions(['password' => 'testPassword']);
263
+        $storage2->setPriority($priority2);
264
+        $storage2->setApplicableUsers($applicableUsers2);
265
+        $storage2->setApplicableGroups($applicableGroups2);
266
+
267
+        $storage2 = $this->globalStoragesService->addStorage($storage2);
268
+
269
+        $storages = $this->service->getUniqueStorages();
270
+        $this->assertCount(1, $storages);
271
+
272
+        if ($expectedPrecedence === 1) {
273
+            $this->assertArrayHasKey($storage1->getID(), $storages);
274
+        } elseif ($expectedPrecedence === 2) {
275
+            $this->assertArrayHasKey($storage2->getID(), $storages);
276
+        }
277
+    }
278
+
279
+    public function testGetStoragesBackendNotVisible(): void {
280
+        // we don't test this here
281
+        $this->addToAssertionCount(1);
282
+    }
283
+
284
+    public function testGetStoragesAuthMechanismNotVisible(): void {
285
+        // we don't test this here
286
+        $this->addToAssertionCount(1);
287
+    }
288
+
289
+    public function testHooksAddStorage($a = null, $b = null, $c = null): void {
290
+        // we don't test this here
291
+        $this->addToAssertionCount(1);
292
+    }
293
+
294
+    public function testHooksUpdateStorage($a = null, $b = null, $c = null, $d = null, $e = null): void {
295
+        // we don't test this here
296
+        $this->addToAssertionCount(1);
297
+    }
298
+
299
+    public function testHooksRenameMountPoint(): void {
300
+        // we don't test this here
301
+        $this->addToAssertionCount(1);
302
+    }
303
+
304
+    public function testHooksDeleteStorage($a = null, $b = null, $c = null): void {
305
+        // we don't test this here
306
+        $this->addToAssertionCount(1);
307
+    }
308
+
309
+    public function testLegacyConfigConversionApplicableAll(): void {
310
+        // we don't test this here
311
+        $this->addToAssertionCount(1);
312
+    }
313
+
314
+    public function testLegacyConfigConversionApplicableUserAndGroup(): void {
315
+        // we don't test this here
316
+        $this->addToAssertionCount(1);
317
+    }
318
+
319
+    public function testReadLegacyConfigAndGenerateConfigId(): void {
320
+        // we don't test this here
321
+        $this->addToAssertionCount(1);
322
+    }
323
+
324
+    public function testReadLegacyConfigNoAuthMechanism(): void {
325
+        // we don't test this here
326
+        $this->addToAssertionCount(1);
327
+    }
328
+
329
+    public function testReadLegacyConfigClass(): void {
330
+        // we don't test this here
331
+        $this->addToAssertionCount(1);
332
+    }
333
+
334
+    public function testReadEmptyMountPoint(): void {
335
+        // we don't test this here
336
+        $this->addToAssertionCount(1);
337
+    }
338
+
339
+    public function testUpdateStorageMountPoint(): void {
340
+        // we don't test this here
341
+        $this->addToAssertionCount(1);
342
+    }
343 343
 }
Please login to merge, or discard this patch.
apps/files_external/tests/Service/GlobalStoragesServiceTest.php 1 patch
Indentation   +592 added lines, -592 removed lines patch added patch discarded remove patch
@@ -17,596 +17,596 @@
 block discarded – undo
17 17
  * @group DB
18 18
  */
19 19
 class GlobalStoragesServiceTest extends StoragesServiceTestCase {
20
-	protected function setUp(): void {
21
-		parent::setUp();
22
-		$this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher);
23
-	}
24
-
25
-	protected function tearDown(): void {
26
-		@unlink($this->dataDir . '/mount.json');
27
-		parent::tearDown();
28
-	}
29
-
30
-	protected function makeTestStorageData() {
31
-		return $this->makeStorageConfig([
32
-			'mountPoint' => 'mountpoint',
33
-			'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
34
-			'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
35
-			'backendOptions' => [
36
-				'option1' => 'value1',
37
-				'option2' => 'value2',
38
-				'password' => 'testPassword',
39
-			],
40
-			'applicableUsers' => [],
41
-			'applicableGroups' => [],
42
-			'priority' => 15,
43
-			'mountOptions' => [
44
-				'preview' => false,
45
-			]
46
-		]);
47
-	}
48
-
49
-	public static function storageDataProvider(): array {
50
-		return [
51
-			// all users
52
-			[
53
-				[
54
-					'mountPoint' => 'mountpoint',
55
-					'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
56
-					'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
57
-					'backendOptions' => [
58
-						'option1' => 'value1',
59
-						'option2' => 'value2',
60
-						'password' => 'testPassword',
61
-					],
62
-					'applicableUsers' => [],
63
-					'applicableGroups' => [],
64
-					'priority' => 15,
65
-				],
66
-			],
67
-			// some users
68
-			[
69
-				[
70
-					'mountPoint' => 'mountpoint',
71
-					'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
72
-					'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
73
-					'backendOptions' => [
74
-						'option1' => 'value1',
75
-						'option2' => 'value2',
76
-						'password' => 'testPassword',
77
-					],
78
-					'applicableUsers' => ['user1', 'user2'],
79
-					'applicableGroups' => [],
80
-					'priority' => 15,
81
-				],
82
-			],
83
-			// some groups
84
-			[
85
-				[
86
-					'mountPoint' => 'mountpoint',
87
-					'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
88
-					'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
89
-					'backendOptions' => [
90
-						'option1' => 'value1',
91
-						'option2' => 'value2',
92
-						'password' => 'testPassword',
93
-					],
94
-					'applicableUsers' => [],
95
-					'applicableGroups' => ['group1', 'group2'],
96
-					'priority' => 15,
97
-				],
98
-			],
99
-			// both users and groups
100
-			[
101
-				[
102
-					'mountPoint' => 'mountpoint',
103
-					'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
104
-					'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
105
-					'backendOptions' => [
106
-						'option1' => 'value1',
107
-						'option2' => 'value2',
108
-						'password' => 'testPassword',
109
-					],
110
-					'applicableUsers' => ['user1', 'user2'],
111
-					'applicableGroups' => ['group1', 'group2'],
112
-					'priority' => 15,
113
-				],
114
-			],
115
-		];
116
-	}
117
-
118
-	/**
119
-	 * @dataProvider storageDataProvider
120
-	 */
121
-	public function testAddStorage($storageParams): void {
122
-		$storage = $this->makeStorageConfig($storageParams);
123
-		$newStorage = $this->service->addStorage($storage);
124
-
125
-		$baseId = $newStorage->getId();
126
-
127
-		$newStorage = $this->service->getStorage($baseId);
128
-
129
-		$this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint());
130
-		$this->assertEquals($storage->getBackend(), $newStorage->getBackend());
131
-		$this->assertEquals($storage->getAuthMechanism(), $newStorage->getAuthMechanism());
132
-		$this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions());
133
-		$this->assertEquals($storage->getApplicableUsers(), $newStorage->getApplicableUsers());
134
-		$this->assertEquals($storage->getApplicableGroups(), $newStorage->getApplicableGroups());
135
-		$this->assertEquals($storage->getPriority(), $newStorage->getPriority());
136
-		$this->assertEquals(0, $newStorage->getStatus());
137
-
138
-		$nextStorage = $this->service->addStorage($storage);
139
-		$this->assertEquals($baseId + 1, $nextStorage->getId());
140
-	}
141
-
142
-	/**
143
-	 * @dataProvider storageDataProvider
144
-	 */
145
-	public function testUpdateStorage($updatedStorageParams): void {
146
-		$updatedStorage = $this->makeStorageConfig($updatedStorageParams);
147
-		$storage = $this->makeStorageConfig([
148
-			'mountPoint' => 'mountpoint',
149
-			'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
150
-			'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
151
-			'backendOptions' => [
152
-				'option1' => 'value1',
153
-				'option2' => 'value2',
154
-				'password' => 'testPassword',
155
-			],
156
-			'applicableUsers' => [],
157
-			'applicableGroups' => [],
158
-			'priority' => 15,
159
-		]);
160
-
161
-		$newStorage = $this->service->addStorage($storage);
162
-		$id = $newStorage->getId();
163
-
164
-		$updatedStorage->setId($id);
165
-
166
-		$this->service->updateStorage($updatedStorage);
167
-		$newStorage = $this->service->getStorage($id);
168
-
169
-		$this->assertEquals($updatedStorage->getMountPoint(), $newStorage->getMountPoint());
170
-		$this->assertEquals($updatedStorage->getBackendOptions()['password'], $newStorage->getBackendOptions()['password']);
171
-		$this->assertEquals($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers());
172
-		$this->assertEquals($updatedStorage->getApplicableGroups(), $newStorage->getApplicableGroups());
173
-		$this->assertEquals($updatedStorage->getPriority(), $newStorage->getPriority());
174
-		$this->assertEquals(0, $newStorage->getStatus());
175
-	}
176
-
177
-	public static function hooksAddStorageDataProvider(): array {
178
-		return [
179
-			// applicable all
180
-			[
181
-				[],
182
-				[],
183
-				// expected hook calls
184
-				[
185
-					[
186
-						Filesystem::signal_create_mount,
187
-						MountConfig::MOUNT_TYPE_USER,
188
-						'all'
189
-					],
190
-				],
191
-			],
192
-			// single user
193
-			[
194
-				['user1'],
195
-				[],
196
-				// expected hook calls
197
-				[
198
-					[
199
-						Filesystem::signal_create_mount,
200
-						MountConfig::MOUNT_TYPE_USER,
201
-						'user1',
202
-					],
203
-				],
204
-			],
205
-			// single group
206
-			[
207
-				[],
208
-				['group1'],
209
-				// expected hook calls
210
-				[
211
-					[
212
-						Filesystem::signal_create_mount,
213
-						MountConfig::MOUNT_TYPE_GROUP,
214
-						'group1',
215
-					],
216
-				],
217
-			],
218
-			// multiple users
219
-			[
220
-				['user1', 'user2'],
221
-				[],
222
-				[
223
-					[
224
-						Filesystem::signal_create_mount,
225
-						MountConfig::MOUNT_TYPE_USER,
226
-						'user1',
227
-					],
228
-					[
229
-						Filesystem::signal_create_mount,
230
-						MountConfig::MOUNT_TYPE_USER,
231
-						'user2',
232
-					],
233
-				],
234
-			],
235
-			// multiple groups
236
-			[
237
-				[],
238
-				['group1', 'group2'],
239
-				// expected hook calls
240
-				[
241
-					[
242
-						Filesystem::signal_create_mount,
243
-						MountConfig::MOUNT_TYPE_GROUP,
244
-						'group1'
245
-					],
246
-					[
247
-						Filesystem::signal_create_mount,
248
-						MountConfig::MOUNT_TYPE_GROUP,
249
-						'group2'
250
-					],
251
-				],
252
-			],
253
-			// mixed groups and users
254
-			[
255
-				['user1', 'user2'],
256
-				['group1', 'group2'],
257
-				// expected hook calls
258
-				[
259
-					[
260
-						Filesystem::signal_create_mount,
261
-						MountConfig::MOUNT_TYPE_USER,
262
-						'user1',
263
-					],
264
-					[
265
-						Filesystem::signal_create_mount,
266
-						MountConfig::MOUNT_TYPE_USER,
267
-						'user2',
268
-					],
269
-					[
270
-						Filesystem::signal_create_mount,
271
-						MountConfig::MOUNT_TYPE_GROUP,
272
-						'group1'
273
-					],
274
-					[
275
-						Filesystem::signal_create_mount,
276
-						MountConfig::MOUNT_TYPE_GROUP,
277
-						'group2'
278
-					],
279
-				],
280
-			],
281
-		];
282
-	}
283
-
284
-	/**
285
-	 * @dataProvider hooksAddStorageDataProvider
286
-	 */
287
-	public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls): void {
288
-		$storage = $this->makeTestStorageData();
289
-		$storage->setApplicableUsers($applicableUsers);
290
-		$storage->setApplicableGroups($applicableGroups);
291
-		$this->service->addStorage($storage);
292
-
293
-		$this->assertCount(count($expectedCalls), self::$hookCalls);
294
-
295
-		foreach ($expectedCalls as $index => $call) {
296
-			$this->assertHookCall(
297
-				self::$hookCalls[$index],
298
-				$call[0],
299
-				$storage->getMountPoint(),
300
-				$call[1],
301
-				$call[2]
302
-			);
303
-		}
304
-	}
305
-
306
-	public static function hooksUpdateStorageDataProvider(): array {
307
-		return [
308
-			[
309
-				// nothing to multiple users and groups
310
-				[],
311
-				[],
312
-				['user1', 'user2'],
313
-				['group1', 'group2'],
314
-				// expected hook calls
315
-				[
316
-					// delete the "all entry"
317
-					[
318
-						Filesystem::signal_delete_mount,
319
-						MountConfig::MOUNT_TYPE_USER,
320
-						'all',
321
-					],
322
-					[
323
-						Filesystem::signal_create_mount,
324
-						MountConfig::MOUNT_TYPE_USER,
325
-						'user1',
326
-					],
327
-					[
328
-						Filesystem::signal_create_mount,
329
-						MountConfig::MOUNT_TYPE_USER,
330
-						'user2',
331
-					],
332
-					[
333
-						Filesystem::signal_create_mount,
334
-						MountConfig::MOUNT_TYPE_GROUP,
335
-						'group1'
336
-					],
337
-					[
338
-						Filesystem::signal_create_mount,
339
-						MountConfig::MOUNT_TYPE_GROUP,
340
-						'group2'
341
-					],
342
-				],
343
-			],
344
-			[
345
-				// adding a user and a group
346
-				['user1'],
347
-				['group1'],
348
-				['user1', 'user2'],
349
-				['group1', 'group2'],
350
-				// expected hook calls
351
-				[
352
-					[
353
-						Filesystem::signal_create_mount,
354
-						MountConfig::MOUNT_TYPE_USER,
355
-						'user2',
356
-					],
357
-					[
358
-						Filesystem::signal_create_mount,
359
-						MountConfig::MOUNT_TYPE_GROUP,
360
-						'group2'
361
-					],
362
-				],
363
-			],
364
-			[
365
-				// removing a user and a group
366
-				['user1', 'user2'],
367
-				['group1', 'group2'],
368
-				['user1'],
369
-				['group1'],
370
-				// expected hook calls
371
-				[
372
-					[
373
-						Filesystem::signal_delete_mount,
374
-						MountConfig::MOUNT_TYPE_USER,
375
-						'user2',
376
-					],
377
-					[
378
-						Filesystem::signal_delete_mount,
379
-						MountConfig::MOUNT_TYPE_GROUP,
380
-						'group2'
381
-					],
382
-				],
383
-			],
384
-			[
385
-				// removing all
386
-				['user1'],
387
-				['group1'],
388
-				[],
389
-				[],
390
-				// expected hook calls
391
-				[
392
-					[
393
-						Filesystem::signal_delete_mount,
394
-						MountConfig::MOUNT_TYPE_USER,
395
-						'user1',
396
-					],
397
-					[
398
-						Filesystem::signal_delete_mount,
399
-						MountConfig::MOUNT_TYPE_GROUP,
400
-						'group1'
401
-					],
402
-					// create the "all" entry
403
-					[
404
-						Filesystem::signal_create_mount,
405
-						MountConfig::MOUNT_TYPE_USER,
406
-						'all'
407
-					],
408
-				],
409
-			],
410
-			[
411
-				// no changes
412
-				['user1'],
413
-				['group1'],
414
-				['user1'],
415
-				['group1'],
416
-				// no hook calls
417
-				[]
418
-			]
419
-		];
420
-	}
421
-
422
-	/**
423
-	 * @dataProvider hooksUpdateStorageDataProvider
424
-	 */
425
-	public function testHooksUpdateStorage(
426
-		array $sourceApplicableUsers,
427
-		array $sourceApplicableGroups,
428
-		array $updatedApplicableUsers,
429
-		array $updatedApplicableGroups,
430
-		array $expectedCalls,
431
-	): void {
432
-		$storage = $this->makeTestStorageData();
433
-		$storage->setApplicableUsers($sourceApplicableUsers);
434
-		$storage->setApplicableGroups($sourceApplicableGroups);
435
-		$storage = $this->service->addStorage($storage);
436
-
437
-		$storage->setApplicableUsers($updatedApplicableUsers);
438
-		$storage->setApplicableGroups($updatedApplicableGroups);
439
-
440
-		// reset calls
441
-		self::$hookCalls = [];
442
-
443
-		$this->service->updateStorage($storage);
444
-
445
-		$this->assertCount(count($expectedCalls), self::$hookCalls);
446
-
447
-		foreach ($expectedCalls as $index => $call) {
448
-			$this->assertHookCall(
449
-				self::$hookCalls[$index],
450
-				$call[0],
451
-				'/mountpoint',
452
-				$call[1],
453
-				$call[2]
454
-			);
455
-		}
456
-	}
457
-
458
-
459
-	public function testHooksRenameMountPoint(): void {
460
-		$storage = $this->makeTestStorageData();
461
-		$storage->setApplicableUsers(['user1', 'user2']);
462
-		$storage->setApplicableGroups(['group1', 'group2']);
463
-		$storage = $this->service->addStorage($storage);
464
-
465
-		$storage->setMountPoint('renamedMountpoint');
466
-
467
-		// reset calls
468
-		self::$hookCalls = [];
469
-
470
-		$this->service->updateStorage($storage);
471
-
472
-		$expectedCalls = [
473
-			// deletes old mount
474
-			[
475
-				Filesystem::signal_delete_mount,
476
-				'/mountpoint',
477
-				MountConfig::MOUNT_TYPE_USER,
478
-				'user1',
479
-			],
480
-			[
481
-				Filesystem::signal_delete_mount,
482
-				'/mountpoint',
483
-				MountConfig::MOUNT_TYPE_USER,
484
-				'user2',
485
-			],
486
-			[
487
-				Filesystem::signal_delete_mount,
488
-				'/mountpoint',
489
-				MountConfig::MOUNT_TYPE_GROUP,
490
-				'group1',
491
-			],
492
-			[
493
-				Filesystem::signal_delete_mount,
494
-				'/mountpoint',
495
-				MountConfig::MOUNT_TYPE_GROUP,
496
-				'group2',
497
-			],
498
-			// creates new one
499
-			[
500
-				Filesystem::signal_create_mount,
501
-				'/renamedMountpoint',
502
-				MountConfig::MOUNT_TYPE_USER,
503
-				'user1',
504
-			],
505
-			[
506
-				Filesystem::signal_create_mount,
507
-				'/renamedMountpoint',
508
-				MountConfig::MOUNT_TYPE_USER,
509
-				'user2',
510
-			],
511
-			[
512
-				Filesystem::signal_create_mount,
513
-				'/renamedMountpoint',
514
-				MountConfig::MOUNT_TYPE_GROUP,
515
-				'group1',
516
-			],
517
-			[
518
-				Filesystem::signal_create_mount,
519
-				'/renamedMountpoint',
520
-				MountConfig::MOUNT_TYPE_GROUP,
521
-				'group2',
522
-			],
523
-		];
524
-
525
-		$this->assertCount(count($expectedCalls), self::$hookCalls);
526
-
527
-		foreach ($expectedCalls as $index => $call) {
528
-			$this->assertHookCall(
529
-				self::$hookCalls[$index],
530
-				$call[0],
531
-				$call[1],
532
-				$call[2],
533
-				$call[3]
534
-			);
535
-		}
536
-	}
537
-
538
-	public static function hooksDeleteStorageDataProvider(): array {
539
-		return [
540
-			[
541
-				['user1', 'user2'],
542
-				['group1', 'group2'],
543
-				// expected hook calls
544
-				[
545
-					[
546
-						Filesystem::signal_delete_mount,
547
-						MountConfig::MOUNT_TYPE_USER,
548
-						'user1',
549
-					],
550
-					[
551
-						Filesystem::signal_delete_mount,
552
-						MountConfig::MOUNT_TYPE_USER,
553
-						'user2',
554
-					],
555
-					[
556
-						Filesystem::signal_delete_mount,
557
-						MountConfig::MOUNT_TYPE_GROUP,
558
-						'group1'
559
-					],
560
-					[
561
-						Filesystem::signal_delete_mount,
562
-						MountConfig::MOUNT_TYPE_GROUP,
563
-						'group2'
564
-					],
565
-				],
566
-			],
567
-			[
568
-				// deleting "all" entry
569
-				[],
570
-				[],
571
-				[
572
-					[
573
-						Filesystem::signal_delete_mount,
574
-						MountConfig::MOUNT_TYPE_USER,
575
-						'all',
576
-					],
577
-				],
578
-			],
579
-		];
580
-	}
581
-
582
-	/**
583
-	 * @dataProvider hooksDeleteStorageDataProvider
584
-	 */
585
-	public function testHooksDeleteStorage(
586
-		array $sourceApplicableUsers,
587
-		array $sourceApplicableGroups,
588
-		array $expectedCalls,
589
-	): void {
590
-		$storage = $this->makeTestStorageData();
591
-		$storage->setApplicableUsers($sourceApplicableUsers);
592
-		$storage->setApplicableGroups($sourceApplicableGroups);
593
-		$storage = $this->service->addStorage($storage);
594
-
595
-		// reset calls
596
-		self::$hookCalls = [];
597
-
598
-		$this->service->removeStorage($storage->getId());
599
-
600
-		$this->assertCount(count($expectedCalls), self::$hookCalls);
601
-
602
-		foreach ($expectedCalls as $index => $call) {
603
-			$this->assertHookCall(
604
-				self::$hookCalls[$index],
605
-				$call[0],
606
-				'/mountpoint',
607
-				$call[1],
608
-				$call[2]
609
-			);
610
-		}
611
-	}
20
+    protected function setUp(): void {
21
+        parent::setUp();
22
+        $this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher);
23
+    }
24
+
25
+    protected function tearDown(): void {
26
+        @unlink($this->dataDir . '/mount.json');
27
+        parent::tearDown();
28
+    }
29
+
30
+    protected function makeTestStorageData() {
31
+        return $this->makeStorageConfig([
32
+            'mountPoint' => 'mountpoint',
33
+            'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
34
+            'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
35
+            'backendOptions' => [
36
+                'option1' => 'value1',
37
+                'option2' => 'value2',
38
+                'password' => 'testPassword',
39
+            ],
40
+            'applicableUsers' => [],
41
+            'applicableGroups' => [],
42
+            'priority' => 15,
43
+            'mountOptions' => [
44
+                'preview' => false,
45
+            ]
46
+        ]);
47
+    }
48
+
49
+    public static function storageDataProvider(): array {
50
+        return [
51
+            // all users
52
+            [
53
+                [
54
+                    'mountPoint' => 'mountpoint',
55
+                    'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
56
+                    'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
57
+                    'backendOptions' => [
58
+                        'option1' => 'value1',
59
+                        'option2' => 'value2',
60
+                        'password' => 'testPassword',
61
+                    ],
62
+                    'applicableUsers' => [],
63
+                    'applicableGroups' => [],
64
+                    'priority' => 15,
65
+                ],
66
+            ],
67
+            // some users
68
+            [
69
+                [
70
+                    'mountPoint' => 'mountpoint',
71
+                    'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
72
+                    'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
73
+                    'backendOptions' => [
74
+                        'option1' => 'value1',
75
+                        'option2' => 'value2',
76
+                        'password' => 'testPassword',
77
+                    ],
78
+                    'applicableUsers' => ['user1', 'user2'],
79
+                    'applicableGroups' => [],
80
+                    'priority' => 15,
81
+                ],
82
+            ],
83
+            // some groups
84
+            [
85
+                [
86
+                    'mountPoint' => 'mountpoint',
87
+                    'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
88
+                    'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
89
+                    'backendOptions' => [
90
+                        'option1' => 'value1',
91
+                        'option2' => 'value2',
92
+                        'password' => 'testPassword',
93
+                    ],
94
+                    'applicableUsers' => [],
95
+                    'applicableGroups' => ['group1', 'group2'],
96
+                    'priority' => 15,
97
+                ],
98
+            ],
99
+            // both users and groups
100
+            [
101
+                [
102
+                    'mountPoint' => 'mountpoint',
103
+                    'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
104
+                    'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
105
+                    'backendOptions' => [
106
+                        'option1' => 'value1',
107
+                        'option2' => 'value2',
108
+                        'password' => 'testPassword',
109
+                    ],
110
+                    'applicableUsers' => ['user1', 'user2'],
111
+                    'applicableGroups' => ['group1', 'group2'],
112
+                    'priority' => 15,
113
+                ],
114
+            ],
115
+        ];
116
+    }
117
+
118
+    /**
119
+     * @dataProvider storageDataProvider
120
+     */
121
+    public function testAddStorage($storageParams): void {
122
+        $storage = $this->makeStorageConfig($storageParams);
123
+        $newStorage = $this->service->addStorage($storage);
124
+
125
+        $baseId = $newStorage->getId();
126
+
127
+        $newStorage = $this->service->getStorage($baseId);
128
+
129
+        $this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint());
130
+        $this->assertEquals($storage->getBackend(), $newStorage->getBackend());
131
+        $this->assertEquals($storage->getAuthMechanism(), $newStorage->getAuthMechanism());
132
+        $this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions());
133
+        $this->assertEquals($storage->getApplicableUsers(), $newStorage->getApplicableUsers());
134
+        $this->assertEquals($storage->getApplicableGroups(), $newStorage->getApplicableGroups());
135
+        $this->assertEquals($storage->getPriority(), $newStorage->getPriority());
136
+        $this->assertEquals(0, $newStorage->getStatus());
137
+
138
+        $nextStorage = $this->service->addStorage($storage);
139
+        $this->assertEquals($baseId + 1, $nextStorage->getId());
140
+    }
141
+
142
+    /**
143
+     * @dataProvider storageDataProvider
144
+     */
145
+    public function testUpdateStorage($updatedStorageParams): void {
146
+        $updatedStorage = $this->makeStorageConfig($updatedStorageParams);
147
+        $storage = $this->makeStorageConfig([
148
+            'mountPoint' => 'mountpoint',
149
+            'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
150
+            'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
151
+            'backendOptions' => [
152
+                'option1' => 'value1',
153
+                'option2' => 'value2',
154
+                'password' => 'testPassword',
155
+            ],
156
+            'applicableUsers' => [],
157
+            'applicableGroups' => [],
158
+            'priority' => 15,
159
+        ]);
160
+
161
+        $newStorage = $this->service->addStorage($storage);
162
+        $id = $newStorage->getId();
163
+
164
+        $updatedStorage->setId($id);
165
+
166
+        $this->service->updateStorage($updatedStorage);
167
+        $newStorage = $this->service->getStorage($id);
168
+
169
+        $this->assertEquals($updatedStorage->getMountPoint(), $newStorage->getMountPoint());
170
+        $this->assertEquals($updatedStorage->getBackendOptions()['password'], $newStorage->getBackendOptions()['password']);
171
+        $this->assertEquals($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers());
172
+        $this->assertEquals($updatedStorage->getApplicableGroups(), $newStorage->getApplicableGroups());
173
+        $this->assertEquals($updatedStorage->getPriority(), $newStorage->getPriority());
174
+        $this->assertEquals(0, $newStorage->getStatus());
175
+    }
176
+
177
+    public static function hooksAddStorageDataProvider(): array {
178
+        return [
179
+            // applicable all
180
+            [
181
+                [],
182
+                [],
183
+                // expected hook calls
184
+                [
185
+                    [
186
+                        Filesystem::signal_create_mount,
187
+                        MountConfig::MOUNT_TYPE_USER,
188
+                        'all'
189
+                    ],
190
+                ],
191
+            ],
192
+            // single user
193
+            [
194
+                ['user1'],
195
+                [],
196
+                // expected hook calls
197
+                [
198
+                    [
199
+                        Filesystem::signal_create_mount,
200
+                        MountConfig::MOUNT_TYPE_USER,
201
+                        'user1',
202
+                    ],
203
+                ],
204
+            ],
205
+            // single group
206
+            [
207
+                [],
208
+                ['group1'],
209
+                // expected hook calls
210
+                [
211
+                    [
212
+                        Filesystem::signal_create_mount,
213
+                        MountConfig::MOUNT_TYPE_GROUP,
214
+                        'group1',
215
+                    ],
216
+                ],
217
+            ],
218
+            // multiple users
219
+            [
220
+                ['user1', 'user2'],
221
+                [],
222
+                [
223
+                    [
224
+                        Filesystem::signal_create_mount,
225
+                        MountConfig::MOUNT_TYPE_USER,
226
+                        'user1',
227
+                    ],
228
+                    [
229
+                        Filesystem::signal_create_mount,
230
+                        MountConfig::MOUNT_TYPE_USER,
231
+                        'user2',
232
+                    ],
233
+                ],
234
+            ],
235
+            // multiple groups
236
+            [
237
+                [],
238
+                ['group1', 'group2'],
239
+                // expected hook calls
240
+                [
241
+                    [
242
+                        Filesystem::signal_create_mount,
243
+                        MountConfig::MOUNT_TYPE_GROUP,
244
+                        'group1'
245
+                    ],
246
+                    [
247
+                        Filesystem::signal_create_mount,
248
+                        MountConfig::MOUNT_TYPE_GROUP,
249
+                        'group2'
250
+                    ],
251
+                ],
252
+            ],
253
+            // mixed groups and users
254
+            [
255
+                ['user1', 'user2'],
256
+                ['group1', 'group2'],
257
+                // expected hook calls
258
+                [
259
+                    [
260
+                        Filesystem::signal_create_mount,
261
+                        MountConfig::MOUNT_TYPE_USER,
262
+                        'user1',
263
+                    ],
264
+                    [
265
+                        Filesystem::signal_create_mount,
266
+                        MountConfig::MOUNT_TYPE_USER,
267
+                        'user2',
268
+                    ],
269
+                    [
270
+                        Filesystem::signal_create_mount,
271
+                        MountConfig::MOUNT_TYPE_GROUP,
272
+                        'group1'
273
+                    ],
274
+                    [
275
+                        Filesystem::signal_create_mount,
276
+                        MountConfig::MOUNT_TYPE_GROUP,
277
+                        'group2'
278
+                    ],
279
+                ],
280
+            ],
281
+        ];
282
+    }
283
+
284
+    /**
285
+     * @dataProvider hooksAddStorageDataProvider
286
+     */
287
+    public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls): void {
288
+        $storage = $this->makeTestStorageData();
289
+        $storage->setApplicableUsers($applicableUsers);
290
+        $storage->setApplicableGroups($applicableGroups);
291
+        $this->service->addStorage($storage);
292
+
293
+        $this->assertCount(count($expectedCalls), self::$hookCalls);
294
+
295
+        foreach ($expectedCalls as $index => $call) {
296
+            $this->assertHookCall(
297
+                self::$hookCalls[$index],
298
+                $call[0],
299
+                $storage->getMountPoint(),
300
+                $call[1],
301
+                $call[2]
302
+            );
303
+        }
304
+    }
305
+
306
+    public static function hooksUpdateStorageDataProvider(): array {
307
+        return [
308
+            [
309
+                // nothing to multiple users and groups
310
+                [],
311
+                [],
312
+                ['user1', 'user2'],
313
+                ['group1', 'group2'],
314
+                // expected hook calls
315
+                [
316
+                    // delete the "all entry"
317
+                    [
318
+                        Filesystem::signal_delete_mount,
319
+                        MountConfig::MOUNT_TYPE_USER,
320
+                        'all',
321
+                    ],
322
+                    [
323
+                        Filesystem::signal_create_mount,
324
+                        MountConfig::MOUNT_TYPE_USER,
325
+                        'user1',
326
+                    ],
327
+                    [
328
+                        Filesystem::signal_create_mount,
329
+                        MountConfig::MOUNT_TYPE_USER,
330
+                        'user2',
331
+                    ],
332
+                    [
333
+                        Filesystem::signal_create_mount,
334
+                        MountConfig::MOUNT_TYPE_GROUP,
335
+                        'group1'
336
+                    ],
337
+                    [
338
+                        Filesystem::signal_create_mount,
339
+                        MountConfig::MOUNT_TYPE_GROUP,
340
+                        'group2'
341
+                    ],
342
+                ],
343
+            ],
344
+            [
345
+                // adding a user and a group
346
+                ['user1'],
347
+                ['group1'],
348
+                ['user1', 'user2'],
349
+                ['group1', 'group2'],
350
+                // expected hook calls
351
+                [
352
+                    [
353
+                        Filesystem::signal_create_mount,
354
+                        MountConfig::MOUNT_TYPE_USER,
355
+                        'user2',
356
+                    ],
357
+                    [
358
+                        Filesystem::signal_create_mount,
359
+                        MountConfig::MOUNT_TYPE_GROUP,
360
+                        'group2'
361
+                    ],
362
+                ],
363
+            ],
364
+            [
365
+                // removing a user and a group
366
+                ['user1', 'user2'],
367
+                ['group1', 'group2'],
368
+                ['user1'],
369
+                ['group1'],
370
+                // expected hook calls
371
+                [
372
+                    [
373
+                        Filesystem::signal_delete_mount,
374
+                        MountConfig::MOUNT_TYPE_USER,
375
+                        'user2',
376
+                    ],
377
+                    [
378
+                        Filesystem::signal_delete_mount,
379
+                        MountConfig::MOUNT_TYPE_GROUP,
380
+                        'group2'
381
+                    ],
382
+                ],
383
+            ],
384
+            [
385
+                // removing all
386
+                ['user1'],
387
+                ['group1'],
388
+                [],
389
+                [],
390
+                // expected hook calls
391
+                [
392
+                    [
393
+                        Filesystem::signal_delete_mount,
394
+                        MountConfig::MOUNT_TYPE_USER,
395
+                        'user1',
396
+                    ],
397
+                    [
398
+                        Filesystem::signal_delete_mount,
399
+                        MountConfig::MOUNT_TYPE_GROUP,
400
+                        'group1'
401
+                    ],
402
+                    // create the "all" entry
403
+                    [
404
+                        Filesystem::signal_create_mount,
405
+                        MountConfig::MOUNT_TYPE_USER,
406
+                        'all'
407
+                    ],
408
+                ],
409
+            ],
410
+            [
411
+                // no changes
412
+                ['user1'],
413
+                ['group1'],
414
+                ['user1'],
415
+                ['group1'],
416
+                // no hook calls
417
+                []
418
+            ]
419
+        ];
420
+    }
421
+
422
+    /**
423
+     * @dataProvider hooksUpdateStorageDataProvider
424
+     */
425
+    public function testHooksUpdateStorage(
426
+        array $sourceApplicableUsers,
427
+        array $sourceApplicableGroups,
428
+        array $updatedApplicableUsers,
429
+        array $updatedApplicableGroups,
430
+        array $expectedCalls,
431
+    ): void {
432
+        $storage = $this->makeTestStorageData();
433
+        $storage->setApplicableUsers($sourceApplicableUsers);
434
+        $storage->setApplicableGroups($sourceApplicableGroups);
435
+        $storage = $this->service->addStorage($storage);
436
+
437
+        $storage->setApplicableUsers($updatedApplicableUsers);
438
+        $storage->setApplicableGroups($updatedApplicableGroups);
439
+
440
+        // reset calls
441
+        self::$hookCalls = [];
442
+
443
+        $this->service->updateStorage($storage);
444
+
445
+        $this->assertCount(count($expectedCalls), self::$hookCalls);
446
+
447
+        foreach ($expectedCalls as $index => $call) {
448
+            $this->assertHookCall(
449
+                self::$hookCalls[$index],
450
+                $call[0],
451
+                '/mountpoint',
452
+                $call[1],
453
+                $call[2]
454
+            );
455
+        }
456
+    }
457
+
458
+
459
+    public function testHooksRenameMountPoint(): void {
460
+        $storage = $this->makeTestStorageData();
461
+        $storage->setApplicableUsers(['user1', 'user2']);
462
+        $storage->setApplicableGroups(['group1', 'group2']);
463
+        $storage = $this->service->addStorage($storage);
464
+
465
+        $storage->setMountPoint('renamedMountpoint');
466
+
467
+        // reset calls
468
+        self::$hookCalls = [];
469
+
470
+        $this->service->updateStorage($storage);
471
+
472
+        $expectedCalls = [
473
+            // deletes old mount
474
+            [
475
+                Filesystem::signal_delete_mount,
476
+                '/mountpoint',
477
+                MountConfig::MOUNT_TYPE_USER,
478
+                'user1',
479
+            ],
480
+            [
481
+                Filesystem::signal_delete_mount,
482
+                '/mountpoint',
483
+                MountConfig::MOUNT_TYPE_USER,
484
+                'user2',
485
+            ],
486
+            [
487
+                Filesystem::signal_delete_mount,
488
+                '/mountpoint',
489
+                MountConfig::MOUNT_TYPE_GROUP,
490
+                'group1',
491
+            ],
492
+            [
493
+                Filesystem::signal_delete_mount,
494
+                '/mountpoint',
495
+                MountConfig::MOUNT_TYPE_GROUP,
496
+                'group2',
497
+            ],
498
+            // creates new one
499
+            [
500
+                Filesystem::signal_create_mount,
501
+                '/renamedMountpoint',
502
+                MountConfig::MOUNT_TYPE_USER,
503
+                'user1',
504
+            ],
505
+            [
506
+                Filesystem::signal_create_mount,
507
+                '/renamedMountpoint',
508
+                MountConfig::MOUNT_TYPE_USER,
509
+                'user2',
510
+            ],
511
+            [
512
+                Filesystem::signal_create_mount,
513
+                '/renamedMountpoint',
514
+                MountConfig::MOUNT_TYPE_GROUP,
515
+                'group1',
516
+            ],
517
+            [
518
+                Filesystem::signal_create_mount,
519
+                '/renamedMountpoint',
520
+                MountConfig::MOUNT_TYPE_GROUP,
521
+                'group2',
522
+            ],
523
+        ];
524
+
525
+        $this->assertCount(count($expectedCalls), self::$hookCalls);
526
+
527
+        foreach ($expectedCalls as $index => $call) {
528
+            $this->assertHookCall(
529
+                self::$hookCalls[$index],
530
+                $call[0],
531
+                $call[1],
532
+                $call[2],
533
+                $call[3]
534
+            );
535
+        }
536
+    }
537
+
538
+    public static function hooksDeleteStorageDataProvider(): array {
539
+        return [
540
+            [
541
+                ['user1', 'user2'],
542
+                ['group1', 'group2'],
543
+                // expected hook calls
544
+                [
545
+                    [
546
+                        Filesystem::signal_delete_mount,
547
+                        MountConfig::MOUNT_TYPE_USER,
548
+                        'user1',
549
+                    ],
550
+                    [
551
+                        Filesystem::signal_delete_mount,
552
+                        MountConfig::MOUNT_TYPE_USER,
553
+                        'user2',
554
+                    ],
555
+                    [
556
+                        Filesystem::signal_delete_mount,
557
+                        MountConfig::MOUNT_TYPE_GROUP,
558
+                        'group1'
559
+                    ],
560
+                    [
561
+                        Filesystem::signal_delete_mount,
562
+                        MountConfig::MOUNT_TYPE_GROUP,
563
+                        'group2'
564
+                    ],
565
+                ],
566
+            ],
567
+            [
568
+                // deleting "all" entry
569
+                [],
570
+                [],
571
+                [
572
+                    [
573
+                        Filesystem::signal_delete_mount,
574
+                        MountConfig::MOUNT_TYPE_USER,
575
+                        'all',
576
+                    ],
577
+                ],
578
+            ],
579
+        ];
580
+    }
581
+
582
+    /**
583
+     * @dataProvider hooksDeleteStorageDataProvider
584
+     */
585
+    public function testHooksDeleteStorage(
586
+        array $sourceApplicableUsers,
587
+        array $sourceApplicableGroups,
588
+        array $expectedCalls,
589
+    ): void {
590
+        $storage = $this->makeTestStorageData();
591
+        $storage->setApplicableUsers($sourceApplicableUsers);
592
+        $storage->setApplicableGroups($sourceApplicableGroups);
593
+        $storage = $this->service->addStorage($storage);
594
+
595
+        // reset calls
596
+        self::$hookCalls = [];
597
+
598
+        $this->service->removeStorage($storage->getId());
599
+
600
+        $this->assertCount(count($expectedCalls), self::$hookCalls);
601
+
602
+        foreach ($expectedCalls as $index => $call) {
603
+            $this->assertHookCall(
604
+                self::$hookCalls[$index],
605
+                $call[0],
606
+                '/mountpoint',
607
+                $call[1],
608
+                $call[2]
609
+            );
610
+        }
611
+    }
612 612
 }
Please login to merge, or discard this patch.
apps/files_external/tests/Service/UserStoragesServiceTest.php 1 patch
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -24,170 +24,170 @@
 block discarded – undo
24 24
  * @group DB
25 25
  */
26 26
 class UserStoragesServiceTest extends StoragesServiceTestCase {
27
-	use UserTrait;
28
-
29
-	protected \OC\User\User $user;
30
-
31
-	protected string $userId;
32
-	protected StoragesService $globalStoragesService;
33
-
34
-	protected function setUp(): void {
35
-		parent::setUp();
36
-
37
-		$this->globalStoragesService = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher);
38
-
39
-		$this->userId = $this->getUniqueID('user_');
40
-		$this->createUser($this->userId, $this->userId);
41
-		$this->user = Server::get(IUserManager::class)->get($this->userId);
42
-
43
-		/** @var IUserSession&MockObject $userSession */
44
-		$userSession = $this->createMock(IUserSession::class);
45
-		$userSession
46
-			->expects($this->any())
47
-			->method('getUser')
48
-			->willReturn($this->user);
49
-
50
-		$this->service = new UserStoragesService($this->backendService, $this->dbConfig, $userSession, $this->mountCache, $this->eventDispatcher);
51
-	}
52
-
53
-	private function makeTestStorageData() {
54
-		return $this->makeStorageConfig([
55
-			'mountPoint' => 'mountpoint',
56
-			'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
57
-			'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
58
-			'backendOptions' => [
59
-				'option1' => 'value1',
60
-				'option2' => 'value2',
61
-				'password' => 'testPassword',
62
-			],
63
-			'mountOptions' => [
64
-				'preview' => false,
65
-			]
66
-		]);
67
-	}
68
-
69
-	public function testAddStorage(): void {
70
-		$storage = $this->makeTestStorageData();
71
-
72
-		$newStorage = $this->service->addStorage($storage);
73
-
74
-		$id = $newStorage->getId();
75
-
76
-		$newStorage = $this->service->getStorage($id);
77
-
78
-		$this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint());
79
-		$this->assertEquals($storage->getBackend(), $newStorage->getBackend());
80
-		$this->assertEquals($storage->getAuthMechanism(), $newStorage->getAuthMechanism());
81
-		$this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions());
82
-		$this->assertEquals(0, $newStorage->getStatus());
83
-
84
-		// hook called once for user
85
-		$this->assertHookCall(
86
-			current(self::$hookCalls),
87
-			Filesystem::signal_create_mount,
88
-			$storage->getMountPoint(),
89
-			MountConfig::MOUNT_TYPE_USER,
90
-			$this->userId
91
-		);
92
-
93
-		$nextStorage = $this->service->addStorage($storage);
94
-		$this->assertEquals($id + 1, $nextStorage->getId());
95
-	}
96
-
97
-	public function testUpdateStorage(): void {
98
-		$storage = $this->makeStorageConfig([
99
-			'mountPoint' => 'mountpoint',
100
-			'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
101
-			'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
102
-			'backendOptions' => [
103
-				'option1' => 'value1',
104
-				'option2' => 'value2',
105
-				'password' => 'testPassword',
106
-			],
107
-		]);
108
-
109
-		$newStorage = $this->service->addStorage($storage);
110
-
111
-		$backendOptions = $newStorage->getBackendOptions();
112
-		$backendOptions['password'] = 'anotherPassword';
113
-		$newStorage->setBackendOptions($backendOptions);
114
-
115
-		self::$hookCalls = [];
116
-
117
-		$newStorage = $this->service->updateStorage($newStorage);
118
-
119
-		$this->assertEquals('anotherPassword', $newStorage->getBackendOptions()['password']);
120
-		$this->assertEquals([$this->userId], $newStorage->getApplicableUsers());
121
-		// these attributes are unused for user storages
122
-		$this->assertEmpty($newStorage->getApplicableGroups());
123
-		$this->assertEquals(0, $newStorage->getStatus());
124
-
125
-		// no hook calls
126
-		$this->assertEmpty(self::$hookCalls);
127
-	}
128
-
129
-	/**
130
-	 * @dataProvider deleteStorageDataProvider
131
-	 */
132
-	public function testDeleteStorage($backendOptions, $rustyStorageId): void {
133
-		parent::testDeleteStorage($backendOptions, $rustyStorageId);
134
-
135
-		// hook called once for user (first one was during test creation)
136
-		$this->assertHookCall(
137
-			self::$hookCalls[1],
138
-			Filesystem::signal_delete_mount,
139
-			'/mountpoint',
140
-			MountConfig::MOUNT_TYPE_USER,
141
-			$this->userId
142
-		);
143
-	}
144
-
145
-	public function testHooksRenameMountPoint(): void {
146
-		$storage = $this->makeTestStorageData();
147
-		$storage = $this->service->addStorage($storage);
148
-
149
-		$storage->setMountPoint('renamedMountpoint');
150
-
151
-		// reset calls
152
-		self::$hookCalls = [];
153
-
154
-		$this->service->updateStorage($storage);
155
-
156
-		// hook called twice
157
-		$this->assertHookCall(
158
-			self::$hookCalls[0],
159
-			Filesystem::signal_delete_mount,
160
-			'/mountpoint',
161
-			MountConfig::MOUNT_TYPE_USER,
162
-			$this->userId
163
-		);
164
-		$this->assertHookCall(
165
-			self::$hookCalls[1],
166
-			Filesystem::signal_create_mount,
167
-			'/renamedMountpoint',
168
-			MountConfig::MOUNT_TYPE_USER,
169
-			$this->userId
170
-		);
171
-	}
172
-
173
-
174
-	public function testGetAdminStorage(): void {
175
-		$this->expectException(NotFoundException::class);
176
-
177
-		$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
178
-		$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
179
-
180
-		$storage = new StorageConfig();
181
-		$storage->setMountPoint('mountpoint');
182
-		$storage->setBackend($backend);
183
-		$storage->setAuthMechanism($authMechanism);
184
-		$storage->setBackendOptions(['password' => 'testPassword']);
185
-		$storage->setApplicableUsers([$this->userId]);
186
-
187
-		$newStorage = $this->globalStoragesService->addStorage($storage);
188
-
189
-		$this->assertInstanceOf('\OCA\Files_External\Lib\StorageConfig', $this->globalStoragesService->getStorage($newStorage->getId()));
190
-
191
-		$this->service->getStorage($newStorage->getId());
192
-	}
27
+    use UserTrait;
28
+
29
+    protected \OC\User\User $user;
30
+
31
+    protected string $userId;
32
+    protected StoragesService $globalStoragesService;
33
+
34
+    protected function setUp(): void {
35
+        parent::setUp();
36
+
37
+        $this->globalStoragesService = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher);
38
+
39
+        $this->userId = $this->getUniqueID('user_');
40
+        $this->createUser($this->userId, $this->userId);
41
+        $this->user = Server::get(IUserManager::class)->get($this->userId);
42
+
43
+        /** @var IUserSession&MockObject $userSession */
44
+        $userSession = $this->createMock(IUserSession::class);
45
+        $userSession
46
+            ->expects($this->any())
47
+            ->method('getUser')
48
+            ->willReturn($this->user);
49
+
50
+        $this->service = new UserStoragesService($this->backendService, $this->dbConfig, $userSession, $this->mountCache, $this->eventDispatcher);
51
+    }
52
+
53
+    private function makeTestStorageData() {
54
+        return $this->makeStorageConfig([
55
+            'mountPoint' => 'mountpoint',
56
+            'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
57
+            'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
58
+            'backendOptions' => [
59
+                'option1' => 'value1',
60
+                'option2' => 'value2',
61
+                'password' => 'testPassword',
62
+            ],
63
+            'mountOptions' => [
64
+                'preview' => false,
65
+            ]
66
+        ]);
67
+    }
68
+
69
+    public function testAddStorage(): void {
70
+        $storage = $this->makeTestStorageData();
71
+
72
+        $newStorage = $this->service->addStorage($storage);
73
+
74
+        $id = $newStorage->getId();
75
+
76
+        $newStorage = $this->service->getStorage($id);
77
+
78
+        $this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint());
79
+        $this->assertEquals($storage->getBackend(), $newStorage->getBackend());
80
+        $this->assertEquals($storage->getAuthMechanism(), $newStorage->getAuthMechanism());
81
+        $this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions());
82
+        $this->assertEquals(0, $newStorage->getStatus());
83
+
84
+        // hook called once for user
85
+        $this->assertHookCall(
86
+            current(self::$hookCalls),
87
+            Filesystem::signal_create_mount,
88
+            $storage->getMountPoint(),
89
+            MountConfig::MOUNT_TYPE_USER,
90
+            $this->userId
91
+        );
92
+
93
+        $nextStorage = $this->service->addStorage($storage);
94
+        $this->assertEquals($id + 1, $nextStorage->getId());
95
+    }
96
+
97
+    public function testUpdateStorage(): void {
98
+        $storage = $this->makeStorageConfig([
99
+            'mountPoint' => 'mountpoint',
100
+            'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
101
+            'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
102
+            'backendOptions' => [
103
+                'option1' => 'value1',
104
+                'option2' => 'value2',
105
+                'password' => 'testPassword',
106
+            ],
107
+        ]);
108
+
109
+        $newStorage = $this->service->addStorage($storage);
110
+
111
+        $backendOptions = $newStorage->getBackendOptions();
112
+        $backendOptions['password'] = 'anotherPassword';
113
+        $newStorage->setBackendOptions($backendOptions);
114
+
115
+        self::$hookCalls = [];
116
+
117
+        $newStorage = $this->service->updateStorage($newStorage);
118
+
119
+        $this->assertEquals('anotherPassword', $newStorage->getBackendOptions()['password']);
120
+        $this->assertEquals([$this->userId], $newStorage->getApplicableUsers());
121
+        // these attributes are unused for user storages
122
+        $this->assertEmpty($newStorage->getApplicableGroups());
123
+        $this->assertEquals(0, $newStorage->getStatus());
124
+
125
+        // no hook calls
126
+        $this->assertEmpty(self::$hookCalls);
127
+    }
128
+
129
+    /**
130
+     * @dataProvider deleteStorageDataProvider
131
+     */
132
+    public function testDeleteStorage($backendOptions, $rustyStorageId): void {
133
+        parent::testDeleteStorage($backendOptions, $rustyStorageId);
134
+
135
+        // hook called once for user (first one was during test creation)
136
+        $this->assertHookCall(
137
+            self::$hookCalls[1],
138
+            Filesystem::signal_delete_mount,
139
+            '/mountpoint',
140
+            MountConfig::MOUNT_TYPE_USER,
141
+            $this->userId
142
+        );
143
+    }
144
+
145
+    public function testHooksRenameMountPoint(): void {
146
+        $storage = $this->makeTestStorageData();
147
+        $storage = $this->service->addStorage($storage);
148
+
149
+        $storage->setMountPoint('renamedMountpoint');
150
+
151
+        // reset calls
152
+        self::$hookCalls = [];
153
+
154
+        $this->service->updateStorage($storage);
155
+
156
+        // hook called twice
157
+        $this->assertHookCall(
158
+            self::$hookCalls[0],
159
+            Filesystem::signal_delete_mount,
160
+            '/mountpoint',
161
+            MountConfig::MOUNT_TYPE_USER,
162
+            $this->userId
163
+        );
164
+        $this->assertHookCall(
165
+            self::$hookCalls[1],
166
+            Filesystem::signal_create_mount,
167
+            '/renamedMountpoint',
168
+            MountConfig::MOUNT_TYPE_USER,
169
+            $this->userId
170
+        );
171
+    }
172
+
173
+
174
+    public function testGetAdminStorage(): void {
175
+        $this->expectException(NotFoundException::class);
176
+
177
+        $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
178
+        $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
179
+
180
+        $storage = new StorageConfig();
181
+        $storage->setMountPoint('mountpoint');
182
+        $storage->setBackend($backend);
183
+        $storage->setAuthMechanism($authMechanism);
184
+        $storage->setBackendOptions(['password' => 'testPassword']);
185
+        $storage->setApplicableUsers([$this->userId]);
186
+
187
+        $newStorage = $this->globalStoragesService->addStorage($storage);
188
+
189
+        $this->assertInstanceOf('\OCA\Files_External\Lib\StorageConfig', $this->globalStoragesService->getStorage($newStorage->getId()));
190
+
191
+        $this->service->getStorage($newStorage->getId());
192
+    }
193 193
 }
Please login to merge, or discard this patch.
apps/files_external/tests/Service/DBConfigServiceTest.php 1 patch
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -18,259 +18,259 @@
 block discarded – undo
18 18
  * @group DB
19 19
  */
20 20
 class DBConfigServiceTest extends TestCase {
21
-	private IDBConnection $connection;
22
-	private DBConfigService $dbConfig;
23
-
24
-	private array $mounts = [];
25
-
26
-	protected function setUp(): void {
27
-		parent::setUp();
28
-		$this->connection = Server::get(IDBConnection::class);
29
-		$this->dbConfig = new DBConfigService($this->connection, Server::get(ICrypto::class));
30
-	}
31
-
32
-	protected function tearDown(): void {
33
-		foreach ($this->mounts as $mount) {
34
-			$this->dbConfig->removeMount($mount);
35
-		}
36
-		$this->mounts = [];
37
-		parent::tearDown();
38
-	}
39
-
40
-	private function addMount(string $mountPoint, string $storageBackend, string $authBackend, int $priority, int $type) {
41
-		$id = $this->dbConfig->addMount($mountPoint, $storageBackend, $authBackend, $priority, $type);
42
-		$this->mounts[] = $id;
43
-		return $id;
44
-	}
45
-
46
-	public function testAddSimpleMount(): void {
47
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
48
-
49
-		$mount = $this->dbConfig->getMountById($id);
50
-		$this->assertEquals('/test', $mount['mount_point']);
51
-		$this->assertEquals('foo', $mount['storage_backend']);
52
-		$this->assertEquals('bar', $mount['auth_backend']);
53
-		$this->assertEquals(100, $mount['priority']);
54
-		$this->assertEquals(DBConfigService::MOUNT_TYPE_ADMIN, $mount['type']);
55
-		$this->assertEquals([], $mount['applicable']);
56
-		$this->assertEquals([], $mount['config']);
57
-		$this->assertEquals([], $mount['options']);
58
-	}
59
-
60
-	public function testAddApplicable(): void {
61
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
62
-		$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
63
-
64
-		$mount = $this->dbConfig->getMountById($id);
65
-		$this->assertEquals([
66
-			['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]
67
-		], $mount['applicable']);
68
-
69
-		$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, 'bar');
70
-		$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
71
-
72
-		$mount = $this->dbConfig->getMountById($id);
73
-		$this->assertEquals([
74
-			['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id],
75
-			['type' => DBConfigService::APPLICABLE_TYPE_GROUP, 'value' => 'bar', 'mount_id' => $id],
76
-			['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id]
77
-		], $mount['applicable']);
78
-	}
79
-
80
-	public function testAddApplicableDouble(): void {
81
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
82
-		$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
83
-		$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
84
-
85
-		$mount = $this->dbConfig->getMountById($id);
86
-		$this->assertEquals([
87
-			['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]
88
-		], $mount['applicable']);
89
-	}
90
-
91
-	public function testDeleteMount(): void {
92
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
93
-
94
-		$this->dbConfig->removeMount($id);
95
-
96
-		$mount = $this->dbConfig->getMountById($id);
97
-		$this->assertEquals(null, $mount);
98
-	}
99
-
100
-	public function testRemoveApplicable(): void {
101
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
102
-		$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
103
-		$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
104
-
105
-		$mount = $this->dbConfig->getMountById($id);
106
-		$this->assertEquals([], $mount['applicable']);
107
-	}
108
-
109
-	public function testRemoveApplicableGlobal(): void {
110
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
111
-		$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
112
-		$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
113
-		$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
114
-
115
-		$mount = $this->dbConfig->getMountById($id);
116
-		$this->assertEquals([
117
-			['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]
118
-		], $mount['applicable']);
119
-	}
120
-
121
-	public function testSetConfig(): void {
122
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
123
-		$this->dbConfig->setConfig($id, 'foo', 'bar');
124
-
125
-		$mount = $this->dbConfig->getMountById($id);
126
-		$this->assertEquals(['foo' => 'bar'], $mount['config']);
127
-
128
-		$this->dbConfig->setConfig($id, 'foo2', 'bar2');
129
-
130
-		$mount = $this->dbConfig->getMountById($id);
131
-		$this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['config']);
132
-	}
133
-
134
-	public function testSetConfigOverwrite(): void {
135
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
136
-		$this->dbConfig->setConfig($id, 'foo', 'bar');
137
-		$this->dbConfig->setConfig($id, 'asd', '1');
138
-		$this->dbConfig->setConfig($id, 'foo', 'qwerty');
139
-
140
-		$mount = $this->dbConfig->getMountById($id);
141
-		$this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['config']);
142
-	}
143
-
144
-	public function testSetOption(): void {
145
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
146
-		$this->dbConfig->setOption($id, 'foo', 'bar');
147
-
148
-		$mount = $this->dbConfig->getMountById($id);
149
-		$this->assertEquals(['foo' => 'bar'], $mount['options']);
150
-
151
-		$this->dbConfig->setOption($id, 'foo2', 'bar2');
152
-
153
-		$mount = $this->dbConfig->getMountById($id);
154
-		$this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['options']);
155
-	}
156
-
157
-	public function testSetOptionOverwrite(): void {
158
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
159
-		$this->dbConfig->setOption($id, 'foo', 'bar');
160
-		$this->dbConfig->setOption($id, 'asd', '1');
161
-		$this->dbConfig->setOption($id, 'foo', 'qwerty');
162
-
163
-		$mount = $this->dbConfig->getMountById($id);
164
-		$this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['options']);
165
-	}
166
-
167
-	public function testGetMountsFor(): void {
168
-		$mounts = $this->dbConfig->getMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test');
169
-		$this->assertEquals([], $mounts);
170
-
171
-		$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
172
-		$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
173
-
174
-		$mounts = $this->dbConfig->getMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test');
175
-		$this->assertCount(1, $mounts);
176
-		$this->assertEquals($id, $mounts[0]['mount_id']);
177
-		$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]], $mounts[0]['applicable']);
178
-	}
179
-
180
-	public function testGetAdminMounts(): void {
181
-		$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
182
-		$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
183
-
184
-		$mounts = $this->dbConfig->getAdminMounts();
185
-		$this->assertCount(1, $mounts);
186
-		$this->assertEquals($id1, $mounts[0]['mount_id']);
187
-	}
188
-
189
-	public function testGetAdminMountsFor(): void {
190
-		$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
191
-		$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_ADMIN);
192
-		$id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
21
+    private IDBConnection $connection;
22
+    private DBConfigService $dbConfig;
23
+
24
+    private array $mounts = [];
25
+
26
+    protected function setUp(): void {
27
+        parent::setUp();
28
+        $this->connection = Server::get(IDBConnection::class);
29
+        $this->dbConfig = new DBConfigService($this->connection, Server::get(ICrypto::class));
30
+    }
31
+
32
+    protected function tearDown(): void {
33
+        foreach ($this->mounts as $mount) {
34
+            $this->dbConfig->removeMount($mount);
35
+        }
36
+        $this->mounts = [];
37
+        parent::tearDown();
38
+    }
39
+
40
+    private function addMount(string $mountPoint, string $storageBackend, string $authBackend, int $priority, int $type) {
41
+        $id = $this->dbConfig->addMount($mountPoint, $storageBackend, $authBackend, $priority, $type);
42
+        $this->mounts[] = $id;
43
+        return $id;
44
+    }
45
+
46
+    public function testAddSimpleMount(): void {
47
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
48
+
49
+        $mount = $this->dbConfig->getMountById($id);
50
+        $this->assertEquals('/test', $mount['mount_point']);
51
+        $this->assertEquals('foo', $mount['storage_backend']);
52
+        $this->assertEquals('bar', $mount['auth_backend']);
53
+        $this->assertEquals(100, $mount['priority']);
54
+        $this->assertEquals(DBConfigService::MOUNT_TYPE_ADMIN, $mount['type']);
55
+        $this->assertEquals([], $mount['applicable']);
56
+        $this->assertEquals([], $mount['config']);
57
+        $this->assertEquals([], $mount['options']);
58
+    }
59
+
60
+    public function testAddApplicable(): void {
61
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
62
+        $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
63
+
64
+        $mount = $this->dbConfig->getMountById($id);
65
+        $this->assertEquals([
66
+            ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]
67
+        ], $mount['applicable']);
68
+
69
+        $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, 'bar');
70
+        $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
71
+
72
+        $mount = $this->dbConfig->getMountById($id);
73
+        $this->assertEquals([
74
+            ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id],
75
+            ['type' => DBConfigService::APPLICABLE_TYPE_GROUP, 'value' => 'bar', 'mount_id' => $id],
76
+            ['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id]
77
+        ], $mount['applicable']);
78
+    }
79
+
80
+    public function testAddApplicableDouble(): void {
81
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
82
+        $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
83
+        $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
84
+
85
+        $mount = $this->dbConfig->getMountById($id);
86
+        $this->assertEquals([
87
+            ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]
88
+        ], $mount['applicable']);
89
+    }
90
+
91
+    public function testDeleteMount(): void {
92
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
93
+
94
+        $this->dbConfig->removeMount($id);
95
+
96
+        $mount = $this->dbConfig->getMountById($id);
97
+        $this->assertEquals(null, $mount);
98
+    }
99
+
100
+    public function testRemoveApplicable(): void {
101
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
102
+        $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
103
+        $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
104
+
105
+        $mount = $this->dbConfig->getMountById($id);
106
+        $this->assertEquals([], $mount['applicable']);
107
+    }
108
+
109
+    public function testRemoveApplicableGlobal(): void {
110
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
111
+        $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
112
+        $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
113
+        $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
114
+
115
+        $mount = $this->dbConfig->getMountById($id);
116
+        $this->assertEquals([
117
+            ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]
118
+        ], $mount['applicable']);
119
+    }
120
+
121
+    public function testSetConfig(): void {
122
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
123
+        $this->dbConfig->setConfig($id, 'foo', 'bar');
124
+
125
+        $mount = $this->dbConfig->getMountById($id);
126
+        $this->assertEquals(['foo' => 'bar'], $mount['config']);
127
+
128
+        $this->dbConfig->setConfig($id, 'foo2', 'bar2');
129
+
130
+        $mount = $this->dbConfig->getMountById($id);
131
+        $this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['config']);
132
+    }
133
+
134
+    public function testSetConfigOverwrite(): void {
135
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
136
+        $this->dbConfig->setConfig($id, 'foo', 'bar');
137
+        $this->dbConfig->setConfig($id, 'asd', '1');
138
+        $this->dbConfig->setConfig($id, 'foo', 'qwerty');
139
+
140
+        $mount = $this->dbConfig->getMountById($id);
141
+        $this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['config']);
142
+    }
143
+
144
+    public function testSetOption(): void {
145
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
146
+        $this->dbConfig->setOption($id, 'foo', 'bar');
147
+
148
+        $mount = $this->dbConfig->getMountById($id);
149
+        $this->assertEquals(['foo' => 'bar'], $mount['options']);
150
+
151
+        $this->dbConfig->setOption($id, 'foo2', 'bar2');
152
+
153
+        $mount = $this->dbConfig->getMountById($id);
154
+        $this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['options']);
155
+    }
156
+
157
+    public function testSetOptionOverwrite(): void {
158
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
159
+        $this->dbConfig->setOption($id, 'foo', 'bar');
160
+        $this->dbConfig->setOption($id, 'asd', '1');
161
+        $this->dbConfig->setOption($id, 'foo', 'qwerty');
162
+
163
+        $mount = $this->dbConfig->getMountById($id);
164
+        $this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['options']);
165
+    }
166
+
167
+    public function testGetMountsFor(): void {
168
+        $mounts = $this->dbConfig->getMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test');
169
+        $this->assertEquals([], $mounts);
170
+
171
+        $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
172
+        $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
173
+
174
+        $mounts = $this->dbConfig->getMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test');
175
+        $this->assertCount(1, $mounts);
176
+        $this->assertEquals($id, $mounts[0]['mount_id']);
177
+        $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]], $mounts[0]['applicable']);
178
+    }
179
+
180
+    public function testGetAdminMounts(): void {
181
+        $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
182
+        $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
183
+
184
+        $mounts = $this->dbConfig->getAdminMounts();
185
+        $this->assertCount(1, $mounts);
186
+        $this->assertEquals($id1, $mounts[0]['mount_id']);
187
+    }
188
+
189
+    public function testGetAdminMountsFor(): void {
190
+        $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
191
+        $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_ADMIN);
192
+        $id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
193 193
 
194
-		$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_USER, 'test');
195
-		$this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_USER, 'test');
196
-
197
-		$mounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test');
198
-		$this->assertCount(1, $mounts);
199
-		$this->assertEquals($id1, $mounts[0]['mount_id']);
200
-		$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id1]], $mounts[0]['applicable']);
201
-	}
202
-
203
-	public function testGetUserMountsFor(): void {
204
-		$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
205
-		$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
206
-		$id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
207
-
208
-		$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_USER, 'test');
209
-		$this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_USER, 'test');
210
-
211
-		$mounts = $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test');
212
-		$this->assertCount(1, $mounts);
213
-		$this->assertEquals($id3, $mounts[0]['mount_id']);
214
-		$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id3]], $mounts[0]['applicable']);
215
-	}
216
-
217
-	public function testGetAdminMountsForGlobal(): void {
218
-		$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
194
+        $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_USER, 'test');
195
+        $this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_USER, 'test');
196
+
197
+        $mounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test');
198
+        $this->assertCount(1, $mounts);
199
+        $this->assertEquals($id1, $mounts[0]['mount_id']);
200
+        $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id1]], $mounts[0]['applicable']);
201
+    }
202
+
203
+    public function testGetUserMountsFor(): void {
204
+        $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
205
+        $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
206
+        $id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
207
+
208
+        $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_USER, 'test');
209
+        $this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_USER, 'test');
210
+
211
+        $mounts = $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test');
212
+        $this->assertCount(1, $mounts);
213
+        $this->assertEquals($id3, $mounts[0]['mount_id']);
214
+        $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id3]], $mounts[0]['applicable']);
215
+    }
216
+
217
+    public function testGetAdminMountsForGlobal(): void {
218
+        $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
219 219
 
220
-		$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
220
+        $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
221 221
 
222
-		$mounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
223
-		$this->assertCount(1, $mounts);
224
-		$this->assertEquals($id1, $mounts[0]['mount_id']);
225
-		$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id1]], $mounts[0]['applicable']);
226
-	}
222
+        $mounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
223
+        $this->assertCount(1, $mounts);
224
+        $this->assertEquals($id1, $mounts[0]['mount_id']);
225
+        $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id1]], $mounts[0]['applicable']);
226
+    }
227 227
 
228
-	public function testSetMountPoint(): void {
229
-		$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
230
-		$id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
231
-
232
-		$this->dbConfig->setMountPoint($id1, '/asd');
228
+    public function testSetMountPoint(): void {
229
+        $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
230
+        $id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
231
+
232
+        $this->dbConfig->setMountPoint($id1, '/asd');
233 233
 
234
-		$mount = $this->dbConfig->getMountById($id1);
235
-		$this->assertEquals('/asd', $mount['mount_point']);
236
-
237
-		// remains unchanged
238
-		$mount = $this->dbConfig->getMountById($id2);
239
-		$this->assertEquals('/foo', $mount['mount_point']);
240
-	}
234
+        $mount = $this->dbConfig->getMountById($id1);
235
+        $this->assertEquals('/asd', $mount['mount_point']);
236
+
237
+        // remains unchanged
238
+        $mount = $this->dbConfig->getMountById($id2);
239
+        $this->assertEquals('/foo', $mount['mount_point']);
240
+    }
241 241
 
242
-	public function testSetAuthBackend(): void {
243
-		$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
244
-		$id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
242
+    public function testSetAuthBackend(): void {
243
+        $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
244
+        $id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
245 245
 
246
-		$this->dbConfig->setAuthBackend($id1, 'none');
246
+        $this->dbConfig->setAuthBackend($id1, 'none');
247 247
 
248
-		$mount = $this->dbConfig->getMountById($id1);
249
-		$this->assertEquals('none', $mount['auth_backend']);
248
+        $mount = $this->dbConfig->getMountById($id1);
249
+        $this->assertEquals('none', $mount['auth_backend']);
250 250
 
251
-		// remains unchanged
252
-		$mount = $this->dbConfig->getMountById($id2);
253
-		$this->assertEquals('bar', $mount['auth_backend']);
254
-	}
255
-
256
-	public function testGetMountsForDuplicateByGroup(): void {
257
-		$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
258
-
259
-		$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group1');
260
-		$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group2');
251
+        // remains unchanged
252
+        $mount = $this->dbConfig->getMountById($id2);
253
+        $this->assertEquals('bar', $mount['auth_backend']);
254
+    }
255
+
256
+    public function testGetMountsForDuplicateByGroup(): void {
257
+        $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
258
+
259
+        $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group1');
260
+        $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group2');
261 261
 
262
-		$mounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, ['group1', 'group2']);
263
-		$this->assertCount(1, $mounts);
264
-		$this->assertEquals($id1, $mounts[0]['mount_id']);
265
-	}
262
+        $mounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, ['group1', 'group2']);
263
+        $this->assertCount(1, $mounts);
264
+        $this->assertEquals($id1, $mounts[0]['mount_id']);
265
+    }
266 266
 
267
-	public function testGetAllMounts(): void {
268
-		$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
269
-		$id2 = $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
267
+    public function testGetAllMounts(): void {
268
+        $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
269
+        $id2 = $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
270 270
 
271
-		$mounts = $this->dbConfig->getAllMounts();
272
-		$this->assertCount(2, $mounts);
273
-		$this->assertEquals($id1, $mounts[0]['mount_id']);
274
-		$this->assertEquals($id2, $mounts[1]['mount_id']);
275
-	}
271
+        $mounts = $this->dbConfig->getAllMounts();
272
+        $this->assertCount(2, $mounts);
273
+        $this->assertEquals($id1, $mounts[0]['mount_id']);
274
+        $this->assertEquals($id2, $mounts[1]['mount_id']);
275
+    }
276 276
 }
Please login to merge, or discard this patch.
apps/files_external/tests/Service/BackendServiceTest.php 2 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -16,230 +16,230 @@
 block discarded – undo
16 16
 use PHPUnit\Framework\MockObject\MockObject;
17 17
 
18 18
 class BackendServiceTest extends \Test\TestCase {
19
-	protected IAppConfig&MockObject $appConfig;
20
-
21
-	protected function setUp(): void {
22
-		$this->appConfig = $this->createMock(IAppConfig::class);
23
-	}
24
-
25
-	/**
26
-	 * @return \OCA\Files_External\Lib\Backend\Backend&MockObject
27
-	 */
28
-	protected function getBackendMock(string $class) {
29
-		$backend = $this->createMock(Backend::class);
30
-		$backend->method('getIdentifier')->willReturn('identifier:' . $class);
31
-		$backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]);
32
-		return $backend;
33
-	}
34
-
35
-	/**
36
-	 * @param string $class
37
-	 *
38
-	 * @return AuthMechanism&MockObject
39
-	 */
40
-	protected function getAuthMechanismMock($class) {
41
-		$backend = $this->createMock(AuthMechanism::class);
42
-		$backend->method('getIdentifier')->willReturn('identifier:' . $class);
43
-		$backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]);
44
-		return $backend;
45
-	}
46
-
47
-	public function testRegisterBackend(): void {
48
-		$service = new BackendService($this->appConfig);
49
-
50
-		$backend = $this->getBackendMock('\Foo\Bar');
51
-
52
-		/** @var \OCA\Files_External\Lib\Backend\Backend&MockObject $backendAlias */
53
-		$backendAlias = $this->createMock(Backend::class);
54
-		$backendAlias->method('getIdentifierAliases')
55
-			->willReturn(['identifier_real', 'identifier_alias']);
56
-		$backendAlias->method('getIdentifier')
57
-			->willReturn('identifier_real');
58
-
59
-		$service->registerBackend($backend);
60
-		$service->registerBackend($backendAlias);
61
-
62
-		$this->assertEquals($backend, $service->getBackend('identifier:\Foo\Bar'));
63
-		$this->assertEquals($backendAlias, $service->getBackend('identifier_real'));
64
-		$this->assertEquals($backendAlias, $service->getBackend('identifier_alias'));
65
-
66
-		$backends = $service->getBackends();
67
-		$this->assertCount(2, $backends);
68
-		$this->assertArrayHasKey('identifier:\Foo\Bar', $backends);
69
-		$this->assertArrayHasKey('identifier_real', $backends);
70
-		$this->assertArrayNotHasKey('identifier_alias', $backends);
71
-	}
72
-
73
-	public function testBackendProvider(): void {
74
-		$service = new BackendService($this->appConfig);
75
-
76
-		$backend1 = $this->getBackendMock('\Foo\Bar');
77
-		$backend2 = $this->getBackendMock('\Bar\Foo');
78
-
79
-		/** @var IBackendProvider&MockObject $providerMock */
80
-		$providerMock = $this->createMock(IBackendProvider::class);
81
-		$providerMock->expects($this->once())
82
-			->method('getBackends')
83
-			->willReturn([$backend1, $backend2]);
84
-		$service->registerBackendProvider($providerMock);
85
-
86
-		$this->assertEquals($backend1, $service->getBackend('identifier:\Foo\Bar'));
87
-		$this->assertEquals($backend2, $service->getBackend('identifier:\Bar\Foo'));
88
-
89
-		$this->assertCount(2, $service->getBackends());
90
-	}
91
-
92
-	public function testAuthMechanismProvider(): void {
93
-		$service = new BackendService($this->appConfig);
94
-
95
-		$backend1 = $this->getAuthMechanismMock('\Foo\Bar');
96
-		$backend2 = $this->getAuthMechanismMock('\Bar\Foo');
97
-
98
-		/** @var IAuthMechanismProvider&MockObject $providerMock */
99
-		$providerMock = $this->createMock(IAuthMechanismProvider::class);
100
-		$providerMock->expects($this->once())
101
-			->method('getAuthMechanisms')
102
-			->willReturn([$backend1, $backend2]);
103
-		$service->registerAuthMechanismProvider($providerMock);
104
-
105
-		$this->assertEquals($backend1, $service->getAuthMechanism('identifier:\Foo\Bar'));
106
-		$this->assertEquals($backend2, $service->getAuthMechanism('identifier:\Bar\Foo'));
107
-
108
-		$this->assertCount(2, $service->getAuthMechanisms());
109
-	}
110
-
111
-	public function testMultipleBackendProviders(): void {
112
-		$service = new BackendService($this->appConfig);
113
-
114
-		$backend1a = $this->getBackendMock('\Foo\Bar');
115
-		$backend1b = $this->getBackendMock('\Bar\Foo');
116
-
117
-		$backend2 = $this->getBackendMock('\Dead\Beef');
118
-
119
-		/** @var IBackendProvider&MockObject $provider1Mock */
120
-		$provider1Mock = $this->createMock(IBackendProvider::class);
121
-		$provider1Mock->expects($this->once())
122
-			->method('getBackends')
123
-			->willReturn([$backend1a, $backend1b]);
124
-		$service->registerBackendProvider($provider1Mock);
125
-		/** @var IBackendProvider&MockObject $provider2Mock */
126
-		$provider2Mock = $this->createMock(IBackendProvider::class);
127
-		$provider2Mock->expects($this->once())
128
-			->method('getBackends')
129
-			->willReturn([$backend2]);
130
-		$service->registerBackendProvider($provider2Mock);
131
-
132
-		$this->assertEquals($backend1a, $service->getBackend('identifier:\Foo\Bar'));
133
-		$this->assertEquals($backend1b, $service->getBackend('identifier:\Bar\Foo'));
134
-		$this->assertEquals($backend2, $service->getBackend('identifier:\Dead\Beef'));
135
-
136
-		$this->assertCount(3, $service->getBackends());
137
-	}
138
-
139
-	public function testUserMountingBackends(): void {
140
-		$this->appConfig->expects($this->once())
141
-			->method('getValueString')
142
-			->with('files_external', 'user_mounting_backends')
143
-			->willReturn('identifier:\User\Mount\Allowed,identifier_alias');
144
-		$this->appConfig->expects($this->once())
145
-			->method('getValueBool')
146
-			->with('files_external', 'allow_user_mounting')
147
-			->willReturn(true);
148
-
149
-		$service = new BackendService($this->appConfig);
150
-
151
-		$backendAllowed = $this->getBackendMock('\User\Mount\Allowed');
152
-		$backendAllowed->expects($this->never())
153
-			->method('removeVisibility');
154
-		$backendNotAllowed = $this->getBackendMock('\User\Mount\NotAllowed');
155
-		$backendNotAllowed->expects($this->once())
156
-			->method('removeVisibility')
157
-			->with(BackendService::VISIBILITY_PERSONAL);
158
-
159
-		$backendAlias = $this->getMockBuilder(Backend::class)
160
-			->disableOriginalConstructor()
161
-			->getMock();
162
-		$backendAlias->method('getIdentifierAliases')
163
-			->willReturn(['identifier_real', 'identifier_alias']);
164
-		$backendAlias->expects($this->never())
165
-			->method('removeVisibility');
166
-
167
-		$service->registerBackend($backendAllowed);
168
-		$service->registerBackend($backendNotAllowed);
169
-		$service->registerBackend($backendAlias);
170
-	}
171
-
172
-	public function testGetAvailableBackends(): void {
173
-		$service = new BackendService($this->appConfig);
174
-
175
-		$backendAvailable = $this->getBackendMock('\Backend\Available');
176
-		$backendAvailable->expects($this->once())
177
-			->method('checkDependencies')
178
-			->willReturn([]);
179
-		$backendNotAvailable = $this->getBackendMock('\Backend\NotAvailable');
180
-		$backendNotAvailable->expects($this->once())
181
-			->method('checkDependencies')
182
-			->willReturn([
183
-				$this->getMockBuilder('\OCA\Files_External\Lib\MissingDependency')
184
-					->disableOriginalConstructor()
185
-					->getMock()
186
-			]);
187
-
188
-		$service->registerBackend($backendAvailable);
189
-		$service->registerBackend($backendNotAvailable);
190
-
191
-		$availableBackends = $service->getAvailableBackends();
192
-		$this->assertArrayHasKey('identifier:\Backend\Available', $availableBackends);
193
-		$this->assertArrayNotHasKey('identifier:\Backend\NotAvailable', $availableBackends);
194
-	}
195
-
196
-	public static function invalidConfigPlaceholderProvider(): array {
197
-		return [
198
-			[['@user']],
199
-			[['$user']],
200
-			[['hællo']],
201
-			[['spa ce']],
202
-			[['yo\o']],
203
-			[['<script>…</script>']],
204
-			[['xxyoloxx', 'invÆlid']],
205
-			[['tautology', 'tautology']],
206
-			[['tautology2', 'TAUTOLOGY2']],
207
-		];
208
-	}
209
-
210
-	/**
211
-	 * @dataProvider invalidConfigPlaceholderProvider
212
-	 */
213
-	public function testRegisterConfigHandlerInvalid(array $placeholders): void {
214
-		$this->expectException(\RuntimeException::class);
215
-
216
-		$service = new BackendService($this->appConfig);
217
-		$mock = $this->createMock(IConfigHandler::class);
218
-		$cb = function () use ($mock) {
219
-			return $mock;
220
-		};
221
-		foreach ($placeholders as $placeholder) {
222
-			$service->registerConfigHandler($placeholder, $cb);
223
-		}
224
-	}
225
-
226
-	public function testConfigHandlers(): void {
227
-		$service = new BackendService($this->appConfig);
228
-		$mock = $this->createMock(IConfigHandler::class);
229
-		$mock->expects($this->exactly(3))
230
-			->method('handle');
231
-		$cb = function () use ($mock) {
232
-			return $mock;
233
-		};
234
-		$service->registerConfigHandler('one', $cb);
235
-		$service->registerConfigHandler('2', $cb);
236
-		$service->registerConfigHandler('Three', $cb);
237
-
238
-		/** @var IConfigHandler[] $handlers */
239
-		$handlers = $service->getConfigHandlers();
240
-
241
-		foreach ($handlers as $handler) {
242
-			$handler->handle('Something');
243
-		}
244
-	}
19
+    protected IAppConfig&MockObject $appConfig;
20
+
21
+    protected function setUp(): void {
22
+        $this->appConfig = $this->createMock(IAppConfig::class);
23
+    }
24
+
25
+    /**
26
+     * @return \OCA\Files_External\Lib\Backend\Backend&MockObject
27
+     */
28
+    protected function getBackendMock(string $class) {
29
+        $backend = $this->createMock(Backend::class);
30
+        $backend->method('getIdentifier')->willReturn('identifier:' . $class);
31
+        $backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]);
32
+        return $backend;
33
+    }
34
+
35
+    /**
36
+     * @param string $class
37
+     *
38
+     * @return AuthMechanism&MockObject
39
+     */
40
+    protected function getAuthMechanismMock($class) {
41
+        $backend = $this->createMock(AuthMechanism::class);
42
+        $backend->method('getIdentifier')->willReturn('identifier:' . $class);
43
+        $backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]);
44
+        return $backend;
45
+    }
46
+
47
+    public function testRegisterBackend(): void {
48
+        $service = new BackendService($this->appConfig);
49
+
50
+        $backend = $this->getBackendMock('\Foo\Bar');
51
+
52
+        /** @var \OCA\Files_External\Lib\Backend\Backend&MockObject $backendAlias */
53
+        $backendAlias = $this->createMock(Backend::class);
54
+        $backendAlias->method('getIdentifierAliases')
55
+            ->willReturn(['identifier_real', 'identifier_alias']);
56
+        $backendAlias->method('getIdentifier')
57
+            ->willReturn('identifier_real');
58
+
59
+        $service->registerBackend($backend);
60
+        $service->registerBackend($backendAlias);
61
+
62
+        $this->assertEquals($backend, $service->getBackend('identifier:\Foo\Bar'));
63
+        $this->assertEquals($backendAlias, $service->getBackend('identifier_real'));
64
+        $this->assertEquals($backendAlias, $service->getBackend('identifier_alias'));
65
+
66
+        $backends = $service->getBackends();
67
+        $this->assertCount(2, $backends);
68
+        $this->assertArrayHasKey('identifier:\Foo\Bar', $backends);
69
+        $this->assertArrayHasKey('identifier_real', $backends);
70
+        $this->assertArrayNotHasKey('identifier_alias', $backends);
71
+    }
72
+
73
+    public function testBackendProvider(): void {
74
+        $service = new BackendService($this->appConfig);
75
+
76
+        $backend1 = $this->getBackendMock('\Foo\Bar');
77
+        $backend2 = $this->getBackendMock('\Bar\Foo');
78
+
79
+        /** @var IBackendProvider&MockObject $providerMock */
80
+        $providerMock = $this->createMock(IBackendProvider::class);
81
+        $providerMock->expects($this->once())
82
+            ->method('getBackends')
83
+            ->willReturn([$backend1, $backend2]);
84
+        $service->registerBackendProvider($providerMock);
85
+
86
+        $this->assertEquals($backend1, $service->getBackend('identifier:\Foo\Bar'));
87
+        $this->assertEquals($backend2, $service->getBackend('identifier:\Bar\Foo'));
88
+
89
+        $this->assertCount(2, $service->getBackends());
90
+    }
91
+
92
+    public function testAuthMechanismProvider(): void {
93
+        $service = new BackendService($this->appConfig);
94
+
95
+        $backend1 = $this->getAuthMechanismMock('\Foo\Bar');
96
+        $backend2 = $this->getAuthMechanismMock('\Bar\Foo');
97
+
98
+        /** @var IAuthMechanismProvider&MockObject $providerMock */
99
+        $providerMock = $this->createMock(IAuthMechanismProvider::class);
100
+        $providerMock->expects($this->once())
101
+            ->method('getAuthMechanisms')
102
+            ->willReturn([$backend1, $backend2]);
103
+        $service->registerAuthMechanismProvider($providerMock);
104
+
105
+        $this->assertEquals($backend1, $service->getAuthMechanism('identifier:\Foo\Bar'));
106
+        $this->assertEquals($backend2, $service->getAuthMechanism('identifier:\Bar\Foo'));
107
+
108
+        $this->assertCount(2, $service->getAuthMechanisms());
109
+    }
110
+
111
+    public function testMultipleBackendProviders(): void {
112
+        $service = new BackendService($this->appConfig);
113
+
114
+        $backend1a = $this->getBackendMock('\Foo\Bar');
115
+        $backend1b = $this->getBackendMock('\Bar\Foo');
116
+
117
+        $backend2 = $this->getBackendMock('\Dead\Beef');
118
+
119
+        /** @var IBackendProvider&MockObject $provider1Mock */
120
+        $provider1Mock = $this->createMock(IBackendProvider::class);
121
+        $provider1Mock->expects($this->once())
122
+            ->method('getBackends')
123
+            ->willReturn([$backend1a, $backend1b]);
124
+        $service->registerBackendProvider($provider1Mock);
125
+        /** @var IBackendProvider&MockObject $provider2Mock */
126
+        $provider2Mock = $this->createMock(IBackendProvider::class);
127
+        $provider2Mock->expects($this->once())
128
+            ->method('getBackends')
129
+            ->willReturn([$backend2]);
130
+        $service->registerBackendProvider($provider2Mock);
131
+
132
+        $this->assertEquals($backend1a, $service->getBackend('identifier:\Foo\Bar'));
133
+        $this->assertEquals($backend1b, $service->getBackend('identifier:\Bar\Foo'));
134
+        $this->assertEquals($backend2, $service->getBackend('identifier:\Dead\Beef'));
135
+
136
+        $this->assertCount(3, $service->getBackends());
137
+    }
138
+
139
+    public function testUserMountingBackends(): void {
140
+        $this->appConfig->expects($this->once())
141
+            ->method('getValueString')
142
+            ->with('files_external', 'user_mounting_backends')
143
+            ->willReturn('identifier:\User\Mount\Allowed,identifier_alias');
144
+        $this->appConfig->expects($this->once())
145
+            ->method('getValueBool')
146
+            ->with('files_external', 'allow_user_mounting')
147
+            ->willReturn(true);
148
+
149
+        $service = new BackendService($this->appConfig);
150
+
151
+        $backendAllowed = $this->getBackendMock('\User\Mount\Allowed');
152
+        $backendAllowed->expects($this->never())
153
+            ->method('removeVisibility');
154
+        $backendNotAllowed = $this->getBackendMock('\User\Mount\NotAllowed');
155
+        $backendNotAllowed->expects($this->once())
156
+            ->method('removeVisibility')
157
+            ->with(BackendService::VISIBILITY_PERSONAL);
158
+
159
+        $backendAlias = $this->getMockBuilder(Backend::class)
160
+            ->disableOriginalConstructor()
161
+            ->getMock();
162
+        $backendAlias->method('getIdentifierAliases')
163
+            ->willReturn(['identifier_real', 'identifier_alias']);
164
+        $backendAlias->expects($this->never())
165
+            ->method('removeVisibility');
166
+
167
+        $service->registerBackend($backendAllowed);
168
+        $service->registerBackend($backendNotAllowed);
169
+        $service->registerBackend($backendAlias);
170
+    }
171
+
172
+    public function testGetAvailableBackends(): void {
173
+        $service = new BackendService($this->appConfig);
174
+
175
+        $backendAvailable = $this->getBackendMock('\Backend\Available');
176
+        $backendAvailable->expects($this->once())
177
+            ->method('checkDependencies')
178
+            ->willReturn([]);
179
+        $backendNotAvailable = $this->getBackendMock('\Backend\NotAvailable');
180
+        $backendNotAvailable->expects($this->once())
181
+            ->method('checkDependencies')
182
+            ->willReturn([
183
+                $this->getMockBuilder('\OCA\Files_External\Lib\MissingDependency')
184
+                    ->disableOriginalConstructor()
185
+                    ->getMock()
186
+            ]);
187
+
188
+        $service->registerBackend($backendAvailable);
189
+        $service->registerBackend($backendNotAvailable);
190
+
191
+        $availableBackends = $service->getAvailableBackends();
192
+        $this->assertArrayHasKey('identifier:\Backend\Available', $availableBackends);
193
+        $this->assertArrayNotHasKey('identifier:\Backend\NotAvailable', $availableBackends);
194
+    }
195
+
196
+    public static function invalidConfigPlaceholderProvider(): array {
197
+        return [
198
+            [['@user']],
199
+            [['$user']],
200
+            [['hællo']],
201
+            [['spa ce']],
202
+            [['yo\o']],
203
+            [['<script>…</script>']],
204
+            [['xxyoloxx', 'invÆlid']],
205
+            [['tautology', 'tautology']],
206
+            [['tautology2', 'TAUTOLOGY2']],
207
+        ];
208
+    }
209
+
210
+    /**
211
+     * @dataProvider invalidConfigPlaceholderProvider
212
+     */
213
+    public function testRegisterConfigHandlerInvalid(array $placeholders): void {
214
+        $this->expectException(\RuntimeException::class);
215
+
216
+        $service = new BackendService($this->appConfig);
217
+        $mock = $this->createMock(IConfigHandler::class);
218
+        $cb = function () use ($mock) {
219
+            return $mock;
220
+        };
221
+        foreach ($placeholders as $placeholder) {
222
+            $service->registerConfigHandler($placeholder, $cb);
223
+        }
224
+    }
225
+
226
+    public function testConfigHandlers(): void {
227
+        $service = new BackendService($this->appConfig);
228
+        $mock = $this->createMock(IConfigHandler::class);
229
+        $mock->expects($this->exactly(3))
230
+            ->method('handle');
231
+        $cb = function () use ($mock) {
232
+            return $mock;
233
+        };
234
+        $service->registerConfigHandler('one', $cb);
235
+        $service->registerConfigHandler('2', $cb);
236
+        $service->registerConfigHandler('Three', $cb);
237
+
238
+        /** @var IConfigHandler[] $handlers */
239
+        $handlers = $service->getConfigHandlers();
240
+
241
+        foreach ($handlers as $handler) {
242
+            $handler->handle('Something');
243
+        }
244
+    }
245 245
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	protected function getBackendMock(string $class) {
29 29
 		$backend = $this->createMock(Backend::class);
30
-		$backend->method('getIdentifier')->willReturn('identifier:' . $class);
31
-		$backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]);
30
+		$backend->method('getIdentifier')->willReturn('identifier:'.$class);
31
+		$backend->method('getIdentifierAliases')->willReturn(['identifier:'.$class]);
32 32
 		return $backend;
33 33
 	}
34 34
 
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	protected function getAuthMechanismMock($class) {
41 41
 		$backend = $this->createMock(AuthMechanism::class);
42
-		$backend->method('getIdentifier')->willReturn('identifier:' . $class);
43
-		$backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]);
42
+		$backend->method('getIdentifier')->willReturn('identifier:'.$class);
43
+		$backend->method('getIdentifierAliases')->willReturn(['identifier:'.$class]);
44 44
 		return $backend;
45 45
 	}
46 46
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 
216 216
 		$service = new BackendService($this->appConfig);
217 217
 		$mock = $this->createMock(IConfigHandler::class);
218
-		$cb = function () use ($mock) {
218
+		$cb = function() use ($mock) {
219 219
 			return $mock;
220 220
 		};
221 221
 		foreach ($placeholders as $placeholder) {
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 		$mock = $this->createMock(IConfigHandler::class);
229 229
 		$mock->expects($this->exactly(3))
230 230
 			->method('handle');
231
-		$cb = function () use ($mock) {
231
+		$cb = function() use ($mock) {
232 232
 			return $mock;
233 233
 		};
234 234
 		$service->registerConfigHandler('one', $cb);
Please login to merge, or discard this patch.