Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for email collaborators pagination #8710

Merged
merged 2 commits into from
Mar 9, 2018
Merged
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
6 changes: 5 additions & 1 deletion lib/private/Collaboration/Collaborators/MailPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,14 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
}
}

$reachedEnd = true;
if (!$this->shareeEnumeration) {
$result['wide'] = [];
$userResults['wide'] = [];
} else {
$reachedEnd = (count($result['wide']) < $offset + $limit) &&
(count($userResults['wide']) < $offset + $limit);

$result['wide'] = array_slice($result['wide'], $offset, $limit);
$userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
}
Expand All @@ -196,7 +200,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
}
$searchResult->addResultSet($emailType, $result['wide'], $result['exact']);

return true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a pretty bad assumption, so I had to fix all tests and wrote some where it is actually supposed to be true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its the default for anything that cannot (or could not) paginate. I took it over as it was when i refactored it.

return !$reachedEnd;
}

public function isCurrentUser(ICloudId $cloud): bool {
Expand Down
129 changes: 111 additions & 18 deletions tests/lib/Collaboration/Collaborators/MailPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\Federation\ICloudIdManager;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share;
use Test\TestCase;
Expand Down Expand Up @@ -98,6 +99,12 @@ function($appName, $key, $default)

$this->instantiatePlugin();

$currentUser = $this->createMock(IUser::class);
$currentUser->method('getUID')
->willReturn('current');
$this->userSession->method('getUser')
->willReturn($currentUser);

$this->contactsManager->expects($this->any())
->method('search')
->with($searchTerm, ['EMAIL', 'FN'])
Expand All @@ -113,31 +120,31 @@ function($appName, $key, $default)

public function dataGetEmail() {
return [
['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, true],
['test', [], false, ['emails' => [], 'exact' => ['emails' => []]], false, true],
['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, false],
['test', [], false, ['emails' => [], 'exact' => ['emails' => []]], false, false],
[
'test@remote.com',
[],
true,
['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
false,
true,
false,
],
[ // no valid email address
'test@remote',
[],
true,
['emails' => [], 'exact' => ['emails' => []]],
false,
true,
false,
],
[
'test@remote.com',
[],
false,
['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
false,
true,
false,
],
[
'test',
Expand All @@ -160,7 +167,7 @@ public function dataGetEmail() {
true,
['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => []]],
false,
true,
false,
],
[
'test',
Expand All @@ -183,7 +190,7 @@ public function dataGetEmail() {
false,
['emails' => [], 'exact' => ['emails' => []]],
false,
true,
false,
],
[
'test@remote.com',
Expand All @@ -206,7 +213,7 @@ public function dataGetEmail() {
true,
['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
false,
true,
false,
],
[
'test@remote.com',
Expand All @@ -229,7 +236,7 @@ public function dataGetEmail() {
false,
['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
false,
true,
false,
],
[
'username@localhost',
Expand All @@ -252,7 +259,7 @@ public function dataGetEmail() {
true,
['emails' => [], 'exact' => ['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]],
true,
true,
false,
],
[
'username@localhost',
Expand All @@ -275,7 +282,7 @@ public function dataGetEmail() {
false,
['emails' => [], 'exact' => ['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]],
true,
true,
false,
],
// contact with space
[
Expand All @@ -299,7 +306,7 @@ public function dataGetEmail() {
false,
['emails' => [], 'exact' => ['emails' => [['label' => 'User Name @ Localhost (user name@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'user name@localhost']]]]],
true,
true,
false,
],
// remote with space, no contact
[
Expand All @@ -323,7 +330,7 @@ public function dataGetEmail() {
false,
['emails' => [], 'exact' => ['emails' => []]],
false,
true,
false,
],
// Local user found by email
[
Expand All @@ -337,10 +344,96 @@ public function dataGetEmail() {
]
],
false,
['users' => [], 'exact' => ['users' => [['label' => 'User (test@example.com)','value' => ['shareType' => 0, 'shareWith' => 'test'],]]]],
['users' => [], 'exact' => ['users' => [['label' => 'User (test@example.com)','value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test'],]]]],
true,
false,
]
],
// Current local user found by email => no result
[
'test@example.com',
[
[
'FN' => 'User',
'EMAIL' => ['test@example.com'],
'CLOUD' => ['current@localhost'],
'isLocalSystemBook' => true,
]
],
true,
['exact' => []],
false,
false,
],
// Pagination and "more results" for user matches byyyyyyy emails
[
'test@example',
[
[
'FN' => 'User1',
'EMAIL' => ['test@example.com'],
'CLOUD' => ['test1@localhost'],
'isLocalSystemBook' => true,
],
[
'FN' => 'User2',
'EMAIL' => ['test@example.de'],
'CLOUD' => ['test2@localhost'],
'isLocalSystemBook' => true,
],
[
'FN' => 'User3',
'EMAIL' => ['test@example.org'],
'CLOUD' => ['test3@localhost'],
'isLocalSystemBook' => true,
],
[
'FN' => 'User4',
'EMAIL' => ['test@example.net'],
'CLOUD' => ['test4@localhost'],
'isLocalSystemBook' => true,
],
],
true,
['users' => [
['label' => 'User1 (test@example.com)', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
['label' => 'User2 (test@example.de)', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']],
], 'emails' => [], 'exact' => ['users' => [], 'emails' => []]],
false,
true,
],
// Pagination and "more results" for normal emails
[
'test@example',
[
[
'FN' => 'User1',
'EMAIL' => ['test@example.com'],
'CLOUD' => ['test1@localhost'],
],
[
'FN' => 'User2',
'EMAIL' => ['test@example.de'],
'CLOUD' => ['test2@localhost'],
],
[
'FN' => 'User3',
'EMAIL' => ['test@example.org'],
'CLOUD' => ['test3@localhost'],
],
[
'FN' => 'User4',
'EMAIL' => ['test@example.net'],
'CLOUD' => ['test4@localhost'],
],
],
true,
['emails' => [
['label' => 'User1 (test@example.com)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@example.com']],
['label' => 'User2 (test@example.de)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@example.de']],
], 'exact' => ['emails' => []]],
false,
true,
],
];
}

Expand Down Expand Up @@ -422,7 +515,7 @@ public function dataGetEmailGroupsOnly() {
],
['users' => [['label' => 'User (test@example.com)','value' => ['shareType' => 0, 'shareWith' => 'test'],]], 'emails' => [], 'exact' => ['emails' => [], 'users' => []]],
false,
true,
false,
[
"currentUser" => ["group1"],
"User" => ["group1"]
Expand All @@ -442,7 +535,7 @@ public function dataGetEmailGroupsOnly() {
],
['emails'=> [], 'exact' => ['emails' => []]],
false,
true,
false,
[
"currentUser" => ["group1"],
"User" => ["group2"]
Expand All @@ -462,7 +555,7 @@ public function dataGetEmailGroupsOnly() {
],
['emails' => [], 'exact' => ['emails' => [['label' => 'test@example.com', 'value' => ['shareType' => 4,'shareWith' => 'test@example.com']]]]],
false,
true,
false,
[
"currentUser" => ["group1"],
"User" => ["group2"]
Expand Down