diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-01-05 18:25:31 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-01-05 18:28:07 +0100 |
commit | 574c6770d18f74c26ec3b72075a52333e6495a7a (patch) | |
tree | 28f0c760c0664062c2fb34becdaab7b36fea48c2 /apps/dav/tests/unit/Connector | |
parent | adef2b85c8c8f771d694dedec2c8509694aee149 (diff) | |
download | nextcloud-server-574c6770d18f74c26ec3b72075a52333e6495a7a.tar.gz nextcloud-server-574c6770d18f74c26ec3b72075a52333e6495a7a.zip |
Get rid of deprecated at matcher in dav application tests
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/dav/tests/unit/Connector')
6 files changed, 171 insertions, 181 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/AuthTest.php b/apps/dav/tests/unit/Connector/Sabre/AuthTest.php index 9355b34d66a..d72e19e1641 100644 --- a/apps/dav/tests/unit/Connector/Sabre/AuthTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/AuthTest.php @@ -220,7 +220,7 @@ class AuthTest extends TestCase { $this->assertFalse($this->invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword'])); } - + public function testValidateUserPassWithPasswordLoginForbidden() { $this->expectException(\OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden::class); @@ -329,7 +329,7 @@ class AuthTest extends TestCase { $this->auth->check($request, $response); } - + public function testAuthenticateAlreadyLoggedInWithoutTwoFactorChallengePassed() { $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); $this->expectExceptionMessage('2FA challenge not passed.'); @@ -383,7 +383,7 @@ class AuthTest extends TestCase { $this->auth->check($request, $response); } - + public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenAndIncorrectlyDavAuthenticated() { $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); $this->expectExceptionMessage('CSRF check not passed.'); @@ -564,7 +564,7 @@ class AuthTest extends TestCase { $this->assertEquals([false, 'No \'Authorization: Basic\' header found. Either the client didn\'t send one, or the server is misconfigured'], $response); } - + public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjax() { $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); $this->expectExceptionMessage('Cannot authenticate over ajax calls'); @@ -639,15 +639,16 @@ class AuthTest extends TestCase { ->disableOriginalConstructor() ->getMock(); $server->httpRequest - ->expects($this->at(0)) - ->method('getHeader') - ->with('X-Requested-With') - ->willReturn(null); - $server->httpRequest - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getHeader') - ->with('Authorization') - ->willReturn('basic dXNlcm5hbWU6cGFzc3dvcmQ='); + ->withConsecutive( + ['X-Requested-With'], + ['Authorization'], + ) + ->willReturnOnConsecutiveCalls( + null, + 'basic dXNlcm5hbWU6cGFzc3dvcmQ=', + ); $server->httpResponse = $this->getMockBuilder(ResponseInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -678,15 +679,16 @@ class AuthTest extends TestCase { ->disableOriginalConstructor() ->getMock(); $server->httpRequest - ->expects($this->at(0)) - ->method('getHeader') - ->with('X-Requested-With') - ->willReturn(null); - $server->httpRequest - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getHeader') - ->with('Authorization') - ->willReturn('basic dXNlcm5hbWU6cGFzc3dvcmQ='); + ->withConsecutive( + ['X-Requested-With'], + ['Authorization'], + ) + ->willReturnOnConsecutiveCalls( + null, + 'basic dXNlcm5hbWU6cGFzc3dvcmQ=', + ); $server->httpResponse = $this->getMockBuilder(ResponseInterface::class) ->disableOriginalConstructor() ->getMock(); diff --git a/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php b/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php index 007b5c90295..58a93b25447 100644 --- a/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php @@ -66,13 +66,12 @@ class BearerAuthTest extends TestCase { public function testValidateBearerToken() { $this->userSession - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('isLoggedIn') - ->willReturn(false); - $this->userSession - ->expects($this->at(2)) - ->method('isLoggedIn') - ->willReturn(true); + ->willReturnOnConsecutiveCalls( + false, + true, + ); $user = $this->createMock(IUser::class); $user ->expects($this->once()) diff --git a/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php index 578576e3f07..9c7ca8e9329 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php @@ -56,21 +56,14 @@ class FakeLockerPluginTest extends TestCase { ->disableOriginalConstructor() ->getMock(); $server - ->expects($this->at(0)) + ->expects($this->exactly(4)) ->method('on') - ->with('method:LOCK', [$this->fakeLockerPlugin, 'fakeLockProvider'], 1); - $server - ->expects($this->at(1)) - ->method('on') - ->with('method:UNLOCK', [$this->fakeLockerPlugin, 'fakeUnlockProvider'], 1); - $server - ->expects($this->at(2)) - ->method('on') - ->with('propFind', [$this->fakeLockerPlugin, 'propFind']); - $server - ->expects($this->at(3)) - ->method('on') - ->with('validateTokens', [$this->fakeLockerPlugin, 'validateTokens']); + ->withConsecutive( + ['method:LOCK', [$this->fakeLockerPlugin, 'fakeLockProvider'], 1], + ['method:UNLOCK', [$this->fakeLockerPlugin, 'fakeUnlockProvider'], 1], + ['propFind', [$this->fakeLockerPlugin, 'propFind']], + ['validateTokens', [$this->fakeLockerPlugin, 'validateTokens']], + ); $this->fakeLockerPlugin->initialize($server); } @@ -98,12 +91,12 @@ class FakeLockerPluginTest extends TestCase { ->disableOriginalConstructor() ->getMock(); - $propFind->expects($this->at(0)) - ->method('handle') - ->with('{DAV:}supportedlock'); - $propFind->expects($this->at(1)) + $propFind->expects($this->exactly(2)) ->method('handle') - ->with('{DAV:}lockdiscovery'); + ->withConsecutive( + ['{DAV:}supportedlock'], + ['{DAV:}lockdiscovery'], + ); $this->fakeLockerPlugin->propFind($propFind, $node); } diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php index f73434b33b6..5b8ed304e96 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php @@ -217,14 +217,16 @@ class FilesReportPluginTest extends \Test\TestCase { ->method('isAdmin') ->willReturn(true); - $this->tagMapper->expects($this->at(0)) - ->method('getObjectIdsForTags') - ->with('123', 'files') - ->willReturn(['111', '222']); - $this->tagMapper->expects($this->at(1)) + $this->tagMapper->expects($this->exactly(2)) ->method('getObjectIdsForTags') - ->with('456', 'files') - ->willReturn(['111', '222', '333']); + ->withConsecutive( + ['123', 'files'], + ['456', 'files'], + ) + ->willReturnOnConsecutiveCalls( + ['111', '222'], + ['111', '222', '333'], + ); $reportTargetNode = $this->getMockBuilder(Directory::class) ->disableOriginalConstructor() @@ -260,14 +262,16 @@ class FilesReportPluginTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); - $this->userFolder->expects($this->at(0)) - ->method('getById') - ->with('111') - ->willReturn([$filesNode1]); - $this->userFolder->expects($this->at(1)) + $this->userFolder->expects($this->exactly(2)) ->method('getById') - ->with('222') - ->willReturn([$filesNode2]); + ->withConsecutive( + ['111'], + ['222'], + ) + ->willReturnOnConsecutiveCalls( + [$filesNode1], + [$filesNode2], + ); $this->server->expects($this->any()) ->method('getRequestUri') @@ -300,14 +304,16 @@ class FilesReportPluginTest extends \Test\TestCase { ->method('getPath') ->willReturn('/'); - $this->userFolder->expects($this->at(0)) - ->method('getById') - ->with('111') - ->willReturn([$filesNode1]); - $this->userFolder->expects($this->at(1)) + $this->userFolder->expects($this->exactly(2)) ->method('getById') - ->with('222') - ->willReturn([$filesNode2]); + ->withConsecutive( + ['111'], + ['222'], + ) + ->willReturnOnConsecutiveCalls( + [$filesNode1], + [$filesNode2], + ); /** @var \OCA\DAV\Connector\Sabre\Directory|\PHPUnit\Framework\MockObject\MockObject $reportTargetNode */ $result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']); @@ -346,19 +352,21 @@ class FilesReportPluginTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); - $this->userFolder->expects($this->at(0)) + $this->userFolder->expects($this->once()) ->method('get') ->with('/sub1/sub2') ->willReturn($subNode); - $subNode->expects($this->at(0)) + $subNode->expects($this->exactly(2)) ->method('getById') - ->with('111') - ->willReturn([$filesNode1]); - $subNode->expects($this->at(1)) - ->method('getById') - ->with('222') - ->willReturn([$filesNode2]); + ->withConsecutive( + ['111'], + ['222'], + ) + ->willReturnOnConsecutiveCalls( + [$filesNode1], + [$filesNode2], + ); /** @var \OCA\DAV\Connector\Sabre\Directory|\PHPUnit\Framework\MockObject\MockObject $reportTargetNode */ $result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']); @@ -588,14 +596,16 @@ class FilesReportPluginTest extends \Test\TestCase { $this->tagManager->expects($this->never()) ->method('getTagsByIds'); - $this->tagMapper->expects($this->at(0)) - ->method('getObjectIdsForTags') - ->with('123') - ->willReturn(['111', '222']); - $this->tagMapper->expects($this->at(1)) + $this->tagMapper->expects($this->exactly(2)) ->method('getObjectIdsForTags') - ->with('456') - ->willReturn(['222', '333']); + ->withConsecutive( + ['123'], + ['456'], + ) + ->willReturnOnConsecutiveCalls( + ['111', '222'], + ['222', '333'], + ); $rules = [ ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'], @@ -676,14 +686,16 @@ class FilesReportPluginTest extends \Test\TestCase { ->with(['123', '456']) ->willReturn([$tag1, $tag2]); - $this->tagMapper->expects($this->at(0)) - ->method('getObjectIdsForTags') - ->with('123') - ->willReturn(['111', '222']); - $this->tagMapper->expects($this->at(1)) + $this->tagMapper->expects($this->exactly(2)) ->method('getObjectIdsForTags') - ->with('456') - ->willReturn(['222', '333']); + ->withConsecutive( + ['123'], + ['456'], + ) + ->willReturnOnConsecutiveCalls( + ['111', '222'], + ['222', '333'], + ); $rules = [ ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'], diff --git a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php index 2614f541613..f9e14d5c39f 100644 --- a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php @@ -458,22 +458,19 @@ class PrincipalTest extends TestCase { ->method('getUID') ->willReturn('bar'); $this->userManager - ->expects($this->at(0)) - ->method('get') - ->with('foo') - ->willReturn($fooUser); - $this->userManager - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('get') - ->with('bar') - ->willReturn($barUser); + ->willReturnMap([ + ['foo', $fooUser], + ['bar', $barUser], + ]); - $this->proxyMapper->expects($this->at(0)) + $this->proxyMapper->expects($this->once()) ->method('getProxiesOf') ->with('principals/users/foo') ->willReturn([]); - $this->proxyMapper->expects($this->at(1)) + $this->proxyMapper->expects($this->once()) ->method('insert') ->with($this->callback(function ($proxy) { /** @var Proxy $proxy */ @@ -514,6 +511,8 @@ class PrincipalTest extends TestCase { ->method('shareAPIEnabled') ->willReturn($sharingEnabled); + $getUserGroupIdsReturnMap = []; + if ($sharingEnabled) { $this->shareManager->expects($this->once()) ->method('allowEnumeration') @@ -529,10 +528,7 @@ class PrincipalTest extends TestCase { ->method('getUser') ->willReturn($user); - $this->groupManager->expects($this->at(0)) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2', 'group5']); + $getUserGroupIdsReturnMap[] = [$user, ['group1', 'group2', 'group5']]; } } else { $this->config->expects($this->never()) @@ -551,12 +547,12 @@ class PrincipalTest extends TestCase { $user4->method('getUID')->willReturn('user4'); if ($sharingEnabled) { - $this->userManager->expects($this->at(0)) + $this->userManager->expects($this->once()) ->method('getByEmail') ->with('user@example.com') ->willReturn([$user2, $user3]); - $this->userManager->expects($this->at(1)) + $this->userManager->expects($this->once()) ->method('searchDisplayName') ->with('User 12') ->willReturn([$user3, $user4]); @@ -569,24 +565,15 @@ class PrincipalTest extends TestCase { } if ($sharingEnabled && $groupsOnly) { - $this->groupManager->expects($this->at(1)) - ->method('getUserGroupIds') - ->with($user2) - ->willReturn(['group1', 'group3']); - $this->groupManager->expects($this->at(2)) - ->method('getUserGroupIds') - ->with($user3) - ->willReturn(['group3', 'group4']); - $this->groupManager->expects($this->at(3)) - ->method('getUserGroupIds') - ->with($user3) - ->willReturn(['group3', 'group4']); - $this->groupManager->expects($this->at(4)) - ->method('getUserGroupIds') - ->with($user4) - ->willReturn(['group4', 'group5']); + $getUserGroupIdsReturnMap[] = [$user2, ['group1', 'group3']]; + $getUserGroupIdsReturnMap[] = [$user3, ['group3', 'group4']]; + $getUserGroupIdsReturnMap[] = [$user4, ['group4', 'group5']]; } + $this->groupManager->expects($this->any()) + ->method('getUserGroupIds') + ->willReturnMap($getUserGroupIdsReturnMap); + $this->assertEquals($result, $this->connector->searchPrincipals('principals/users', ['{http://sabredav.org/ns}email-address' => 'user@example.com', @@ -622,7 +609,7 @@ class PrincipalTest extends TestCase { $user3 = $this->createMock(IUser::class); $user3->method('getUID')->willReturn('user3'); - $this->userManager->expects($this->at(0)) + $this->userManager->expects($this->once()) ->method('getByEmail') ->with('user@example.com') ->willReturn([$user2, $user3]); @@ -664,7 +651,7 @@ class PrincipalTest extends TestCase { $user4->method('getDisplayName')->willReturn('User 222'); $user4->method('getSystemEMailAddress')->willReturn('user2@foo.bar456'); - $this->userManager->expects($this->at(0)) + $this->userManager->expects($this->once()) ->method('searchDisplayName') ->with('User 2') ->willReturn([$user2, $user3, $user4]); @@ -760,15 +747,15 @@ class PrincipalTest extends TestCase { } public function testSearchPrincipalWithEnumerationLimitedDisplayname(): void { - $this->shareManager->expects($this->at(0)) + $this->shareManager->expects($this->once()) ->method('shareAPIEnabled') ->willReturn(true); - $this->shareManager->expects($this->at(1)) + $this->shareManager->expects($this->once()) ->method('allowEnumeration') ->willReturn(true); - $this->shareManager->expects($this->at(2)) + $this->shareManager->expects($this->once()) ->method('limitEnumerationToGroups') ->willReturn(true); @@ -790,24 +777,19 @@ class PrincipalTest extends TestCase { $user4->method('getSystemEMailAddress')->willReturn('user2@foo.bar456'); - $this->userSession->expects($this->at(0)) + $this->userSession->expects($this->once()) ->method('getUser') ->willReturn($user2); - $this->groupManager->expects($this->at(0)) - ->method('getUserGroupIds') - ->willReturn(['group1']); - $this->groupManager->expects($this->at(1)) - ->method('getUserGroupIds') - ->willReturn(['group1']); - $this->groupManager->expects($this->at(2)) + $this->groupManager->expects($this->exactly(4)) ->method('getUserGroupIds') - ->willReturn(['group1']); - $this->groupManager->expects($this->at(3)) - ->method('getUserGroupIds') - ->willReturn(['group2']); + ->willReturnMap([ + [$user2, ['group1']], + [$user3, ['group1']], + [$user4, ['group2']], + ]); - $this->userManager->expects($this->at(0)) + $this->userManager->expects($this->once()) ->method('searchDisplayName') ->with('User') ->willReturn([$user2, $user3, $user4]); @@ -821,15 +803,15 @@ class PrincipalTest extends TestCase { } public function testSearchPrincipalWithEnumerationLimitedMail(): void { - $this->shareManager->expects($this->at(0)) + $this->shareManager->expects($this->once()) ->method('shareAPIEnabled') ->willReturn(true); - $this->shareManager->expects($this->at(1)) + $this->shareManager->expects($this->once()) ->method('allowEnumeration') ->willReturn(true); - $this->shareManager->expects($this->at(2)) + $this->shareManager->expects($this->once()) ->method('limitEnumerationToGroups') ->willReturn(true); @@ -851,24 +833,19 @@ class PrincipalTest extends TestCase { $user4->method('getSystemEMailAddress')->willReturn('user2@foo.bar456'); - $this->userSession->expects($this->at(0)) + $this->userSession->expects($this->once()) ->method('getUser') ->willReturn($user2); - $this->groupManager->expects($this->at(0)) + $this->groupManager->expects($this->exactly(4)) ->method('getUserGroupIds') - ->willReturn(['group1']); - $this->groupManager->expects($this->at(1)) - ->method('getUserGroupIds') - ->willReturn(['group1']); - $this->groupManager->expects($this->at(2)) - ->method('getUserGroupIds') - ->willReturn(['group1']); - $this->groupManager->expects($this->at(3)) - ->method('getUserGroupIds') - ->willReturn(['group2']); + ->willReturnMap([ + [$user2, ['group1']], + [$user3, ['group1']], + [$user4, ['group2']], + ]); - $this->userManager->expects($this->at(0)) + $this->userManager->expects($this->once()) ->method('getByEmail') ->with('user') ->willReturn([$user2, $user3, $user4]); @@ -906,11 +883,6 @@ class PrincipalTest extends TestCase { ->method('getUser') ->willReturn($user); - $this->groupManager->expects($this->at(0)) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); $user3 = $this->createMock(IUser::class); @@ -922,15 +894,27 @@ class PrincipalTest extends TestCase { ->willReturn([$email === 'user2@foo.bar' ? $user2 : $user3]); if ($email === 'user2@foo.bar') { - $this->groupManager->expects($this->at(1)) - ->method('getUserGroupIds') - ->with($user2) - ->willReturn(['group1', 'group3']); + $this->groupManager->expects($this->exactly(2)) + ->method('getUserGroupIds') + ->withConsecutive( + [$user], + [$user2], + ) + ->willReturnOnConsecutiveCalls( + ['group1', 'group2'], + ['group1', 'group3'], + ); } else { - $this->groupManager->expects($this->at(1)) - ->method('getUserGroupIds') - ->with($user3) - ->willReturn(['group3', 'group3']); + $this->groupManager->expects($this->exactly(2)) + ->method('getUserGroupIds') + ->withConsecutive( + [$user], + [$user3], + ) + ->willReturnOnConsecutiveCalls( + ['group1', 'group2'], + ['group3', 'group3'], + ); } $this->assertEquals($expects, $this->connector->findByUri($uri, 'principals/users')); diff --git a/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php index 995342db003..ad49f45f6b0 100644 --- a/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php @@ -304,21 +304,21 @@ class TagsPluginTest extends \Test\TestCase { ->with('/dummypath') ->willReturn($node); - $this->tagger->expects($this->at(0)) + $this->tagger->expects($this->once()) ->method('getTagsForObjects') ->with($this->equalTo([123])) ->willReturn([123 => ['tagkeep', 'tagremove', self::TAG_FAVORITE]]); // then tag as tag1 and tag2 - $this->tagger->expects($this->at(1)) - ->method('tagAs') - ->with(123, 'tag1'); - $this->tagger->expects($this->at(2)) + $this->tagger->expects($this->exactly(2)) ->method('tagAs') - ->with(123, 'tag2'); + ->withConsecutive( + [123, 'tag1'], + [123, 'tag2'], + ); // it will untag tag3 - $this->tagger->expects($this->at(3)) + $this->tagger->expects($this->once()) ->method('unTag') ->with(123, 'tagremove'); @@ -355,22 +355,22 @@ class TagsPluginTest extends \Test\TestCase { ->with('/dummypath') ->willReturn($node); - $this->tagger->expects($this->at(0)) + $this->tagger->expects($this->once()) ->method('getTagsForObjects') ->with($this->equalTo([123])) ->willReturn([]); // then tag as tag1 and tag2 - $this->tagger->expects($this->at(1)) - ->method('tagAs') - ->with(123, 'tag1'); - $this->tagger->expects($this->at(2)) + $this->tagger->expects($this->exactly(2)) ->method('tagAs') - ->with(123, 'tag2'); + ->withConsecutive( + [123, 'tag1'], + [123, 'tag2'], + ); // properties to set $propPatch = new \Sabre\DAV\PropPatch([ - self::TAGS_PROPERTYNAME => new \OCA\DAV\Connector\Sabre\TagList(['tag1', 'tag2', 'tagkeep']) + self::TAGS_PROPERTYNAME => new \OCA\DAV\Connector\Sabre\TagList(['tag1', 'tag2']) ]); $this->plugin->handleUpdateProperties( |