|
13 | 13 | use OCA\Files_External\Lib\Auth\PublicKey\RSA; |
14 | 14 | use OCA\Files_External\Settings\Admin; |
15 | 15 | use OCP\AppFramework\Http\JSONResponse; |
| 16 | +use OCP\IGroup; |
16 | 17 | use OCP\IGroupManager; |
17 | 18 | use OCP\IL10N; |
18 | 19 | use OCP\IRequest; |
@@ -67,6 +68,50 @@ protected function setUp(): void { |
67 | 68 | parent::setUp(); |
68 | 69 | } |
69 | 70 |
|
| 71 | + public function testGetApplicableEntitiesReturnsGroupsAndUsers(): void { |
| 72 | + $group = $this->createMock(IGroup::class); |
| 73 | + $group->method('getGID')->willReturn('group1'); |
| 74 | + $group->method('getDisplayName')->willReturn('Group One'); |
| 75 | + |
| 76 | + $user = $this->createMock(IUser::class); |
| 77 | + $user->method('getUID')->willReturn('user1'); |
| 78 | + $user->method('getDisplayName')->willReturn('User One'); |
| 79 | + |
| 80 | + $this->groupManager |
| 81 | + ->expects($this->once()) |
| 82 | + ->method('search') |
| 83 | + ->with('test', 10, 0) |
| 84 | + ->willReturn([$group]); |
| 85 | + $this->userManager |
| 86 | + ->expects($this->once()) |
| 87 | + ->method('searchDisplayName') |
| 88 | + ->with('test', 10, 0) |
| 89 | + ->willReturn([$user]); |
| 90 | + |
| 91 | + $response = $this->ajaxController->getApplicableEntities('test', 10, 0); |
| 92 | + $this->assertSame(200, $response->getStatus()); |
| 93 | + $this->assertSame(['group1' => 'Group One'], $response->getData()['groups']); |
| 94 | + $this->assertSame(['user1' => 'User One'], $response->getData()['users']); |
| 95 | + } |
| 96 | + |
| 97 | + public function testGetApplicableEntitiesWithNoResults(): void { |
| 98 | + $this->groupManager |
| 99 | + ->expects($this->once()) |
| 100 | + ->method('search') |
| 101 | + ->with('', null, null) |
| 102 | + ->willReturn([]); |
| 103 | + $this->userManager |
| 104 | + ->expects($this->once()) |
| 105 | + ->method('searchDisplayName') |
| 106 | + ->with('', null, null) |
| 107 | + ->willReturn([]); |
| 108 | + |
| 109 | + $response = $this->ajaxController->getApplicableEntities(); |
| 110 | + $this->assertSame(200, $response->getStatus()); |
| 111 | + $this->assertSame([], $response->getData()['groups']); |
| 112 | + $this->assertSame([], $response->getData()['users']); |
| 113 | + } |
| 114 | + |
70 | 115 | public function testGetSshKeys(): void { |
71 | 116 | $this->rsa |
72 | 117 | ->expects($this->once()) |
|
0 commit comments