From d776890228ef06d5c1a817b8b0e6957925eb0560 Mon Sep 17 00:00:00 2001 From: Johannes Merkel Date: Mon, 19 Jun 2023 17:56:15 +0200 Subject: [PATCH] test(ContactsIntegration): Add unittests getMatchingRecipient Signed-off-by: Johannes Merkel --- .../Unit/Service/ContactsIntegrationTest.php | 179 +++++++++--------- 1 file changed, 93 insertions(+), 86 deletions(-) diff --git a/tests/Unit/Service/ContactsIntegrationTest.php b/tests/Unit/Service/ContactsIntegrationTest.php index b607b61cc8..7a1c42cfa7 100644 --- a/tests/Unit/Service/ContactsIntegrationTest.php +++ b/tests/Unit/Service/ContactsIntegrationTest.php @@ -151,7 +151,7 @@ public function testGetMatchingRecipientRestrictedToGroup() { ], ]; - $this->common($term, $searchResult, true, true, false, false); + $this->common($term, $searchResult, true, true, false, false, false); $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') @@ -191,150 +191,157 @@ public function testGetMatchingRecipientRestrictedToGroup() { $this->assertEquals($expected, $actual); } - public function testGetMatchingRecipientRestrictedToFullMatch() { - $term = 'jo'; // searching for: John Doe + public function testGetMatchingRecipientRestrictedToGroupFullMatchUserId() { + $term = 'jf'; // searching for: Jonathan Frakes $searchResult = [ [ + // Simple match 'UID' => 'jf', 'FN' => 'Jonathan Frakes', 'EMAIL' => 'jonathan@frakes.com', 'isLocalSystemBook' => true, ], - [ - 'UID' => 'jd', - 'FN' => 'John Doe', - 'EMAIL' => [ - 'john@doe.info', - 'doe@john.info', - ], - 'isLocalSystemBook' => true, - ], - [ - 'UID' => 'js', - 'FN' => 'Johann Strauss II', - 'EMAIL' => 'johann@strauss.com', - ], ]; - $this->common($term, $searchResult, true, false, true); + + $this->common($term, $searchResult, true, true, true); + $user = $this->createMock(IUser::class); + $this->userManager->expects($this->once()) + ->method('get') + ->with('auser') + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->will($this->returnValue(['agroup'])); + $this->groupManager->expects(self::exactly(1)) + ->method('isInGroup') + ->withConsecutive(['jf', 'agroup']) + ->willReturnOnConsecutiveCalls(false); $expected = [ [ - 'id' => 'js', - 'label' => 'Johann Strauss II (johann@strauss.com)', - 'email' => 'johann@strauss.com', + 'id' => 'jf', + 'label' => 'Jonathan Frakes (jonathan@frakes.com)', + 'email' => 'jonathan@frakes.com', 'photo' => null, ], ]; - $actual = $this->contactsIntegration->getMatchingRecipient("", $term); + $actual = $this->contactsIntegration->getMatchingRecipient("auser", $term); $this->assertEquals($expected, $actual); } - public function testGetMatchingRecipientRestrictedToFullMatchFullName() { - $term = 'john doe'; // searching for: John Doe + public function testGetMatchingRecipientRestrictedToGroupFullMatchFullName() { + $term = 'Jonathan Frakes'; // searching for: Jonathan Frakes $searchResult = [ [ - // Array of addresses - 'UID' => 'jd', - 'FN' => 'John Doe', - 'EMAIL' => [ - 'john@doe.info', - 'doe@john.info', - ], + // Simple match + 'UID' => 'jf', + 'FN' => 'Jonathan Frakes', + 'EMAIL' => 'jonathan@frakes.com', 'isLocalSystemBook' => true, - ] + ], ]; - $this->common($term, $searchResult, true, false, true); + $this->common($term, $searchResult, true, true, true); + $user = $this->createMock(IUser::class); + $this->userManager->expects($this->once()) + ->method('get') + ->with('auser') + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->will($this->returnValue(['agroup'])); + $this->groupManager->expects(self::exactly(1)) + ->method('isInGroup') + ->withConsecutive(['jf', 'agroup']) + ->willReturnOnConsecutiveCalls(false); $expected = [ [ - 'id' => 'jd', - 'label' => 'John Doe (john@doe.info)', - 'email' => 'john@doe.info', - 'photo' => null, - ], - [ - 'id' => 'jd', - 'label' => 'John Doe (doe@john.info)', - 'email' => 'doe@john.info', + 'id' => 'jf', + 'label' => 'Jonathan Frakes (jonathan@frakes.com)', + 'email' => 'jonathan@frakes.com', 'photo' => null, ], ]; - $actual = $this->contactsIntegration->getMatchingRecipient("", $term); + $actual = $this->contactsIntegration->getMatchingRecipient("auser", $term); $this->assertEquals($expected, $actual); } - public function testGetMatchingRecipientRestrictedToFullMatchUserId() { - $term = 'jd'; // searching for: John Doe + public function testGetMatchingRecipientRestrictedToGroupFullMatchEmail() { + $term = 'jonathan@frakes.com'; // searching for: Jonathan Frakes $searchResult = [ [ - // Array of addresses - 'UID' => 'jd', - 'FN' => 'John Doe', - 'EMAIL' => [ - 'john@doe.info', - 'doe@john.info', - ], + // Simple match + 'UID' => 'jf', + 'FN' => 'Jonathan Frakes', + 'EMAIL' => 'jonathan@frakes.com', 'isLocalSystemBook' => true, - ] + ], ]; - $this->common($term, $searchResult, true, false, true); + $this->common($term, $searchResult, true, true, true); + $user = $this->createMock(IUser::class); + $this->userManager->expects($this->once()) + ->method('get') + ->with('auser') + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->will($this->returnValue(['agroup'])); + $this->groupManager->expects(self::exactly(1)) + ->method('isInGroup') + ->withConsecutive(['jf', 'agroup']) + ->willReturnOnConsecutiveCalls(false); $expected = [ [ - 'id' => 'jd', - 'label' => 'John Doe (john@doe.info)', - 'email' => 'john@doe.info', - 'photo' => null, - ], - [ - 'id' => 'jd', - 'label' => 'John Doe (doe@john.info)', - 'email' => 'doe@john.info', + 'id' => 'jf', + 'label' => 'Jonathan Frakes (jonathan@frakes.com)', + 'email' => 'jonathan@frakes.com', 'photo' => null, ], ]; - $actual = $this->contactsIntegration->getMatchingRecipient("", $term); + $actual = $this->contactsIntegration->getMatchingRecipient("auser", $term); $this->assertEquals($expected, $actual); } + public function testGetMatchingRecipientRestrictedToGroupFullMatchFalse() { + $term = 'jf'; // searching for: Jonathan Frakes - - public function testGetMatchingRecipientRestrictedToFullMatchEmail() { - $term = 'doe@john.info'; // searching for: John Doe $searchResult = [ [ - // Array of addresses - 'UID' => 'jd', - 'FN' => 'John Doe', - 'EMAIL' => [ - 'john@doe.info', - 'doe@john.info', - ], + // Simple match + 'UID' => 'jf', + 'FN' => 'Jonathan Frakes', + 'EMAIL' => 'jonathan@frakes.com', 'isLocalSystemBook' => true, - ] + ], ]; - $this->common($term, $searchResult, true, false, true); + $this->common($term, $searchResult, true, true, false, false, false); - $expected = [ - [ - 'id' => 'jd', - 'label' => 'John Doe (doe@john.info)', - 'email' => 'doe@john.info', - 'photo' => null, - ], - ]; + $user = $this->createMock(IUser::class); + $this->userManager->expects($this->once()) + ->method('get') + ->with('auser') + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->will($this->returnValue(['agroup'])); + $this->groupManager->expects(self::exactly(1)) + ->method('isInGroup') + ->withConsecutive(['jf', 'agroup']) + ->willReturnOnConsecutiveCalls(false); - $actual = $this->contactsIntegration->getMatchingRecipient("", $term); + $expected = []; + $actual = $this->contactsIntegration->getMatchingRecipient("auser", $term); $this->assertEquals($expected, $actual); } @@ -359,7 +366,7 @@ public function common($term, $searchResult, $allowSystemUsers, $allowSystemUser ->will($this->returnValue(true)); $this->contactsManager->expects($this->once()) ->method('search') - ->with($term, ['UID', 'FN', 'EMAIL'], ['enumeration' => $allowSystemUsers]) + ->with($term, ['UID', 'FN', 'EMAIL'], ['enumeration' => $allowSystemUsers, 'fullmatch' => $shareeEnumerationFullMatch]) ->will($this->returnValue($searchResult)); }