Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 20 additions & 38 deletions tests/lib/Controller/ConfigControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1265,20 +1265,13 @@ public function testOPOAuthTokenRevokeDoesNotOccurIfNoOPOAuthClientHasChanged()

$configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url', ''],
['integration_openproject', 'authorization_method', ''],
['integration_openproject', 'openproject_client_id', ''],
['integration_openproject', 'openproject_client_secret', ''],
['integration_openproject', 'oPOAuthTokenRevokeStatus', '']
)
->willReturnOnConsecutiveCalls(
$oldAdminConfig['openproject_instance_url'],
$oldAdminConfig['authorization_method'],
$oldAdminConfig['openproject_client_id'],
$oldAdminConfig['openproject_client_secret'],
''
);
->willReturnMap([
[Application::APP_ID, 'openproject_instance_url', '', $oldAdminConfig['openproject_instance_url']],
[Application::APP_ID, 'authorization_method', '', $oldAdminConfig['authorization_method']],
[Application::APP_ID, 'openproject_client_id', '', $oldAdminConfig['openproject_client_id']],
[Application::APP_ID, 'openproject_client_secret', '', $oldAdminConfig['openproject_client_secret']],
[Application::APP_ID, 'oPOAuthTokenRevokeStatus', '', ''],
]);
$configMock
->expects($this->exactly(2))
->method('deleteAppValue')
Expand Down Expand Up @@ -1522,30 +1515,19 @@ public function testSetAdminConfigOIDCAuthSetting(
->getMock();
$configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url', ''],
['integration_openproject', 'authorization_method', ''],
['integration_openproject', 'oidc_provider'],
['integration_openproject', 'targeted_audience_client_id'],
['integration_openproject', 'nc_oauth_client_id', ''],
['integration_openproject', 'oPOAuthTokenRevokeStatus', ''],
['integration_openproject', 'authorization_method', ''],
['integration_openproject', 'oidc_provider'],
['integration_openproject', 'targeted_audience_client_id'],
['integration_openproject', 'openproject_instance_url'],
)
->willReturnOnConsecutiveCalls(
$oldCreds['openproject_instance_url'],
$oldCreds['authorization_method'],
$oldCreds['oidc_provider'],
$oldCreds['targeted_audience_client_id'],
'123',
'',
OpenProjectAPIService::AUTH_METHOD_OAUTH,
$credsToUpdate['oidc_provider'],
$credsToUpdate['targeted_audience_client_id'],
$credsToUpdate['openproject_instance_url']
);
->willReturnMap([
['integration_openproject', 'openproject_instance_url', '', $oldCreds['openproject_instance_url']],
['integration_openproject', 'authorization_method', '', $oldCreds['authorization_method']],
['integration_openproject', 'oidc_provider', '', $oldCreds['oidc_provider']],
['integration_openproject', 'targeted_audience_client_id', '', $oldCreds['targeted_audience_client_id']],
['integration_openproject', 'nc_oauth_client_id', '', '123'],
['integration_openproject', 'oPOAuthTokenRevokeStatus', '', ''],
['integration_openproject', 'authorization_method', '', OpenProjectAPIService::AUTH_METHOD_OIDC],
['integration_openproject', 'oidc_provider', '', $credsToUpdate['oidc_provider']],
['integration_openproject', 'targeted_audience_client_id', '', $credsToUpdate['targeted_audience_client_id']],
['integration_openproject', 'openproject_instance_url', '', $credsToUpdate['openproject_instance_url']],

]);

