|
|
|
|
@ -35,6 +35,7 @@ use OCP\IGroupManager;
|
|
|
|
|
use OCP\IUser;
|
|
|
|
|
use OCP\IUserSession;
|
|
|
|
|
use OCP\Share\IShare;
|
|
|
|
|
use OCP\Mail\IMailer;
|
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class MailPluginTest extends TestCase {
|
|
|
|
|
@ -62,6 +63,9 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
|
protected $userSession;
|
|
|
|
|
|
|
|
|
|
/** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
|
protected $mailer;
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
@ -70,6 +74,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
|
|
|
|
$this->knownUserService = $this->createMock(KnownUserService::class);
|
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
|
$this->mailer = $this->createMock(IMailer::class);
|
|
|
|
|
$this->cloudIdManager = new CloudIdManager($this->contactsManager);
|
|
|
|
|
|
|
|
|
|
$this->searchResult = new SearchResult();
|
|
|
|
|
@ -82,7 +87,8 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
$this->config,
|
|
|
|
|
$this->groupManager,
|
|
|
|
|
$this->knownUserService,
|
|
|
|
|
$this->userSession
|
|
|
|
|
$this->userSession,
|
|
|
|
|
$this->mailer
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -95,7 +101,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
* @param array $expected
|
|
|
|
|
* @param bool $reachedEnd
|
|
|
|
|
*/
|
|
|
|
|
public function testSearch($searchTerm, $contacts, $shareeEnumeration, $expected, $exactIdMatch, $reachedEnd) {
|
|
|
|
|
public function testSearch($searchTerm, $contacts, $shareeEnumeration, $expected, $exactIdMatch, $reachedEnd, $validEmail) {
|
|
|
|
|
$this->config->expects($this->any())
|
|
|
|
|
->method('getAppValue')
|
|
|
|
|
->willReturnCallback(
|
|
|
|
|
@ -115,6 +121,9 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
$this->userSession->method('getUser')
|
|
|
|
|
->willReturn($currentUser);
|
|
|
|
|
|
|
|
|
|
$this->mailer->method('validateMailAddress')
|
|
|
|
|
->willReturn($validEmail);
|
|
|
|
|
|
|
|
|
|
$this->contactsManager->expects($this->any())
|
|
|
|
|
->method('search')
|
|
|
|
|
->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
|
|
|
|
|
@ -135,9 +144,9 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
public function dataGetEmail() {
|
|
|
|
|
return [
|
|
|
|
|
// data set 0
|
|
|
|
|
['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, false],
|
|
|
|
|
['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, false, false],
|
|
|
|
|
// data set 1
|
|
|
|
|
['test', [], false, ['emails' => [], 'exact' => ['emails' => []]], false, false],
|
|
|
|
|
['test', [], false, ['emails' => [], 'exact' => ['emails' => []]], false, false, false],
|
|
|
|
|
// data set 2
|
|
|
|
|
[
|
|
|
|
|
'test@remote.com',
|
|
|
|
|
@ -146,6 +155,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [], 'exact' => ['emails' => [['uuid' => 'test@remote.com', 'label' => 'test@remote.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
],
|
|
|
|
|
// data set 3
|
|
|
|
|
[ // no valid email address
|
|
|
|
|
@ -155,6 +165,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [], 'exact' => ['emails' => []]],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// data set 4
|
|
|
|
|
[
|
|
|
|
|
@ -164,6 +175,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [], 'exact' => ['emails' => [['uuid' => 'test@remote.com', 'label' => 'test@remote.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
],
|
|
|
|
|
// data set 5
|
|
|
|
|
[
|
|
|
|
|
@ -191,6 +203,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [['uuid' => 'uid1', 'name' => 'User @ Localhost', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => []]],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// data set 6
|
|
|
|
|
[
|
|
|
|
|
@ -218,6 +231,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [], 'exact' => ['emails' => []]],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// data set 7
|
|
|
|
|
[
|
|
|
|
|
@ -245,6 +259,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [['uuid' => 'uid1', 'name' => 'User @ Localhost', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => [['label' => 'test@remote.com', 'uuid' => 'test@remote.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
],
|
|
|
|
|
// data set 8
|
|
|
|
|
[
|
|
|
|
|
@ -272,6 +287,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'uuid' => 'test@remote.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
],
|
|
|
|
|
// data set 9
|
|
|
|
|
[
|
|
|
|
|
@ -299,6 +315,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [], 'exact' => ['emails' => [['name' => 'User @ Localhost', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]],
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// data set 10
|
|
|
|
|
[
|
|
|
|
|
@ -326,6 +343,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [], 'exact' => ['emails' => [['name' => 'User @ Localhost', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]],
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// data set 11
|
|
|
|
|
// contact with space
|
|
|
|
|
@ -354,6 +372,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [], 'exact' => ['emails' => [['name' => 'User Name @ Localhost', 'uuid' => 'uid1', 'type' => '', 'label' => 'User Name @ Localhost (user name@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'user name@localhost']]]]],
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// data set 12
|
|
|
|
|
// remote with space, no contact
|
|
|
|
|
@ -382,6 +401,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['emails' => [], 'exact' => ['emails' => []]],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// data set 13
|
|
|
|
|
// Local user found by email
|
|
|
|
|
@ -400,6 +420,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['users' => [], 'exact' => ['users' => [['uuid' => 'uid1', 'name' => 'User', 'label' => 'User (test@example.com)','value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => 'test@example.com']]]],
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
],
|
|
|
|
|
// data set 14
|
|
|
|
|
// Current local user found by email => no result
|
|
|
|
|
@ -418,6 +439,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
['exact' => []],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
],
|
|
|
|
|
// data set 15
|
|
|
|
|
// Pagination and "more results" for user matches byyyyyyy emails
|
|
|
|
|
@ -460,6 +482,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
], 'emails' => [], 'exact' => ['users' => [], 'emails' => []]],
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// data set 16
|
|
|
|
|
// Pagination and "more results" for normal emails
|
|
|
|
|
@ -498,6 +521,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
], 'exact' => ['emails' => []]],
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// data set 17
|
|
|
|
|
// multiple email addresses with type
|
|
|
|
|
@ -531,6 +555,18 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
]]],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// data set 18
|
|
|
|
|
// idn email
|
|
|
|
|
[
|
|
|
|
|
'test@lölölölölölölöl.com',
|
|
|
|
|
[],
|
|
|
|
|
true,
|
|
|
|
|
['emails' => [], 'exact' => ['emails' => [['uuid' => 'test@lölölölölölölöl.com', 'label' => 'test@lölölölölölölöl.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@lölölölölölölöl.com']]]]],
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
@ -545,7 +581,7 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
* @param bool $reachedEnd
|
|
|
|
|
* @param array groups
|
|
|
|
|
*/
|
|
|
|
|
public function testSearchGroupsOnly($searchTerm, $contacts, $expected, $exactIdMatch, $reachedEnd, $userToGroupMapping) {
|
|
|
|
|
public function testSearchGroupsOnly($searchTerm, $contacts, $expected, $exactIdMatch, $reachedEnd, $userToGroupMapping, $validEmail) {
|
|
|
|
|
$this->config->expects($this->any())
|
|
|
|
|
->method('getAppValue')
|
|
|
|
|
->willReturnCallback(
|
|
|
|
|
@ -568,6 +604,9 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
->method('getUID')
|
|
|
|
|
->willReturn('currentUser');
|
|
|
|
|
|
|
|
|
|
$this->mailer->method('validateMailAddress')
|
|
|
|
|
->willReturn($validEmail);
|
|
|
|
|
|
|
|
|
|
$this->contactsManager->expects($this->any())
|
|
|
|
|
->method('search')
|
|
|
|
|
->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
|
|
|
|
|
@ -621,7 +660,8 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
[
|
|
|
|
|
"currentUser" => ["group1"],
|
|
|
|
|
"User" => ["group1"]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// The user `User` cannot share with the current user
|
|
|
|
|
[
|
|
|
|
|
@ -641,7 +681,8 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
[
|
|
|
|
|
"currentUser" => ["group1"],
|
|
|
|
|
"User" => ["group2"]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
// The user `User` cannot share with the current user, but there is an exact match on the e-mail address -> share by e-mail
|
|
|
|
|
[
|
|
|
|
|
@ -661,7 +702,8 @@ class MailPluginTest extends TestCase {
|
|
|
|
|
[
|
|
|
|
|
"currentUser" => ["group1"],
|
|
|
|
|
"User" => ["group2"]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|