|
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; |
|
46 | 47 | use OCP\IUserManager; |
47 | 48 | use OCP\Share\IManager; |
48 | 49 | use OCP\Share\IShare; |
| 50 | +use PHPUnit\Framework\MockObject\MockObject; |
49 | 51 |
|
50 | 52 | /** |
51 | 53 | * Class FederatedShareProviderTest |
@@ -80,6 +82,8 @@ class FederatedShareProviderTest extends \Test\TestCase { |
80 | 82 | protected $shareManager; |
81 | 83 | /** @var FederatedShareProvider */ |
82 | 84 | protected $provider; |
| 85 | + /** @var IContactsManager|\PHPUnit\Framework\MockObject\MockObject */ |
| 86 | + protected $contactsManager; |
83 | 87 |
|
84 | 88 | /** @var ICloudIdManager */ |
85 | 89 | private $cloudIdManager; |
@@ -108,7 +112,8 @@ protected function setUp(): void { |
108 | 112 | $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock(); |
109 | 113 | //$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l); |
110 | 114 | $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')->disableOriginalConstructor()->getMock(); |
111 | | - $this->cloudIdManager = new CloudIdManager(); |
| 115 | + $this->contactsManager = $this->createMock(IContactsManager::class); |
| 116 | + $this->cloudIdManager = new CloudIdManager($this->contactsManager); |
112 | 117 | $this->gsConfig = $this->createMock(\OCP\GlobalScale\IConfig::class); |
113 | 118 |
|
114 | 119 | $this->userManager->expects($this->any())->method('userExists')->willReturn(true); |
@@ -142,6 +147,7 @@ protected function tearDown(): void { |
142 | 147 | public function testCreate() { |
143 | 148 | $share = $this->shareManager->newShare(); |
144 | 149 |
|
| 150 | + /** @var File|MockObject $node */ |
145 | 151 | $node = $this->getMockBuilder(File::class)->getMock(); |
146 | 152 | $node->method('getId')->willReturn(42); |
147 | 153 | $node->method('getName')->willReturn('myFile'); |
@@ -171,10 +177,15 @@ public function testCreate() { |
171 | 177 | 'shareOwner@http://localhost/', |
172 | 178 | 'sharedBy', |
173 | 179 | 'sharedBy@http://localhost/' |
174 | | - )->willReturn(true); |
| 180 | + ) |
| 181 | + ->willReturn(true); |
175 | 182 |
|
176 | 183 | $this->rootFolder->expects($this->never())->method($this->anything()); |
177 | 184 |
|
| 185 | + $this->contactsManager->expects($this->any()) |
| 186 | + ->method('search') |
| 187 | + ->willReturn([]); |
| 188 | + |
178 | 189 | $share = $this->provider->create($share); |
179 | 190 |
|
180 | 191 | $qb = $this->connection->getQueryBuilder(); |
@@ -251,6 +262,10 @@ public function testCreateCouldNotFindServer() { |
251 | 262 | ->with('42') |
252 | 263 | ->willReturn([$node]); |
253 | 264 |
|
| 265 | + $this->contactsManager->expects($this->any()) |
| 266 | + ->method('search') |
| 267 | + ->willReturn([]); |
| 268 | + |
254 | 269 | try { |
255 | 270 | $share = $this->provider->create($share); |
256 | 271 | $this->fail(); |
@@ -308,6 +323,10 @@ public function testCreateException() { |
308 | 323 | ->with('42') |
309 | 324 | ->willReturn([$node]); |
310 | 325 |
|
| 326 | + $this->contactsManager->expects($this->any()) |
| 327 | + ->method('search') |
| 328 | + ->willReturn([]); |
| 329 | + |
311 | 330 | try { |
312 | 331 | $share = $this->provider->create($share); |
313 | 332 | $this->fail(); |
@@ -345,6 +364,10 @@ public function testCreateShareWithSelf() { |
345 | 364 | ->setPermissions(19) |
346 | 365 | ->setNode($node); |
347 | 366 |
|
| 367 | + $this->contactsManager->expects($this->any()) |
| 368 | + ->method('search') |
| 369 | + ->willReturn([]); |
| 370 | + |
348 | 371 | $this->rootFolder->expects($this->never())->method($this->anything()); |
349 | 372 |
|
350 | 373 | try { |
@@ -404,6 +427,10 @@ public function testCreateAlreadyShared() { |
404 | 427 |
|
405 | 428 | $this->rootFolder->expects($this->never())->method($this->anything()); |
406 | 429 |
|
| 430 | + $this->contactsManager->expects($this->any()) |
| 431 | + ->method('search') |
| 432 | + ->willReturn([]); |
| 433 | + |
407 | 434 | $this->provider->create($share); |
408 | 435 |
|
409 | 436 | try { |
@@ -442,7 +469,6 @@ public function testUpdate($owner, $sharedBy) { |
442 | 469 | $node->method('getId')->willReturn(42); |
443 | 470 | $node->method('getName')->willReturn('myFile'); |
444 | 471 |
|
445 | | - |
446 | 472 | $this->addressHandler->expects($this->any())->method('splitUserRemote') |
447 | 473 | ->willReturn(['user', 'server.com']); |
448 | 474 |
|
@@ -478,6 +504,10 @@ public function testUpdate($owner, $sharedBy) { |
478 | 504 |
|
479 | 505 | $this->rootFolder->expects($this->never())->method($this->anything()); |
480 | 506 |
|
| 507 | + $this->contactsManager->expects($this->any()) |
| 508 | + ->method('search') |
| 509 | + ->willReturn([]); |
| 510 | + |
481 | 511 | $share = $this->provider->create($share); |
482 | 512 |
|
483 | 513 | $share->setPermissions(1); |
@@ -516,6 +546,10 @@ public function testGetSharedBy() { |
516 | 546 |
|
517 | 547 | $this->rootFolder->expects($this->never())->method($this->anything()); |
518 | 548 |
|
| 549 | + $this->contactsManager->expects($this->any()) |
| 550 | + ->method('search') |
| 551 | + ->willReturn([]); |
| 552 | + |
519 | 553 | $share = $this->shareManager->newShare(); |
520 | 554 | $share->setSharedWith('user@server.com') |
521 | 555 | ->setSharedBy('sharedBy') |
@@ -556,6 +590,10 @@ public function testGetSharedByWithNode() { |
556 | 590 | $this->addressHandler->method('generateRemoteURL') |
557 | 591 | ->willReturn('remoteurl.com'); |
558 | 592 |
|
| 593 | + $this->contactsManager->expects($this->any()) |
| 594 | + ->method('search') |
| 595 | + ->willReturn([]); |
| 596 | + |
559 | 597 | $share = $this->shareManager->newShare(); |
560 | 598 | $share->setSharedWith('user@server.com') |
561 | 599 | ->setSharedBy('sharedBy') |
@@ -599,6 +637,10 @@ public function testGetSharedByWithReshares() { |
599 | 637 | $this->addressHandler->method('generateRemoteURL') |
600 | 638 | ->willReturn('remoteurl.com'); |
601 | 639 |
|
| 640 | + $this->contactsManager->expects($this->any()) |
| 641 | + ->method('search') |
| 642 | + ->willReturn([]); |
| 643 | + |
602 | 644 | $share = $this->shareManager->newShare(); |
603 | 645 | $share->setSharedWith('user@server.com') |
604 | 646 | ->setSharedBy('shareOwner') |
@@ -645,6 +687,10 @@ public function testGetSharedByWithLimit() { |
645 | 687 | $this->addressHandler->method('generateRemoteURL') |
646 | 688 | ->willReturn('remoteurl.com'); |
647 | 689 |
|
| 690 | + $this->contactsManager->expects($this->any()) |
| 691 | + ->method('search') |
| 692 | + ->willReturn([]); |
| 693 | + |
648 | 694 | $share = $this->shareManager->newShare(); |
649 | 695 | $share->setSharedWith('user@server.com') |
650 | 696 | ->setSharedBy('sharedBy') |
@@ -845,6 +891,10 @@ public function testGetSharesInFolder() { |
845 | 891 | $this->addressHandler->method('generateRemoteURL') |
846 | 892 | ->willReturn('remoteurl.com'); |
847 | 893 |
|
| 894 | + $this->contactsManager->expects($this->any()) |
| 895 | + ->method('search') |
| 896 | + ->willReturn([]); |
| 897 | + |
848 | 898 | $share1 = $this->shareManager->newShare(); |
849 | 899 | $share1->setSharedWith('user@server.com') |
850 | 900 | ->setSharedBy($u1->getUID()) |
@@ -892,6 +942,10 @@ public function testGetAccessList() { |
892 | 942 | ->method('sendRemoteShare') |
893 | 943 | ->willReturn(true); |
894 | 944 |
|
| 945 | + $this->contactsManager->expects($this->any()) |
| 946 | + ->method('search') |
| 947 | + ->willReturn([]); |
| 948 | + |
895 | 949 | $result = $this->provider->getAccessList([$file1], true); |
896 | 950 | $this->assertEquals(['remote' => []], $result); |
897 | 951 |
|
|
0 commit comments