$apiService = $this->getMockBuilder(OpenProjectAPIService::class)
->disableOriginalConstructor()
Expand Down
141 changes: 71 additions & 70 deletions tests/lib/Controller/FilesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,20 @@ public function testGetFileInfoFileExistingButCannotGetNameInContextOfOwner(): v
public function testGetFilesInfoFourIdsRequestedOneExistsOneInTrashOneNotExisitingOneForbidden(): void {
$folderMock = $this->getMockBuilder(Folder::class)->getMock();
$folderMock->method('getById')
->withConsecutive([123], [759], [365], [956])
->willReturnOnConsecutiveCalls(
->willReturnMap(
[
$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')
],
[],
[]
[123, [$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')]],
[759, []],
[365, []],
[956, []]
]
);

$cachedMountFileInfoMock = $this->getMockBuilder(
ICachedMountFileInfo::class
)->getMock();
$cachedMountFileInfoMock->method('getInternalPath')
->willReturnOnConsecutiveCalls(
->willReturn(
'files/logo.png',
'files_trashbin/files/welcome.txt.d1648724302',
'/anotherUser/files/logo.png'
Expand All @@ -213,19 +213,20 @@ public function testGetFilesInfoFourIdsRequestedOneExistsOneInTrashOneNotExisiti

$mountCacheMock = $this->getMockBuilder(IUserMountCache::class)->getMock();
$mountCacheMock->method('getMountsForFileId')
->withConsecutive([123], [759], [365], [956])
->willReturnOnConsecutiveCalls(
[$cachedMountFileInfoMock],
[$cachedMountFileInfoMock],
[], // not found
[$cachedMountFileInfoMock],
->willReturnMap(
[
[123, null, [$cachedMountFileInfoMock]],
[759, null, [$cachedMountFileInfoMock]],
[365, null, []],
[956, null, [$cachedMountFileInfoMock]]
]
);

$filesController = $this->getFilesControllerMock(
['getDavPermissions'], $folderMock, $mountCacheMock
);
$filesController->method('getDavPermissions')
->willReturnOnConsecutiveCalls('RGDNVW', 'RGDNVW');
->willReturn('RGDNVW', 'RGDNVW');

$result = $filesController->getFilesInfo([123, 759, 365, 956]);
assertSame(
Expand Down Expand Up @@ -268,13 +269,12 @@ public function testGetFilesInfoOneIdRequestedFileExistsReturnsOneResult(): void
public function testGetFilesInfoThreeIdsRequestedOneFileExistsReturnsOneResult(): void {
$folderMock = $this->getMockBuilder(Folder::class)->getMock();
$folderMock->method('getById')
->withConsecutive([123], [256], [365])
->willReturnOnConsecutiveCalls(
->willReturnMap(
[
$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')
],
[],
[]
[123, [$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')]],
[256, []],
[365, []]
]
);

$cachedMountFileInfoMock = $this->getMockBuilder(
Expand All @@ -289,7 +289,7 @@ public function testGetFilesInfoThreeIdsRequestedOneFileExistsReturnsOneResult()
$mountCacheMock = $this->getMockBuilder(IUserMountCache::class)
->getMock();
$mountCacheMock->method('getMountsForFileId')
->willReturnOnConsecutiveCalls(
->willReturn(
[$cachedMountFileInfoMock], [], []
);

Expand All @@ -313,20 +313,18 @@ public function testGetFilesInfoThreeIdsRequestedOneFileExistsReturnsOneResult()
public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsOneResult(): void {
$folderMock = $this->getMockBuilder(Folder::class)->getMock();
$folderMock->method('getById')
->withConsecutive([123], [365])
->willReturnOnConsecutiveCalls(
->willReturnMap(
[
$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')
],
[
$this->getNodeMock('image/png', 365, 'file', '/testUser/files/inFolder/image.png'),
[123, [$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')]],
[365, [$this->getNodeMock('image/png', 365, 'file', '/testUser/files/inFolder/image.png')]]
]
);

$cachedMountFileInfoMock = $this->getMockBuilder(
ICachedMountFileInfo::class
)->getMock();
$cachedMountFileInfoMock->method('getInternalPath')
->willReturnOnConsecutiveCalls(
->willReturn(
'files/logo.png',
'files/inFolder/image.png',
);
Expand All @@ -344,7 +342,7 @@ public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsOneResul
['getDavPermissions'], $folderMock, $mountCacheMock
);
$filesController->method('getDavPermissions')
->willReturnOnConsecutiveCalls('RGDNVW', 'RGDNVW');
->willReturn('RGDNVW');
$result = $filesController->getFilesInfo([123,365]);
assertSame(
[
Expand All @@ -359,21 +357,18 @@ public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsOneResul
public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsMultipleResults(): void {
$folderMock = $this->getMockBuilder(Folder::class)->getMock();
$folderMock->method('getById')
->withConsecutive([123], [365])
->willReturnOnConsecutiveCalls(
[
$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png'),
],
->willReturnMap(
[
$this->getNodeMock('image/png', 365, 'file', '/testUser/files/inFolder/image.png'),
[123, [$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')]],
[365, [$this->getNodeMock('image/png', 365, 'file', '/testUser/files/inFolder/image.png')]]
]
);

$cachedMountFileInfoMock = $this->getMockBuilder(
ICachedMountFileInfo::class
)->getMock();
$cachedMountFileInfoMock->method('getInternalPath')
->willReturnOnConsecutiveCalls(
->willReturn(
'files/logo.png',
'files/inFolder/image.png',
);
Expand All @@ -391,7 +386,7 @@ public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsMultiple
['getDavPermissions'], $folderMock, $mountCacheMock
);
$filesController->method('getDavPermissions')
->willReturnOnConsecutiveCalls('RGDNVW', 'RGDNVW');
->willReturn('RGDNVW');

$result = $filesController->getFilesInfo([123,365]);
assertSame(
Expand All @@ -407,31 +402,36 @@ public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsMultiple
public function testGetFilesInfoTwoIdsRequestedEachReturnsOneFolder(): void {
$folderMock = $this->getMockBuilder(Folder::class)->getMock();
$folderMock->method('getById')
->withConsecutive([2], [3])
->willReturnOnConsecutiveCalls(
->willReturnMap([
[
$this->getNodeMock(
'httpd/unix-directory',
2,
'dir',
'/testUser/files/myFolder/a-sub-folder'
)
2,
[
$this->getNodeMock(
'httpd/unix-directory',
2,
'dir',
'/testUser/files/myFolder/a-sub-folder'
)
]
],
[
$this->getNodeMock(
'httpd/unix-directory',
3,
'dir',
'/testUser/files'
)
]
);
3,
[
$this->getNodeMock(
'httpd/unix-directory',
3,
'dir',
'/testUser/files'
)
]
],
]);

$cachedMountFileInfoMock = $this->getMockBuilder(
ICachedMountFileInfo::class
)->getMock();
$cachedMountFileInfoMock->method('getInternalPath')
->willReturnOnConsecutiveCalls(
->willReturn(
'files/myFolder/a-sub-folder',
'files'
);
Expand All @@ -449,7 +449,7 @@ public function testGetFilesInfoTwoIdsRequestedEachReturnsOneFolder(): void {
['getDavPermissions'], $folderMock, $mountCacheMock
);
$filesController->method('getDavPermissions')
->willReturnOnConsecutiveCalls('RGDNVCK', 'RGDNVCK');
->willReturn('RGDNVCK', 'RGDNVCK');

$result = $filesController->getFilesInfo([2,3]);
assertSame(
Expand Down Expand Up @@ -507,31 +507,32 @@ public function testGetFilesInfoInvalidRequest(): void {
public function testGetFilesInfoSendStringIds(): void {
$folderMock = $this->getMockBuilder(Folder::class)->getMock();
$folderMock->method('getById')
->withConsecutive([2], [3])
->willReturnOnConsecutiveCalls(
[
$this->getNodeMock(
->willReturnMap([
[ 2,
[$this->getNodeMock(
'httpd/unix-directory',
2,
'dir',
'/testUser/files/myFolder/a-sub-folder'
)
)]
],
[
$this->getNodeMock(
'httpd/unix-directory',
3,
'dir',
'/testUser/files/testFolder'
)
[ 3,
[
$this->getNodeMock(
'httpd/unix-directory',
3,
'dir',
'/testUser/files/testFolder'
)
]
]
);
]);

$cachedMountFileInfoMock = $this->getMockBuilder(
ICachedMountFileInfo::class
)->getMock();
$cachedMountFileInfoMock->method('getInternalPath')
->willReturnOnConsecutiveCalls(
->willReturn(
'files/myFolder/a-sub-folder',
''
);
Expand All @@ -549,7 +550,7 @@ public function testGetFilesInfoSendStringIds(): void {
['getDavPermissions'], $folderMock, $mountCacheMock
);
$filesController->method('getDavPermissions')
->willReturnOnConsecutiveCalls('RGDNVCK', 'RGDNVCK');
->willReturn('RGDNVCK', 'RGDNVCK');

$result = $filesController->getFilesInfo(["2","3"]);
assertSame(
Expand Down