|
35 | 35 | use OCA\FederatedFileSharing\FederatedShareProvider; |
36 | 36 | use OCA\FederatedFileSharing\Notifications; |
37 | 37 | use OCA\FederatedFileSharing\TokenHandler; |
| 38 | +use OCP\Contacts\IManager as IContactsManager; |
38 | 39 | use OCP\Federation\ICloudFederationProviderManager; |
39 | 40 | use OCP\Federation\ICloudIdManager; |
40 | 41 | use OCP\Files\File; |
@@ -79,6 +80,8 @@ class FederatedShareProviderTest extends \Test\TestCase { |
79 | 80 | protected $shareManager; |
80 | 81 | /** @var FederatedShareProvider */ |
81 | 82 | protected $provider; |
| 83 | + /** @var IContactsManager|\PHPUnit\Framework\MockObject\MockObject */ |
| 84 | + protected $contactsManager; |
82 | 85 |
|
83 | 86 | /** @var ICloudIdManager */ |
84 | 87 | private $cloudIdManager; |
@@ -107,7 +110,8 @@ protected function setUp(): void { |
107 | 110 | $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock(); |
108 | 111 | //$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l); |
109 | 112 | $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')->disableOriginalConstructor()->getMock(); |
110 | | - $this->cloudIdManager = new CloudIdManager(); |
| 113 | + $this->contactsManager = $this->createMock(IContactsManager::class); |
| 114 | + $this->cloudIdManager = new CloudIdManager($this->contactsManager); |
111 | 115 | $this->gsConfig = $this->createMock(\OCP\GlobalScale\IConfig::class); |
112 | 116 |
|
113 | 117 | $this->userManager->expects($this->any())->method('userExists')->willReturn(true); |
@@ -141,6 +145,7 @@ protected function tearDown(): void { |
141 | 145 | public function testCreate() { |
142 | 146 | $share = $this->shareManager->newShare(); |
143 | 147 |
|
| 148 | + /** @var File|MockObject $node */ |
144 | 149 | $node = $this->getMockBuilder(File::class)->getMock(); |
145 | 150 | $node->method('getId')->willReturn(42); |
146 | 151 | $node->method('getName')->willReturn('myFile'); |
@@ -170,10 +175,15 @@ public function testCreate() { |
170 | 175 | 'shareOwner@http://localhost/', |
171 | 176 | 'sharedBy', |
172 | 177 | 'sharedBy@http://localhost/' |
173 | | - )->willReturn(true); |
| 178 | + ) |
| 179 | + ->willReturn(true); |
174 | 180 |
|
175 | 181 | $this->rootFolder->expects($this->never())->method($this->anything()); |
176 | 182 |
|
| 183 | + $this->contactsManager->expects($this->any()) |
| 184 | + ->method('search') |
| 185 | + ->willReturn([]); |
| 186 | + |
177 | 187 | $share = $this->provider->create($share); |
178 | 188 |
|
179 | 189 | $qb = $this->connection->getQueryBuilder(); |
@@ -250,6 +260,10 @@ public function testCreateCouldNotFindServer() { |
250 | 260 | ->with('42') |
251 | 261 | ->willReturn([$node]); |
252 | 262 |
|
| 263 | + $this->contactsManager->expects($this->any()) |
| 264 | + ->method('search') |
| 265 | + ->willReturn([]); |
| 266 | + |
253 | 267 | try { |
254 | 268 | $share = $this->provider->create($share); |
255 | 269 | $this->fail(); |
@@ -307,6 +321,10 @@ public function testCreateException() { |
307 | 321 | ->with('42') |
308 | 322 | ->willReturn([$node]); |
309 | 323 |
|
| 324 | + $this->contactsManager->expects($this->any()) |
| 325 | + ->method('search') |
| 326 | + ->willReturn([]); |
| 327 | + |
310 | 328 | try { |
311 | 329 | $share = $this->provider->create($share); |
312 | 330 | $this->fail(); |
@@ -344,6 +362,10 @@ public function testCreateShareWithSelf() { |
344 | 362 | ->setPermissions(19) |
345 | 363 | ->setNode($node); |
346 | 364 |
|
| 365 | + $this->contactsManager->expects($this->any()) |
| 366 | + ->method('search') |
| 367 | + ->willReturn([]); |
| 368 | + |
347 | 369 | $this->rootFolder->expects($this->never())->method($this->anything()); |
348 | 370 |
|
349 | 371 | try { |
@@ -403,6 +425,10 @@ public function testCreateAlreadyShared() { |
403 | 425 |
|
404 | 426 | $this->rootFolder->expects($this->never())->method($this->anything()); |
405 | 427 |
|
| 428 | + $this->contactsManager->expects($this->any()) |
| 429 | + ->method('search') |
| 430 | + ->willReturn([]); |
| 431 | + |
406 | 432 | $this->provider->create($share); |
407 | 433 |
|
408 | 434 | try { |
@@ -441,7 +467,6 @@ public function testUpdate($owner, $sharedBy) { |
441 | 467 | $node->method('getId')->willReturn(42); |
442 | 468 | $node->method('getName')->willReturn('myFile'); |
443 | 469 |
|
444 | | - |
445 | 470 | $this->addressHandler->expects($this->any())->method('splitUserRemote') |
446 | 471 | ->willReturn(['user', 'server.com']); |
447 | 472 |
|
@@ -477,6 +502,10 @@ public function testUpdate($owner, $sharedBy) { |
477 | 502 |
|
478 | 503 | $this->rootFolder->expects($this->never())->method($this->anything()); |
479 | 504 |
|
| 505 | + $this->contactsManager->expects($this->any()) |
| 506 | + ->method('search') |
| 507 | + ->willReturn([]); |
| 508 | + |
480 | 509 | $share = $this->provider->create($share); |
481 | 510 |
|
482 | 511 | $share->setPermissions(1); |
@@ -515,6 +544,10 @@ public function testGetSharedBy() { |
515 | 544 |
|
516 | 545 | $this->rootFolder->expects($this->never())->method($this->anything()); |
517 | 546 |
|
| 547 | + $this->contactsManager->expects($this->any()) |
| 548 | + ->method('search') |
| 549 | + ->willReturn([]); |
| 550 | + |
518 | 551 | $share = $this->shareManager->newShare(); |
519 | 552 | $share->setSharedWith('user@server.com') |
520 | 553 | ->setSharedBy('sharedBy') |
@@ -555,6 +588,10 @@ public function testGetSharedByWithNode() { |
555 | 588 | $this->addressHandler->method('generateRemoteURL') |
556 | 589 | ->willReturn('remoteurl.com'); |
557 | 590 |
|
| 591 | + $this->contactsManager->expects($this->any()) |
| 592 | + ->method('search') |
| 593 | + ->willReturn([]); |
| 594 | + |
558 | 595 | $share = $this->shareManager->newShare(); |
559 | 596 | $share->setSharedWith('user@server.com') |
560 | 597 | ->setSharedBy('sharedBy') |
@@ -598,6 +635,10 @@ public function testGetSharedByWithReshares() { |
598 | 635 | $this->addressHandler->method('generateRemoteURL') |
599 | 636 | ->willReturn('remoteurl.com'); |
600 | 637 |
|
| 638 | + $this->contactsManager->expects($this->any()) |
| 639 | + ->method('search') |
| 640 | + ->willReturn([]); |
| 641 | + |
601 | 642 | $share = $this->shareManager->newShare(); |
602 | 643 | $share->setSharedWith('user@server.com') |
603 | 644 | ->setSharedBy('shareOwner') |
@@ -644,6 +685,10 @@ public function testGetSharedByWithLimit() { |
644 | 685 | $this->addressHandler->method('generateRemoteURL') |
645 | 686 | ->willReturn('remoteurl.com'); |
646 | 687 |
|
| 688 | + $this->contactsManager->expects($this->any()) |
| 689 | + ->method('search') |
| 690 | + ->willReturn([]); |
| 691 | + |
647 | 692 | $share = $this->shareManager->newShare(); |
648 | 693 | $share->setSharedWith('user@server.com') |
649 | 694 | ->setSharedBy('sharedBy') |
@@ -844,6 +889,10 @@ public function testGetSharesInFolder() { |
844 | 889 | $this->addressHandler->method('generateRemoteURL') |
845 | 890 | ->willReturn('remoteurl.com'); |
846 | 891 |
|
| 892 | + $this->contactsManager->expects($this->any()) |
| 893 | + ->method('search') |
| 894 | + ->willReturn([]); |
| 895 | + |
847 | 896 | $share1 = $this->shareManager->newShare(); |
848 | 897 | $share1->setSharedWith('user@server.com') |
849 | 898 | ->setSharedBy($u1->getUID()) |
@@ -891,6 +940,10 @@ public function testGetAccessList() { |
891 | 940 | ->method('sendRemoteShare') |
892 | 941 | ->willReturn(true); |
893 | 942 |
|
| 943 | + $this->contactsManager->expects($this->any()) |
| 944 | + ->method('search') |
| 945 | + ->willReturn([]); |
| 946 | + |
894 | 947 | $result = $this->provider->getAccessList([$file1], true); |
895 | 948 | $this->assertEquals(['remote' => []], $result); |
896 | 949 |
|
|
0 commit comments