2020 */
2121namespace Test \Files \External ;
2222
23+ use OC \Files \External \StoragesBackendChecker ;
2324use OC \Files \External \StoragesBackendService ;
2425use OCP \Files \External \IStoragesBackendService ;
26+ use OCP \Files \External \Backend \Backend ;
2527use OCP \IConfig ;
2628use PHPUnit \Framework \MockObject \MockObject ;
2729
2830class StoragesBackendServiceTest extends \Test \TestCase {
2931 /** @var \OCP\IConfig */
30- protected $ config ;
32+ //protected $config;
33+ /** @var StoragesBackendChecker */
34+ protected $ storagesBackendChecker ;
3135
3236 protected function setUp (): void {
37+ $ this ->storagesBackendChecker = $ this ->createMock (StoragesBackendChecker::class);
38+ $ this ->storagesBackendChecker ->method ('isUserMountingAllowed ' )->willReturn (false );
39+ $ this ->storagesBackendChecker ->method ('isAllowedUserBackend ' )->willReturn (false );
40+ /*
3341 $this->config = $this->createMock('\OCP\IConfig');
3442 $this->config
3543 ->method('getAppValue')
3644 ->willReturnMap([
3745 ['files_external', 'user_mounting_backends', '', '']
3846 ]);
47+ */
3948 }
4049
4150 /**
@@ -67,7 +76,7 @@ protected function getAuthMechanismMock($class) {
6776 }
6877
6978 public function testRegisterBackend () {
70- $ service = new StoragesBackendService ($ this ->config );
79+ $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
7180
7281 $ backend = $ this ->getBackendMock ('\Foo\Bar ' );
7382
@@ -94,7 +103,7 @@ public function testRegisterBackend() {
94103 }
95104
96105 public function testBackendProvider () {
97- $ service = new StoragesBackendService ($ this ->config );
106+ $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
98107
99108 $ backend1 = $ this ->getBackendMock ('\Foo\Bar ' );
100109 $ backend2 = $ this ->getBackendMock ('\Bar\Foo ' );
@@ -112,7 +121,7 @@ public function testBackendProvider() {
112121 }
113122
114123 public function testAuthMechanismProvider () {
115- $ service = new StoragesBackendService ($ this ->config );
124+ $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
116125
117126 $ backend1 = $ this ->getAuthMechanismMock ('\Foo\Bar ' );
118127 $ backend2 = $ this ->getAuthMechanismMock ('\Bar\Foo ' );
@@ -130,7 +139,7 @@ public function testAuthMechanismProvider() {
130139 }
131140
132141 public function testMultipleBackendProviders () {
133- $ service = new StoragesBackendService ($ this ->config );
142+ $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
134143
135144 $ backend1a = $ this ->getBackendMock ('\Foo\Bar ' );
136145 $ backend1b = $ this ->getBackendMock ('\Bar\Foo ' );
@@ -156,15 +165,26 @@ public function testMultipleBackendProviders() {
156165 }
157166
158167 public function testUserMountingBackends () {
168+ $ storagesBackendChecker = $ this ->createMock (StoragesBackendChecker::class);
169+ $ storagesBackendChecker ->method ('isUserMountingAllowed ' )->willReturn (true );
170+ $ storagesBackendChecker ->method ('isAllowedUserBackend ' )->willReturnCallback (function (Backend $ backend ) {
171+ $ backendAliases = $ backend ->getIdentifierAliases ();
172+ if (\in_array ('identifier:\User\Mount\Allowed ' , $ backendAliases , true ) || \in_array ('identifier_alias ' , $ backendAliases , true )) {
173+ return true ;
174+ }
175+ return false ;
176+ });
177+ /*
159178 $config = $this->createMock(IConfig::class);
160179 $config->expects($this->exactly(2))
161180 ->method('getAppValue')
162181 ->willReturnMap([
163182 ['files_external', 'allow_user_mounting', 'no', 'yes'],
164183 ['files_external', 'user_mounting_backends', '', 'identifier:\User\Mount\Allowed,identifier_alias']
165184 ]);
185+ */
166186
167- $ service = new StoragesBackendService ($ config );
187+ $ service = new StoragesBackendService ($ storagesBackendChecker );
168188
169189 $ backendAllowed = $ this ->getBackendMock ('\User\Mount\Allowed ' );
170190 $ backendAllowed ->expects ($ this ->never ())
@@ -188,7 +208,7 @@ public function testUserMountingBackends() {
188208 }
189209
190210 public function testGetAvailableBackends () {
191- $ service = new StoragesBackendService ($ this ->config );
211+ $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
192212
193213 $ backendAvailable = $ this ->getBackendMock ('\Backend\Available ' );
194214 $ backendAvailable ->expects ($ this ->once ())
0 commit comments