MailPluginTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Collaboration\Collaborators;
  24. use OC\Collaboration\Collaborators\MailPlugin;
  25. use OC\Collaboration\Collaborators\SearchResult;
  26. use OC\Federation\CloudIdManager;
  27. use OC\KnownUser\KnownUserService;
  28. use OCP\Collaboration\Collaborators\SearchResultType;
  29. use OCP\Contacts\IManager;
  30. use OCP\EventDispatcher\IEventDispatcher;
  31. use OCP\Federation\ICloudIdManager;
  32. use OCP\ICacheFactory;
  33. use OCP\IConfig;
  34. use OCP\IGroupManager;
  35. use OCP\IURLGenerator;
  36. use OCP\IUser;
  37. use OCP\IUserManager;
  38. use OCP\IUserSession;
  39. use OCP\Share\IShare;
  40. use OCP\Mail\IMailer;
  41. use Test\TestCase;
  42. class MailPluginTest extends TestCase {
  43. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  44. protected $config;
  45. /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
  46. protected $contactsManager;
  47. /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */
  48. protected $cloudIdManager;
  49. /** @var MailPlugin */
  50. protected $plugin;
  51. /** @var SearchResult */
  52. protected $searchResult;
  53. /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
  54. protected $groupManager;
  55. /** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */
  56. protected $knownUserService;
  57. /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
  58. protected $userSession;
  59. /** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
  60. protected $mailer;
  61. protected function setUp(): void {
  62. parent::setUp();
  63. $this->config = $this->createMock(IConfig::class);
  64. $this->contactsManager = $this->createMock(IManager::class);
  65. $this->groupManager = $this->createMock(IGroupManager::class);
  66. $this->knownUserService = $this->createMock(KnownUserService::class);
  67. $this->userSession = $this->createMock(IUserSession::class);
  68. $this->mailer = $this->createMock(IMailer::class);
  69. $this->cloudIdManager = new CloudIdManager(
  70. $this->contactsManager,
  71. $this->createMock(IURLGenerator::class),
  72. $this->createMock(IUserManager::class),
  73. $this->createMock(ICacheFactory::class),
  74. $this->createMock(IEventDispatcher::class)
  75. );
  76. $this->searchResult = new SearchResult();
  77. }
  78. public function instantiatePlugin() {
  79. $this->plugin = new MailPlugin(
  80. $this->contactsManager,
  81. $this->cloudIdManager,
  82. $this->config,
  83. $this->groupManager,
  84. $this->knownUserService,
  85. $this->userSession,
  86. $this->mailer
  87. );
  88. }
  89. /**
  90. * @dataProvider dataGetEmail
  91. *
  92. * @param string $searchTerm
  93. * @param array $contacts
  94. * @param bool $shareeEnumeration
  95. * @param array $expected
  96. * @param bool $reachedEnd
  97. */
  98. public function testSearch($searchTerm, $contacts, $shareeEnumeration, $expected, $exactIdMatch, $reachedEnd, $validEmail) {
  99. $this->config->expects($this->any())
  100. ->method('getAppValue')
  101. ->willReturnCallback(
  102. function ($appName, $key, $default) use ($shareeEnumeration) {
  103. if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
  104. return $shareeEnumeration ? 'yes' : 'no';
  105. }
  106. return $default;
  107. }
  108. );
  109. $this->instantiatePlugin();
  110. $currentUser = $this->createMock(IUser::class);
  111. $currentUser->method('getUID')
  112. ->willReturn('current');
  113. $this->userSession->method('getUser')
  114. ->willReturn($currentUser);
  115. $this->mailer->method('validateMailAddress')
  116. ->willReturn($validEmail);
  117. $this->contactsManager->expects($this->any())
  118. ->method('search')
  119. ->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
  120. if ($search === $searchTerm) {
  121. return $contacts;
  122. }
  123. return [];
  124. });
  125. $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult);
  126. $result = $this->searchResult->asArray();
  127. $this->assertSame($exactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails')));
  128. $this->assertEquals($expected, $result);
  129. $this->assertSame($reachedEnd, $moreResults);
  130. }
  131. public function dataGetEmail() {
  132. return [
  133. // data set 0
  134. ['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, false, false],
  135. // data set 1
  136. ['test', [], false, ['emails' => [], 'exact' => ['emails' => []]], false, false, false],
  137. // data set 2
  138. [
  139. 'test@remote.com',
  140. [],
  141. true,
  142. ['emails' => [], 'exact' => ['emails' => [['uuid' => 'test@remote.com', 'label' => 'test@remote.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
  143. false,
  144. false,
  145. true,
  146. ],
  147. // data set 3
  148. [ // no valid email address
  149. 'test@remote',
  150. [],
  151. true,
  152. ['emails' => [], 'exact' => ['emails' => []]],
  153. false,
  154. false,
  155. false,
  156. ],
  157. // data set 4
  158. [
  159. 'test@remote.com',
  160. [],
  161. false,
  162. ['emails' => [], 'exact' => ['emails' => [['uuid' => 'test@remote.com', 'label' => 'test@remote.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
  163. false,
  164. false,
  165. true,
  166. ],
  167. // data set 5
  168. [
  169. 'test',
  170. [
  171. [
  172. 'UID' => 'uid3',
  173. 'FN' => 'User3 @ Localhost',
  174. ],
  175. [
  176. 'UID' => 'uid2',
  177. 'FN' => 'User2 @ Localhost',
  178. 'EMAIL' => [
  179. ],
  180. ],
  181. [
  182. 'UID' => 'uid1',
  183. 'FN' => 'User @ Localhost',
  184. 'EMAIL' => [
  185. 'username@localhost',
  186. ],
  187. ],
  188. ],
  189. true,
  190. ['emails' => [['uuid' => 'uid1', 'name' => 'User @ Localhost', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => []]],
  191. false,
  192. false,
  193. false,
  194. ],
  195. // data set 6
  196. [
  197. 'test',
  198. [
  199. [
  200. 'UID' => 'uid3',
  201. 'FN' => 'User3 @ Localhost',
  202. ],
  203. [
  204. 'UID' => 'uid2',
  205. 'FN' => 'User2 @ Localhost',
  206. 'EMAIL' => [
  207. ],
  208. ],
  209. [
  210. 'isLocalSystemBook' => true,
  211. 'UID' => 'uid1',
  212. 'FN' => 'User @ Localhost',
  213. 'EMAIL' => [
  214. 'username@localhost',
  215. ],
  216. ],
  217. ],
  218. false,
  219. ['emails' => [], 'exact' => ['emails' => []]],
  220. false,
  221. false,
  222. false,
  223. ],
  224. // data set 7
  225. [
  226. 'test@remote.com',
  227. [
  228. [
  229. 'UID' => 'uid3',
  230. 'FN' => 'User3 @ Localhost',
  231. ],
  232. [
  233. 'UID' => 'uid2',
  234. 'FN' => 'User2 @ Localhost',
  235. 'EMAIL' => [
  236. ],
  237. ],
  238. [
  239. 'UID' => 'uid1',
  240. 'FN' => 'User @ Localhost',
  241. 'EMAIL' => [
  242. 'username@localhost',
  243. ],
  244. ],
  245. ],
  246. true,
  247. ['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']]]]],
  248. false,
  249. false,
  250. true,
  251. ],
  252. // data set 8
  253. [
  254. 'test@remote.com',
  255. [
  256. [
  257. 'UID' => 'uid3',
  258. 'FN' => 'User3 @ Localhost',
  259. ],
  260. [
  261. 'UID' => 'uid2',
  262. 'FN' => 'User2 @ Localhost',
  263. 'EMAIL' => [
  264. ],
  265. ],
  266. [
  267. 'isLocalSystemBook' => true,
  268. 'UID' => 'uid1',
  269. 'FN' => 'User @ Localhost',
  270. 'EMAIL' => [
  271. 'username@localhost',
  272. ],
  273. ],
  274. ],
  275. false,
  276. ['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'uuid' => 'test@remote.com', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
  277. false,
  278. false,
  279. true,
  280. ],
  281. // data set 9
  282. [
  283. 'username@localhost',
  284. [
  285. [
  286. 'UID' => 'uid3',
  287. 'FN' => 'User3 @ Localhost',
  288. ],
  289. [
  290. 'UID' => 'uid2',
  291. 'FN' => 'User2 @ Localhost',
  292. 'EMAIL' => [
  293. ],
  294. ],
  295. [
  296. 'UID' => 'uid1',
  297. 'FN' => 'User @ Localhost',
  298. 'EMAIL' => [
  299. 'username@localhost',
  300. ],
  301. ],
  302. ],
  303. true,
  304. ['emails' => [], 'exact' => ['emails' => [['name' => 'User @ Localhost', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]],
  305. true,
  306. false,
  307. false,
  308. ],
  309. // data set 10
  310. [
  311. 'username@localhost',
  312. [
  313. [
  314. 'UID' => 'uid1',
  315. 'FN' => 'User3 @ Localhost',
  316. ],
  317. [
  318. 'UID' => 'uid2',
  319. 'FN' => 'User2 @ Localhost',
  320. 'EMAIL' => [
  321. ],
  322. ],
  323. [
  324. 'UID' => 'uid1',
  325. 'FN' => 'User @ Localhost',
  326. 'EMAIL' => [
  327. 'username@localhost',
  328. ],
  329. ],
  330. ],
  331. false,
  332. ['emails' => [], 'exact' => ['emails' => [['name' => 'User @ Localhost', 'uuid' => 'uid1', 'type' => '', 'label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]],
  333. true,
  334. false,
  335. false,
  336. ],
  337. // data set 11
  338. // contact with space
  339. [
  340. 'user name@localhost',
  341. [
  342. [
  343. 'UID' => 'uid3',
  344. 'FN' => 'User3 @ Localhost',
  345. ],
  346. [
  347. 'UID' => 'uid2',
  348. 'FN' => 'User2 @ Localhost',
  349. 'EMAIL' => [
  350. ],
  351. ],
  352. [
  353. 'UID' => 'uid1',
  354. 'FN' => 'User Name @ Localhost',
  355. 'EMAIL' => [
  356. 'user name@localhost',
  357. ],
  358. ],
  359. ],
  360. false,
  361. ['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']]]]],
  362. true,
  363. false,
  364. false,
  365. ],
  366. // data set 12
  367. // remote with space, no contact
  368. [
  369. 'user space@remote.com',
  370. [
  371. [
  372. 'UID' => 'uid3',
  373. 'FN' => 'User3 @ Localhost',
  374. ],
  375. [
  376. 'UID' => 'uid2',
  377. 'FN' => 'User2 @ Localhost',
  378. 'EMAIL' => [
  379. ],
  380. ],
  381. [
  382. 'isLocalSystemBook' => true,
  383. 'UID' => 'uid1',
  384. 'FN' => 'User @ Localhost',
  385. 'EMAIL' => [
  386. 'username@localhost',
  387. ],
  388. ],
  389. ],
  390. false,
  391. ['emails' => [], 'exact' => ['emails' => []]],
  392. false,
  393. false,
  394. false,
  395. ],
  396. // data set 13
  397. // Local user found by email
  398. [
  399. 'test@example.com',
  400. [
  401. [
  402. 'UID' => 'uid1',
  403. 'FN' => 'User',
  404. 'EMAIL' => ['test@example.com'],
  405. 'CLOUD' => ['test@localhost'],
  406. 'isLocalSystemBook' => true,
  407. ]
  408. ],
  409. false,
  410. ['users' => [], 'exact' => ['users' => [['uuid' => 'uid1', 'name' => 'User', 'label' => 'User (test@example.com)','value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => 'test@example.com']]]],
  411. true,
  412. false,
  413. true,
  414. ],
  415. // data set 14
  416. // Current local user found by email => no result
  417. [
  418. 'test@example.com',
  419. [
  420. [
  421. 'UID' => 'uid1',
  422. 'FN' => 'User',
  423. 'EMAIL' => ['test@example.com'],
  424. 'CLOUD' => ['current@localhost'],
  425. 'isLocalSystemBook' => true,
  426. ]
  427. ],
  428. true,
  429. ['exact' => []],
  430. false,
  431. false,
  432. true,
  433. ],
  434. // data set 15
  435. // Pagination and "more results" for user matches byyyyyyy emails
  436. [
  437. 'test@example',
  438. [
  439. [
  440. 'UID' => 'uid1',
  441. 'FN' => 'User1',
  442. 'EMAIL' => ['test@example.com'],
  443. 'CLOUD' => ['test1@localhost'],
  444. 'isLocalSystemBook' => true,
  445. ],
  446. [
  447. 'UID' => 'uid2',
  448. 'FN' => 'User2',
  449. 'EMAIL' => ['test@example.de'],
  450. 'CLOUD' => ['test2@localhost'],
  451. 'isLocalSystemBook' => true,
  452. ],
  453. [
  454. 'UID' => 'uid3',
  455. 'FN' => 'User3',
  456. 'EMAIL' => ['test@example.org'],
  457. 'CLOUD' => ['test3@localhost'],
  458. 'isLocalSystemBook' => true,
  459. ],
  460. [
  461. 'UID' => 'uid4',
  462. 'FN' => 'User4',
  463. 'EMAIL' => ['test@example.net'],
  464. 'CLOUD' => ['test4@localhost'],
  465. 'isLocalSystemBook' => true,
  466. ],
  467. ],
  468. true,
  469. ['users' => [
  470. ['uuid' => 'uid1', 'name' => 'User1', 'label' => 'User1 (test@example.com)', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'shareWithDisplayNameUnique' => 'test@example.com'],
  471. ['uuid' => 'uid2', 'name' => 'User2', 'label' => 'User2 (test@example.de)', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'shareWithDisplayNameUnique' => 'test@example.de'],
  472. ], 'emails' => [], 'exact' => ['users' => [], 'emails' => []]],
  473. false,
  474. true,
  475. false,
  476. ],
  477. // data set 16
  478. // Pagination and "more results" for normal emails
  479. [
  480. 'test@example',
  481. [
  482. [
  483. 'UID' => 'uid1',
  484. 'FN' => 'User1',
  485. 'EMAIL' => ['test@example.com'],
  486. 'CLOUD' => ['test1@localhost'],
  487. ],
  488. [
  489. 'UID' => 'uid2',
  490. 'FN' => 'User2',
  491. 'EMAIL' => ['test@example.de'],
  492. 'CLOUD' => ['test2@localhost'],
  493. ],
  494. [
  495. 'UID' => 'uid3',
  496. 'FN' => 'User3',
  497. 'EMAIL' => ['test@example.org'],
  498. 'CLOUD' => ['test3@localhost'],
  499. ],
  500. [
  501. 'UID' => 'uid4',
  502. 'FN' => 'User4',
  503. 'EMAIL' => ['test@example.net'],
  504. 'CLOUD' => ['test4@localhost'],
  505. ],
  506. ],
  507. true,
  508. ['emails' => [
  509. ['uuid' => 'uid1', 'name' => 'User1', 'type' => '', 'label' => 'User1 (test@example.com)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@example.com']],
  510. ['uuid' => 'uid2', 'name' => 'User2', 'type' => '', 'label' => 'User2 (test@example.de)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'test@example.de']],
  511. ], 'exact' => ['emails' => []]],
  512. false,
  513. true,
  514. false,
  515. ],
  516. // data set 17
  517. // multiple email addresses with type
  518. [
  519. 'User Name',
  520. [
  521. [
  522. 'UID' => 'uid3',
  523. 'FN' => 'User3',
  524. ],
  525. [
  526. 'UID' => 'uid2',
  527. 'FN' => 'User2',
  528. 'EMAIL' => [
  529. ],
  530. ],
  531. [
  532. 'UID' => 'uid1',
  533. 'FN' => 'User Name',
  534. 'EMAIL' => [
  535. ['type' => 'HOME', 'value' => 'username@localhost'],
  536. ['type' => 'WORK', 'value' => 'username@other'],
  537. ],
  538. ],
  539. ],
  540. false,
  541. ['emails' => [
  542. ], 'exact' => ['emails' => [
  543. ['name' => 'User Name', 'uuid' => 'uid1', 'type' => 'HOME', 'label' => 'User Name (username@localhost)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@localhost']],
  544. ['name' => 'User Name', 'uuid' => 'uid1', 'type' => 'WORK', 'label' => 'User Name (username@other)', 'value' => ['shareType' => IShare::TYPE_EMAIL, 'shareWith' => 'username@other']]
  545. ]]],
  546. false,
  547. false,
  548. false,
  549. ],
  550. // data set 18
  551. // idn email
  552. [
  553. 'test@lölölölölölölöl.com',
  554. [],
  555. true,
  556. ['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']]]]],
  557. false,
  558. false,
  559. true,
  560. ],
  561. ];
  562. }
  563. /**
  564. * @dataProvider dataGetEmailGroupsOnly
  565. *
  566. * @param string $searchTerm
  567. * @param array $contacts
  568. * @param array $expected
  569. * @param bool $exactIdMatch
  570. * @param bool $reachedEnd
  571. * @param array groups
  572. */
  573. public function testSearchGroupsOnly($searchTerm, $contacts, $expected, $exactIdMatch, $reachedEnd, $userToGroupMapping, $validEmail) {
  574. $this->config->expects($this->any())
  575. ->method('getAppValue')
  576. ->willReturnCallback(
  577. function ($appName, $key, $default) {
  578. if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
  579. return 'yes';
  580. } elseif ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') {
  581. return 'yes';
  582. }
  583. return $default;
  584. }
  585. );
  586. $this->instantiatePlugin();
  587. /** @var \OCP\IUser | \PHPUnit\Framework\MockObject\MockObject */
  588. $currentUser = $this->createMock('\OCP\IUser');
  589. $currentUser->expects($this->any())
  590. ->method('getUID')
  591. ->willReturn('currentUser');
  592. $this->mailer->method('validateMailAddress')
  593. ->willReturn($validEmail);
  594. $this->contactsManager->expects($this->any())
  595. ->method('search')
  596. ->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) {
  597. if ($search === $searchTerm) {
  598. return $contacts;
  599. }
  600. return [];
  601. });
  602. $this->userSession->expects($this->any())
  603. ->method('getUser')
  604. ->willReturn($currentUser);
  605. $this->groupManager->expects($this->any())
  606. ->method('getUserGroupIds')
  607. ->willReturnCallback(function (\OCP\IUser $user) use ($userToGroupMapping) {
  608. return $userToGroupMapping[$user->getUID()];
  609. });
  610. $this->groupManager->expects($this->any())
  611. ->method('isInGroup')
  612. ->willReturnCallback(function ($userId, $group) use ($userToGroupMapping) {
  613. return in_array($group, $userToGroupMapping[$userId]);
  614. });
  615. $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult);
  616. $result = $this->searchResult->asArray();
  617. $this->assertSame($exactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails')));
  618. $this->assertEquals($expected, $result);
  619. $this->assertSame($reachedEnd, $moreResults);
  620. }
  621. public function dataGetEmailGroupsOnly() {
  622. return [
  623. // The user `User` can share with the current user
  624. [
  625. 'test',
  626. [
  627. [
  628. 'FN' => 'User',
  629. 'EMAIL' => ['test@example.com'],
  630. 'CLOUD' => ['test@localhost'],
  631. 'isLocalSystemBook' => true,
  632. 'UID' => 'User'
  633. ]
  634. ],
  635. ['users' => [['label' => 'User (test@example.com)', 'uuid' => 'User', 'name' => 'User', 'value' => ['shareType' => 0, 'shareWith' => 'test'],'shareWithDisplayNameUnique' => 'test@example.com',]], 'emails' => [], 'exact' => ['emails' => [], 'users' => []]],
  636. false,
  637. false,
  638. [
  639. "currentUser" => ["group1"],
  640. "User" => ["group1"]
  641. ],
  642. false,
  643. ],
  644. // The user `User` cannot share with the current user
  645. [
  646. 'test',
  647. [
  648. [
  649. 'FN' => 'User',
  650. 'EMAIL' => ['test@example.com'],
  651. 'CLOUD' => ['test@localhost'],
  652. 'isLocalSystemBook' => true,
  653. 'UID' => 'User'
  654. ]
  655. ],
  656. ['emails' => [], 'exact' => ['emails' => []]],
  657. false,
  658. false,
  659. [
  660. "currentUser" => ["group1"],
  661. "User" => ["group2"]
  662. ],
  663. false,
  664. ],
  665. // The user `User` cannot share with the current user, but there is an exact match on the e-mail address -> share by e-mail
  666. [
  667. 'test@example.com',
  668. [
  669. [
  670. 'FN' => 'User',
  671. 'EMAIL' => ['test@example.com'],
  672. 'CLOUD' => ['test@localhost'],
  673. 'isLocalSystemBook' => true,
  674. 'UID' => 'User'
  675. ]
  676. ],
  677. ['emails' => [], 'exact' => ['emails' => [['label' => 'test@example.com', 'uuid' => 'test@example.com', 'value' => ['shareType' => 4,'shareWith' => 'test@example.com']]]]],
  678. false,
  679. false,
  680. [
  681. "currentUser" => ["group1"],
  682. "User" => ["group2"]
  683. ],
  684. true,
  685. ]
  686. ];
  687. }
  688. }