ShareesAPIControllerTest.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Files_Sharing\Tests\Controller;
  26. use OCA\Files_Sharing\Controller\ShareesAPIController;
  27. use OCA\Files_Sharing\Tests\TestCase;
  28. use OCP\AppFramework\Http;
  29. use OCP\AppFramework\OCS\OCSBadRequestException;
  30. use OCP\Share;
  31. /**
  32. * Class ShareesTest
  33. *
  34. * @group DB
  35. *
  36. * @package OCA\Files_Sharing\Tests\API
  37. */
  38. class ShareesAPIControllerTest extends TestCase {
  39. /** @var ShareesAPIController */
  40. protected $sharees;
  41. /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */
  42. protected $userManager;
  43. /** @var \OCP\IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
  44. protected $groupManager;
  45. /** @var \OCP\Contacts\IManager|\PHPUnit_Framework_MockObject_MockObject */
  46. protected $contactsManager;
  47. /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
  48. protected $session;
  49. /** @var \OCP\IRequest|\PHPUnit_Framework_MockObject_MockObject */
  50. protected $request;
  51. /** @var \OCP\Share\IManager|\PHPUnit_Framework_MockObject_MockObject */
  52. protected $shareManager;
  53. protected function setUp() {
  54. parent::setUp();
  55. $this->userManager = $this->getMockBuilder('OCP\IUserManager')
  56. ->disableOriginalConstructor()
  57. ->getMock();
  58. $this->groupManager = $this->getMockBuilder('OCP\IGroupManager')
  59. ->disableOriginalConstructor()
  60. ->getMock();
  61. $this->contactsManager = $this->getMockBuilder('OCP\Contacts\IManager')
  62. ->disableOriginalConstructor()
  63. ->getMock();
  64. $this->session = $this->getMockBuilder('OCP\IUserSession')
  65. ->disableOriginalConstructor()
  66. ->getMock();
  67. $this->request = $this->getMockBuilder('OCP\IRequest')
  68. ->disableOriginalConstructor()
  69. ->getMock();
  70. $this->shareManager = $this->getMockBuilder('OCP\Share\IManager')
  71. ->disableOriginalConstructor()
  72. ->getMock();
  73. $this->sharees = new ShareesAPIController(
  74. 'files_sharing',
  75. $this->request,
  76. $this->groupManager,
  77. $this->userManager,
  78. $this->contactsManager,
  79. $this->getMockBuilder('OCP\IConfig')->disableOriginalConstructor()->getMock(),
  80. $this->session,
  81. $this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
  82. $this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(),
  83. $this->shareManager
  84. );
  85. }
  86. /**
  87. * @param string $uid
  88. * @param string $displayName
  89. * @return \OCP\IUser|\PHPUnit_Framework_MockObject_MockObject
  90. */
  91. protected function getUserMock($uid, $displayName) {
  92. $user = $this->getMockBuilder('OCP\IUser')
  93. ->disableOriginalConstructor()
  94. ->getMock();
  95. $user->expects($this->any())
  96. ->method('getUID')
  97. ->willReturn($uid);
  98. $user->expects($this->any())
  99. ->method('getDisplayName')
  100. ->willReturn($displayName);
  101. return $user;
  102. }
  103. /**
  104. * @param string $gid
  105. * @return \OCP\IGroup|\PHPUnit_Framework_MockObject_MockObject
  106. */
  107. protected function getGroupMock($gid) {
  108. $group = $this->getMockBuilder('OCP\IGroup')
  109. ->disableOriginalConstructor()
  110. ->getMock();
  111. $group->expects($this->any())
  112. ->method('getGID')
  113. ->willReturn($gid);
  114. return $group;
  115. }
  116. public function dataGetUsers() {
  117. return [
  118. ['test', false, true, [], [], [], [], true, false],
  119. ['test', false, false, [], [], [], [], true, false],
  120. ['test', true, true, [], [], [], [], true, false],
  121. ['test', true, false, [], [], [], [], true, false],
  122. [
  123. 'test', false, true, [], [],
  124. [
  125. ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
  126. ], [], true, $this->getUserMock('test', 'Test')
  127. ],
  128. [
  129. 'test', false, false, [], [],
  130. [
  131. ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
  132. ], [], true, $this->getUserMock('test', 'Test')
  133. ],
  134. [
  135. 'test', true, true, [], [],
  136. [], [], true, $this->getUserMock('test', 'Test')
  137. ],
  138. [
  139. 'test', true, false, [], [],
  140. [], [], true, $this->getUserMock('test', 'Test')
  141. ],
  142. [
  143. 'test', true, true, ['test-group'], [['test-group', 'test', 2, 0, []]],
  144. [
  145. ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
  146. ], [], true, $this->getUserMock('test', 'Test')
  147. ],
  148. [
  149. 'test', true, false, ['test-group'], [['test-group', 'test', 2, 0, []]],
  150. [
  151. ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
  152. ], [], true, $this->getUserMock('test', 'Test')
  153. ],
  154. [
  155. 'test',
  156. false,
  157. true,
  158. [],
  159. [
  160. $this->getUserMock('test1', 'Test One'),
  161. ],
  162. [],
  163. [
  164. ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  165. ],
  166. true,
  167. false,
  168. ],
  169. [
  170. 'test',
  171. false,
  172. false,
  173. [],
  174. [
  175. $this->getUserMock('test1', 'Test One'),
  176. ],
  177. [],
  178. [],
  179. true,
  180. false,
  181. ],
  182. [
  183. 'test',
  184. false,
  185. true,
  186. [],
  187. [
  188. $this->getUserMock('test1', 'Test One'),
  189. $this->getUserMock('test2', 'Test Two'),
  190. ],
  191. [],
  192. [
  193. ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  194. ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']],
  195. ],
  196. false,
  197. false,
  198. ],
  199. [
  200. 'test',
  201. false,
  202. false,
  203. [],
  204. [
  205. $this->getUserMock('test1', 'Test One'),
  206. $this->getUserMock('test2', 'Test Two'),
  207. ],
  208. [],
  209. [],
  210. true,
  211. false,
  212. ],
  213. [
  214. 'test',
  215. false,
  216. true,
  217. [],
  218. [
  219. $this->getUserMock('test0', 'Test'),
  220. $this->getUserMock('test1', 'Test One'),
  221. $this->getUserMock('test2', 'Test Two'),
  222. ],
  223. [
  224. ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test0']],
  225. ],
  226. [
  227. ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  228. ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']],
  229. ],
  230. false,
  231. false,
  232. ],
  233. [
  234. 'test',
  235. false,
  236. false,
  237. [],
  238. [
  239. $this->getUserMock('test0', 'Test'),
  240. $this->getUserMock('test1', 'Test One'),
  241. $this->getUserMock('test2', 'Test Two'),
  242. ],
  243. [
  244. ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test0']],
  245. ],
  246. [],
  247. true,
  248. false,
  249. ],
  250. [
  251. 'test',
  252. true,
  253. true,
  254. ['abc', 'xyz'],
  255. [
  256. ['abc', 'test', 2, 0, ['test1' => 'Test One']],
  257. ['xyz', 'test', 2, 0, []],
  258. ],
  259. [],
  260. [
  261. ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  262. ],
  263. true,
  264. false,
  265. ],
  266. [
  267. 'test',
  268. true,
  269. false,
  270. ['abc', 'xyz'],
  271. [
  272. ['abc', 'test', 2, 0, ['test1' => 'Test One']],
  273. ['xyz', 'test', 2, 0, []],
  274. ],
  275. [],
  276. [],
  277. true,
  278. false,
  279. ],
  280. [
  281. 'test',
  282. true,
  283. true,
  284. ['abc', 'xyz'],
  285. [
  286. ['abc', 'test', 2, 0, [
  287. 'test1' => 'Test One',
  288. 'test2' => 'Test Two',
  289. ]],
  290. ['xyz', 'test', 2, 0, [
  291. 'test1' => 'Test One',
  292. 'test2' => 'Test Two',
  293. ]],
  294. ],
  295. [],
  296. [
  297. ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  298. ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']],
  299. ],
  300. false,
  301. false,
  302. ],
  303. [
  304. 'test',
  305. true,
  306. false,
  307. ['abc', 'xyz'],
  308. [
  309. ['abc', 'test', 2, 0, [
  310. 'test1' => 'Test One',
  311. 'test2' => 'Test Two',
  312. ]],
  313. ['xyz', 'test', 2, 0, [
  314. 'test1' => 'Test One',
  315. 'test2' => 'Test Two',
  316. ]],
  317. ],
  318. [],
  319. [],
  320. true,
  321. false,
  322. ],
  323. [
  324. 'test',
  325. true,
  326. true,
  327. ['abc', 'xyz'],
  328. [
  329. ['abc', 'test', 2, 0, [
  330. 'test' => 'Test One',
  331. ]],
  332. ['xyz', 'test', 2, 0, [
  333. 'test2' => 'Test Two',
  334. ]],
  335. ],
  336. [
  337. ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
  338. ],
  339. [
  340. ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']],
  341. ],
  342. false,
  343. false,
  344. ],
  345. [
  346. 'test',
  347. true,
  348. false,
  349. ['abc', 'xyz'],
  350. [
  351. ['abc', 'test', 2, 0, [
  352. 'test' => 'Test One',
  353. ]],
  354. ['xyz', 'test', 2, 0, [
  355. 'test2' => 'Test Two',
  356. ]],
  357. ],
  358. [
  359. ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
  360. ],
  361. [],
  362. true,
  363. false,
  364. ],
  365. ];
  366. }
  367. /**
  368. * @dataProvider dataGetUsers
  369. *
  370. * @param string $searchTerm
  371. * @param bool $shareWithGroupOnly
  372. * @param bool $shareeEnumeration
  373. * @param array $groupResponse
  374. * @param array $userResponse
  375. * @param array $exactExpected
  376. * @param array $expected
  377. * @param bool $reachedEnd
  378. * @param mixed $singleUser
  379. */
  380. public function testGetUsers($searchTerm, $shareWithGroupOnly, $shareeEnumeration, $groupResponse, $userResponse, $exactExpected, $expected, $reachedEnd, $singleUser) {
  381. $this->invokePrivate($this->sharees, 'limit', [2]);
  382. $this->invokePrivate($this->sharees, 'offset', [0]);
  383. $this->invokePrivate($this->sharees, 'shareWithGroupOnly', [$shareWithGroupOnly]);
  384. $this->invokePrivate($this->sharees, 'shareeEnumeration', [$shareeEnumeration]);
  385. $user = $this->getUserMock('admin', 'Administrator');
  386. $this->session->expects($this->any())
  387. ->method('getUser')
  388. ->willReturn($user);
  389. if (!$shareWithGroupOnly) {
  390. $this->userManager->expects($this->once())
  391. ->method('searchDisplayName')
  392. ->with($searchTerm, $this->invokePrivate($this->sharees, 'limit'), $this->invokePrivate($this->sharees, 'offset'))
  393. ->willReturn($userResponse);
  394. } else {
  395. if ($singleUser !== false) {
  396. $this->groupManager->expects($this->exactly(2))
  397. ->method('getUserGroupIds')
  398. ->withConsecutive(
  399. $user,
  400. $singleUser
  401. )
  402. ->willReturn($groupResponse);
  403. } else {
  404. $this->groupManager->expects($this->once())
  405. ->method('getUserGroupIds')
  406. ->with($user)
  407. ->willReturn($groupResponse);
  408. }
  409. $this->groupManager->expects($this->exactly(sizeof($groupResponse)))
  410. ->method('displayNamesInGroup')
  411. ->with($this->anything(), $searchTerm, $this->invokePrivate($this->sharees, 'limit'), $this->invokePrivate($this->sharees, 'offset'))
  412. ->willReturnMap($userResponse);
  413. }
  414. if ($singleUser !== false) {
  415. $this->userManager->expects($this->once())
  416. ->method('get')
  417. ->with($searchTerm)
  418. ->willReturn($singleUser);
  419. }
  420. $this->invokePrivate($this->sharees, 'getUsers', [$searchTerm]);
  421. $result = $this->invokePrivate($this->sharees, 'result');
  422. $this->assertEquals($exactExpected, $result['exact']['users']);
  423. $this->assertEquals($expected, $result['users']);
  424. $this->assertCount((int) $reachedEnd, $this->invokePrivate($this->sharees, 'reachedEndFor'));
  425. }
  426. public function dataGetGroups() {
  427. return [
  428. ['test', false, true, [], [], [], [], true, false],
  429. ['test', false, false, [], [], [], [], true, false],
  430. [
  431. 'test', false, true,
  432. [$this->getGroupMock('test1')],
  433. [],
  434. [],
  435. [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]],
  436. true,
  437. false,
  438. ],
  439. [
  440. 'test', false, false,
  441. [$this->getGroupMock('test1')],
  442. [],
  443. [],
  444. [],
  445. true,
  446. false,
  447. ],
  448. [
  449. 'test', false, true,
  450. [
  451. $this->getGroupMock('test'),
  452. $this->getGroupMock('test1'),
  453. ],
  454. [],
  455. [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]],
  456. [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]],
  457. false,
  458. false,
  459. ],
  460. [
  461. 'test', false, false,
  462. [
  463. $this->getGroupMock('test'),
  464. $this->getGroupMock('test1'),
  465. ],
  466. [],
  467. [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]],
  468. [],
  469. true,
  470. false,
  471. ],
  472. [
  473. 'test', false, true,
  474. [
  475. $this->getGroupMock('test0'),
  476. $this->getGroupMock('test1'),
  477. ],
  478. [],
  479. [],
  480. [
  481. ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']],
  482. ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']],
  483. ],
  484. false,
  485. null,
  486. ],
  487. [
  488. 'test', false, false,
  489. [
  490. $this->getGroupMock('test0'),
  491. $this->getGroupMock('test1'),
  492. ],
  493. [],
  494. [],
  495. [],
  496. true,
  497. null,
  498. ],
  499. [
  500. 'test', false, true,
  501. [
  502. $this->getGroupMock('test0'),
  503. $this->getGroupMock('test1'),
  504. ],
  505. [],
  506. [
  507. ['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']],
  508. ],
  509. [
  510. ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']],
  511. ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']],
  512. ],
  513. false,
  514. $this->getGroupMock('test'),
  515. ],
  516. [
  517. 'test', false, false,
  518. [
  519. $this->getGroupMock('test0'),
  520. $this->getGroupMock('test1'),
  521. ],
  522. [],
  523. [
  524. ['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']],
  525. ],
  526. [],
  527. true,
  528. $this->getGroupMock('test'),
  529. ],
  530. ['test', true, true, [], [], [], [], true, false],
  531. ['test', true, false, [], [], [], [], true, false],
  532. [
  533. 'test', true, true,
  534. [
  535. $this->getGroupMock('test1'),
  536. $this->getGroupMock('test2'),
  537. ],
  538. [$this->getGroupMock('test1')],
  539. [],
  540. [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]],
  541. false,
  542. false,
  543. ],
  544. [
  545. 'test', true, false,
  546. [
  547. $this->getGroupMock('test1'),
  548. $this->getGroupMock('test2'),
  549. ],
  550. [$this->getGroupMock('test1')],
  551. [],
  552. [],
  553. true,
  554. false,
  555. ],
  556. [
  557. 'test', true, true,
  558. [
  559. $this->getGroupMock('test'),
  560. $this->getGroupMock('test1'),
  561. ],
  562. [$this->getGroupMock('test')],
  563. [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]],
  564. [],
  565. false,
  566. false,
  567. ],
  568. [
  569. 'test', true, false,
  570. [
  571. $this->getGroupMock('test'),
  572. $this->getGroupMock('test1'),
  573. ],
  574. [$this->getGroupMock('test')],
  575. [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]],
  576. [],
  577. true,
  578. false,
  579. ],
  580. [
  581. 'test', true, true,
  582. [
  583. $this->getGroupMock('test'),
  584. $this->getGroupMock('test1'),
  585. ],
  586. [$this->getGroupMock('test1')],
  587. [],
  588. [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]],
  589. false,
  590. false,
  591. ],
  592. [
  593. 'test', true, false,
  594. [
  595. $this->getGroupMock('test'),
  596. $this->getGroupMock('test1'),
  597. ],
  598. [$this->getGroupMock('test1')],
  599. [],
  600. [],
  601. true,
  602. false,
  603. ],
  604. [
  605. 'test', true, true,
  606. [
  607. $this->getGroupMock('test'),
  608. $this->getGroupMock('test1'),
  609. ],
  610. [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
  611. [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]],
  612. [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]],
  613. false,
  614. false,
  615. ],
  616. [
  617. 'test', true, false,
  618. [
  619. $this->getGroupMock('test'),
  620. $this->getGroupMock('test1'),
  621. ],
  622. [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
  623. [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]],
  624. [],
  625. true,
  626. false,
  627. ],
  628. [
  629. 'test', true, true,
  630. [
  631. $this->getGroupMock('test0'),
  632. $this->getGroupMock('test1'),
  633. ],
  634. [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
  635. [],
  636. [
  637. ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']],
  638. ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']],
  639. ],
  640. false,
  641. null,
  642. ],
  643. [
  644. 'test', true, false,
  645. [
  646. $this->getGroupMock('test0'),
  647. $this->getGroupMock('test1'),
  648. ],
  649. [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
  650. [],
  651. [],
  652. true,
  653. null,
  654. ],
  655. [
  656. 'test', true, true,
  657. [
  658. $this->getGroupMock('test0'),
  659. $this->getGroupMock('test1'),
  660. ],
  661. [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
  662. [
  663. ['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']],
  664. ],
  665. [
  666. ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']],
  667. ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']],
  668. ],
  669. false,
  670. $this->getGroupMock('test'),
  671. ],
  672. [
  673. 'test', true, false,
  674. [
  675. $this->getGroupMock('test0'),
  676. $this->getGroupMock('test1'),
  677. ],
  678. [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
  679. [
  680. ['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']],
  681. ],
  682. [],
  683. true,
  684. $this->getGroupMock('test'),
  685. ],
  686. ];
  687. }
  688. /**
  689. * @dataProvider dataGetGroups
  690. *
  691. * @param string $searchTerm
  692. * @param bool $shareWithGroupOnly
  693. * @param bool $shareeEnumeration
  694. * @param array $groupResponse
  695. * @param array $userGroupsResponse
  696. * @param array $exactExpected
  697. * @param array $expected
  698. * @param bool $reachedEnd
  699. * @param mixed $singleGroup
  700. */
  701. public function testGetGroups($searchTerm, $shareWithGroupOnly, $shareeEnumeration, $groupResponse, $userGroupsResponse, $exactExpected, $expected, $reachedEnd, $singleGroup) {
  702. $this->invokePrivate($this->sharees, 'limit', [2]);
  703. $this->invokePrivate($this->sharees, 'offset', [0]);
  704. $this->invokePrivate($this->sharees, 'shareWithGroupOnly', [$shareWithGroupOnly]);
  705. $this->invokePrivate($this->sharees, 'shareeEnumeration', [$shareeEnumeration]);
  706. $this->groupManager->expects($this->once())
  707. ->method('search')
  708. ->with($searchTerm, $this->invokePrivate($this->sharees, 'limit'), $this->invokePrivate($this->sharees, 'offset'))
  709. ->willReturn($groupResponse);
  710. if ($singleGroup !== false) {
  711. $this->groupManager->expects($this->once())
  712. ->method('get')
  713. ->with($searchTerm)
  714. ->willReturn($singleGroup);
  715. }
  716. if ($shareWithGroupOnly) {
  717. $user = $this->getUserMock('admin', 'Administrator');
  718. $this->session->expects($this->any())
  719. ->method('getUser')
  720. ->willReturn($user);
  721. $numGetUserGroupsCalls = empty($groupResponse) ? 0 : 1;
  722. $this->groupManager->expects($this->exactly($numGetUserGroupsCalls))
  723. ->method('getUserGroups')
  724. ->with($user)
  725. ->willReturn($userGroupsResponse);
  726. }
  727. $this->invokePrivate($this->sharees, 'getGroups', [$searchTerm]);
  728. $result = $this->invokePrivate($this->sharees, 'result');
  729. $this->assertEquals($exactExpected, $result['exact']['groups']);
  730. $this->assertEquals($expected, $result['groups']);
  731. $this->assertCount((int) $reachedEnd, $this->invokePrivate($this->sharees, 'reachedEndFor'));
  732. }
  733. /**
  734. * @dataProvider dataGetRemote
  735. *
  736. * @param string $searchTerm
  737. * @param array $contacts
  738. * @param bool $shareeEnumeration
  739. * @param array $expected
  740. * @param bool $reachedEnd
  741. */
  742. public function testGetRemote($searchTerm, $contacts, $shareeEnumeration, $expected, $reachedEnd) {
  743. $this->invokePrivate($this->sharees, 'shareeEnumeration', [$shareeEnumeration]);
  744. $this->contactsManager->expects($this->any())
  745. ->method('search')
  746. ->with($searchTerm, ['CLOUD', 'FN'])
  747. ->willReturn($contacts);
  748. $result = $this->invokePrivate($this->sharees, 'getRemote', [$searchTerm]);
  749. $this->assertEquals($expected, $result);
  750. $this->assertCount((int) $reachedEnd, $this->invokePrivate($this->sharees, 'reachedEndFor'));
  751. }
  752. public function dataGetRemote() {
  753. return [
  754. ['test', [], true, ['results' => [], 'exact' => [], 'exactIdMatch' => false], true],
  755. ['test', [], false, ['results' => [], 'exact' => [], 'exactIdMatch' => false], true],
  756. [
  757. 'test@remote',
  758. [],
  759. true,
  760. ['results' => [], 'exact' => [['label' => 'test@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']]], 'exactIdMatch' => false],
  761. true,
  762. ],
  763. [
  764. 'test@remote',
  765. [],
  766. false,
  767. ['results' => [], 'exact' => [['label' => 'test@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']]], 'exactIdMatch' => false],
  768. true,
  769. ],
  770. [
  771. 'test',
  772. [
  773. [
  774. 'FN' => 'User3 @ Localhost',
  775. ],
  776. [
  777. 'FN' => 'User2 @ Localhost',
  778. 'CLOUD' => [
  779. ],
  780. ],
  781. [
  782. 'FN' => 'User @ Localhost',
  783. 'CLOUD' => [
  784. 'username@localhost',
  785. ],
  786. ],
  787. ],
  788. true,
  789. ['results' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exact' => [], 'exactIdMatch' => false],
  790. true,
  791. ],
  792. [
  793. 'test',
  794. [
  795. [
  796. 'FN' => 'User3 @ Localhost',
  797. ],
  798. [
  799. 'FN' => 'User2 @ Localhost',
  800. 'CLOUD' => [
  801. ],
  802. ],
  803. [
  804. 'FN' => 'User @ Localhost',
  805. 'CLOUD' => [
  806. 'username@localhost',
  807. ],
  808. ],
  809. ],
  810. false,
  811. ['results' => [], 'exact' => [], 'exactIdMatch' => false],
  812. true,
  813. ],
  814. [
  815. 'test@remote',
  816. [
  817. [
  818. 'FN' => 'User3 @ Localhost',
  819. ],
  820. [
  821. 'FN' => 'User2 @ Localhost',
  822. 'CLOUD' => [
  823. ],
  824. ],
  825. [
  826. 'FN' => 'User @ Localhost',
  827. 'CLOUD' => [
  828. 'username@localhost',
  829. ],
  830. ],
  831. ],
  832. true,
  833. ['results' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exact' => [['label' => 'test@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']]], 'exactIdMatch' => false],
  834. true,
  835. ],
  836. [
  837. 'test@remote',
  838. [
  839. [
  840. 'FN' => 'User3 @ Localhost',
  841. ],
  842. [
  843. 'FN' => 'User2 @ Localhost',
  844. 'CLOUD' => [
  845. ],
  846. ],
  847. [
  848. 'FN' => 'User @ Localhost',
  849. 'CLOUD' => [
  850. 'username@localhost',
  851. ],
  852. ],
  853. ],
  854. false,
  855. ['results' => [], 'exact' => [['label' => 'test@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']]], 'exactIdMatch' => false],
  856. true,
  857. ],
  858. [
  859. 'username@localhost',
  860. [
  861. [
  862. 'FN' => 'User3 @ Localhost',
  863. ],
  864. [
  865. 'FN' => 'User2 @ Localhost',
  866. 'CLOUD' => [
  867. ],
  868. ],
  869. [
  870. 'FN' => 'User @ Localhost',
  871. 'CLOUD' => [
  872. 'username@localhost',
  873. ],
  874. ],
  875. ],
  876. true,
  877. ['results' => [], 'exact' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exactIdMatch' => true],
  878. true,
  879. ],
  880. [
  881. 'username@localhost',
  882. [
  883. [
  884. 'FN' => 'User3 @ Localhost',
  885. ],
  886. [
  887. 'FN' => 'User2 @ Localhost',
  888. 'CLOUD' => [
  889. ],
  890. ],
  891. [
  892. 'FN' => 'User @ Localhost',
  893. 'CLOUD' => [
  894. 'username@localhost',
  895. ],
  896. ],
  897. ],
  898. false,
  899. ['results' => [], 'exact' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exactIdMatch' => true],
  900. true,
  901. ],
  902. // contact with space
  903. [
  904. 'user name@localhost',
  905. [
  906. [
  907. 'FN' => 'User3 @ Localhost',
  908. ],
  909. [
  910. 'FN' => 'User2 @ Localhost',
  911. 'CLOUD' => [
  912. ],
  913. ],
  914. [
  915. 'FN' => 'User Name @ Localhost',
  916. 'CLOUD' => [
  917. 'user name@localhost',
  918. ],
  919. ],
  920. ],
  921. false,
  922. ['results' => [], 'exact' => [['label' => 'User Name @ Localhost (user name@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'user name@localhost', 'server' => 'localhost']]], 'exactIdMatch' => true],
  923. true,
  924. ],
  925. // remote with space, no contact
  926. [
  927. 'user space@remote',
  928. [
  929. [
  930. 'FN' => 'User3 @ Localhost',
  931. ],
  932. [
  933. 'FN' => 'User2 @ Localhost',
  934. 'CLOUD' => [
  935. ],
  936. ],
  937. [
  938. 'FN' => 'User @ Localhost',
  939. 'CLOUD' => [
  940. 'username@localhost',
  941. ],
  942. ],
  943. ],
  944. false,
  945. ['results' => [], 'exact' => [['label' => 'user space@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'user space@remote']]], 'exactIdMatch' => false],
  946. true,
  947. ],
  948. ];
  949. }
  950. /**
  951. * @dataProvider dataGetEmail
  952. *
  953. * @param string $searchTerm
  954. * @param array $contacts
  955. * @param bool $shareeEnumeration
  956. * @param array $expected
  957. * @param bool $reachedEnd
  958. */
  959. public function testGetEmail($searchTerm, $contacts, $shareeEnumeration, $expected, $reachedEnd) {
  960. $this->invokePrivate($this->sharees, 'shareeEnumeration', [$shareeEnumeration]);
  961. $this->contactsManager->expects($this->any())
  962. ->method('search')
  963. ->with($searchTerm, ['EMAIL', 'FN'])
  964. ->willReturn($contacts);
  965. $result = $this->invokePrivate($this->sharees, 'getEmail', [$searchTerm]);
  966. $this->assertEquals($expected, $result);
  967. $this->assertCount((int) $reachedEnd, $this->invokePrivate($this->sharees, 'reachedEndFor'));
  968. }
  969. public function dataGetEmail() {
  970. return [
  971. ['test', [], true, ['results' => [], 'exact' => [], 'exactIdMatch' => false], true],
  972. ['test', [], false, ['results' => [], 'exact' => [], 'exactIdMatch' => false], true],
  973. [
  974. 'test@remote.com',
  975. [],
  976. true,
  977. ['results' => [], 'exact' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]], 'exactIdMatch' => false],
  978. true,
  979. ],
  980. [ // no valid email address
  981. 'test@remote',
  982. [],
  983. true,
  984. ['results' => [], 'exact' => [], 'exactIdMatch' => false],
  985. true,
  986. ],
  987. [
  988. 'test@remote.com',
  989. [],
  990. false,
  991. ['results' => [], 'exact' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]], 'exactIdMatch' => false],
  992. true,
  993. ],
  994. [
  995. 'test',
  996. [
  997. [
  998. 'FN' => 'User3 @ Localhost',
  999. ],
  1000. [
  1001. 'FN' => 'User2 @ Localhost',
  1002. 'EMAIL' => [
  1003. ],
  1004. ],
  1005. [
  1006. 'FN' => 'User @ Localhost',
  1007. 'EMAIL' => [
  1008. 'username@localhost',
  1009. ],
  1010. ],
  1011. ],
  1012. true,
  1013. ['results' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => [], 'exactIdMatch' => false],
  1014. true,
  1015. ],
  1016. [
  1017. 'test',
  1018. [
  1019. [
  1020. 'FN' => 'User3 @ Localhost',
  1021. ],
  1022. [
  1023. 'FN' => 'User2 @ Localhost',
  1024. 'EMAIL' => [
  1025. ],
  1026. ],
  1027. [
  1028. 'FN' => 'User @ Localhost',
  1029. 'EMAIL' => [
  1030. 'username@localhost',
  1031. ],
  1032. ],
  1033. ],
  1034. false,
  1035. ['results' => [], 'exact' => [], 'exactIdMatch' => false],
  1036. true,
  1037. ],
  1038. [
  1039. 'test@remote.com',
  1040. [
  1041. [
  1042. 'FN' => 'User3 @ Localhost',
  1043. ],
  1044. [
  1045. 'FN' => 'User2 @ Localhost',
  1046. 'EMAIL' => [
  1047. ],
  1048. ],
  1049. [
  1050. 'FN' => 'User @ Localhost',
  1051. 'EMAIL' => [
  1052. 'username@localhost',
  1053. ],
  1054. ],
  1055. ],
  1056. true,
  1057. ['results' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]], 'exactIdMatch' => false],
  1058. true,
  1059. ],
  1060. [
  1061. 'test@remote.com',
  1062. [
  1063. [
  1064. 'FN' => 'User3 @ Localhost',
  1065. ],
  1066. [
  1067. 'FN' => 'User2 @ Localhost',
  1068. 'EMAIL' => [
  1069. ],
  1070. ],
  1071. [
  1072. 'FN' => 'User @ Localhost',
  1073. 'EMAIL' => [
  1074. 'username@localhost',
  1075. ],
  1076. ],
  1077. ],
  1078. false,
  1079. ['results' => [], 'exact' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]], 'exactIdMatch' => false],
  1080. true,
  1081. ],
  1082. [
  1083. 'username@localhost',
  1084. [
  1085. [
  1086. 'FN' => 'User3 @ Localhost',
  1087. ],
  1088. [
  1089. 'FN' => 'User2 @ Localhost',
  1090. 'EMAIL' => [
  1091. ],
  1092. ],
  1093. [
  1094. 'FN' => 'User @ Localhost',
  1095. 'EMAIL' => [
  1096. 'username@localhost',
  1097. ],
  1098. ],
  1099. ],
  1100. true,
  1101. ['results' => [], 'exact' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exactIdMatch' => true],
  1102. true,
  1103. ],
  1104. [
  1105. 'username@localhost',
  1106. [
  1107. [
  1108. 'FN' => 'User3 @ Localhost',
  1109. ],
  1110. [
  1111. 'FN' => 'User2 @ Localhost',
  1112. 'EMAIL' => [
  1113. ],
  1114. ],
  1115. [
  1116. 'FN' => 'User @ Localhost',
  1117. 'EMAIL' => [
  1118. 'username@localhost',
  1119. ],
  1120. ],
  1121. ],
  1122. false,
  1123. ['results' => [], 'exact' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exactIdMatch' => true],
  1124. true,
  1125. ],
  1126. // contact with space
  1127. [
  1128. 'user name@localhost',
  1129. [
  1130. [
  1131. 'FN' => 'User3 @ Localhost',
  1132. ],
  1133. [
  1134. 'FN' => 'User2 @ Localhost',
  1135. 'EMAIL' => [
  1136. ],
  1137. ],
  1138. [
  1139. 'FN' => 'User Name @ Localhost',
  1140. 'EMAIL' => [
  1141. 'user name@localhost',
  1142. ],
  1143. ],
  1144. ],
  1145. false,
  1146. ['results' => [], 'exact' => [['label' => 'User Name @ Localhost (user name@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'user name@localhost']]], 'exactIdMatch' => true],
  1147. true,
  1148. ],
  1149. // remote with space, no contact
  1150. [
  1151. 'user space@remote.com',
  1152. [
  1153. [
  1154. 'FN' => 'User3 @ Localhost',
  1155. ],
  1156. [
  1157. 'FN' => 'User2 @ Localhost',
  1158. 'EMAIL' => [
  1159. ],
  1160. ],
  1161. [
  1162. 'FN' => 'User @ Localhost',
  1163. 'EMAIL' => [
  1164. 'username@localhost',
  1165. ],
  1166. ],
  1167. ],
  1168. false,
  1169. ['results' => [], 'exact' => [], 'exactIdMatch' => false],
  1170. true,
  1171. ],
  1172. ];
  1173. }
  1174. public function dataSearch() {
  1175. $noRemote = [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_EMAIL];
  1176. $allTypes = [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE, Share::SHARE_TYPE_EMAIL];
  1177. return [
  1178. [[], '', 'yes', true, true, $noRemote, false, true, true],
  1179. // Test itemType
  1180. [[
  1181. 'search' => '',
  1182. ], '', 'yes', true, true, $noRemote, false, true, true],
  1183. [[
  1184. 'search' => 'foobar',
  1185. ], '', 'yes', true, true, $noRemote, false, true, true],
  1186. [[
  1187. 'search' => 0,
  1188. ], '', 'yes', true, true, $noRemote, false, true, true],
  1189. // Test itemType
  1190. [[
  1191. 'itemType' => '',
  1192. ], '', 'yes', true, true, $noRemote, false, true, true],
  1193. [[
  1194. 'itemType' => 'folder',
  1195. ], '', 'yes', true, true, $allTypes, false, true, true],
  1196. [[
  1197. 'itemType' => 0,
  1198. ], '', 'yes', true, true, $noRemote, false, true, true],
  1199. // Test shareType
  1200. [[
  1201. 'itemType' => 'call',
  1202. ], '', 'yes', true, true, $noRemote, false, true, true],
  1203. [[
  1204. 'itemType' => 'folder',
  1205. ], '', 'yes', true, true, $allTypes, false, true, true],
  1206. [[
  1207. 'itemType' => 'folder',
  1208. 'shareType' => 0,
  1209. ], '', 'yes', true, false, [0], false, true, true],
  1210. [[
  1211. 'itemType' => 'folder',
  1212. 'shareType' => '0',
  1213. ], '', 'yes', true, false, [0], false, true, true],
  1214. [[
  1215. 'itemType' => 'folder',
  1216. 'shareType' => 1,
  1217. ], '', 'yes', true, false, [1], false, true, true],
  1218. [[
  1219. 'itemType' => 'folder',
  1220. 'shareType' => 12,
  1221. ], '', 'yes', true, false, [], false, true, true],
  1222. [[
  1223. 'itemType' => 'folder',
  1224. 'shareType' => 'foobar',
  1225. ], '', 'yes', true, true, $allTypes, false, true, true],
  1226. [[
  1227. 'itemType' => 'folder',
  1228. 'shareType' => [0, 1, 2],
  1229. ], '', 'yes', false, false, [0, 1], false, true, true],
  1230. [[
  1231. 'itemType' => 'folder',
  1232. 'shareType' => [0, 1],
  1233. ], '', 'yes', false, false, [0, 1], false, true, true],
  1234. [[
  1235. 'itemType' => 'folder',
  1236. 'shareType' => $allTypes,
  1237. ], '', 'yes', true, true, $allTypes, false, true, true],
  1238. [[
  1239. 'itemType' => 'folder',
  1240. 'shareType' => $allTypes,
  1241. ], '', 'yes', false, false, [0, 1], false, true, true],
  1242. [[
  1243. 'itemType' => 'folder',
  1244. 'shareType' => $allTypes,
  1245. ], '', 'yes', true, false, [0, 6], false, true, false],
  1246. [[
  1247. 'itemType' => 'folder',
  1248. 'shareType' => $allTypes,
  1249. ], '', 'yes', false, true, [0, 4], false, true, false],
  1250. // Test pagination
  1251. [[
  1252. 'itemType' => 'folder',
  1253. 'page' => 1,
  1254. ], '', 'yes', true, true, $allTypes, false, true, true],
  1255. [[
  1256. 'itemType' => 'folder',
  1257. 'page' => 10,
  1258. ], '', 'yes', true, true, $allTypes, false, true, true],
  1259. // Test perPage
  1260. [[
  1261. 'itemType' => 'folder',
  1262. 'perPage' => 1,
  1263. ], '', 'yes', true, true, $allTypes, false, true, true],
  1264. [[
  1265. 'itemType' => 'folder',
  1266. 'perPage' => 10,
  1267. ], '', 'yes', true, true, $allTypes, false, true, true],
  1268. // Test $shareWithGroupOnly setting
  1269. [[
  1270. 'itemType' => 'folder',
  1271. ], 'no', 'yes', true, true, $allTypes, false, true, true],
  1272. [[
  1273. 'itemType' => 'folder',
  1274. ], 'yes', 'yes', true, true, $allTypes, true, true, true],
  1275. // Test $shareeEnumeration setting
  1276. [[
  1277. 'itemType' => 'folder',
  1278. ], 'no', 'yes', true, true, $allTypes, false, true, true],
  1279. [[
  1280. 'itemType' => 'folder',
  1281. ], 'no', 'no', true, true, $allTypes, false, false, true],
  1282. ];
  1283. }
  1284. /**
  1285. * @dataProvider dataSearch
  1286. *
  1287. * @param array $getData
  1288. * @param string $apiSetting
  1289. * @param string $enumSetting
  1290. * @param bool $remoteSharingEnabled
  1291. * @param bool $emailSharingEnabled
  1292. * @param array $shareTypes
  1293. * @param bool $shareWithGroupOnly
  1294. * @param bool $shareeEnumeration
  1295. * @param bool $allowGroupSharing
  1296. */
  1297. public function testSearch($getData, $apiSetting, $enumSetting, $remoteSharingEnabled, $emailSharingEnabled, $shareTypes, $shareWithGroupOnly, $shareeEnumeration, $allowGroupSharing) {
  1298. $search = isset($getData['search']) ? $getData['search'] : '';
  1299. $itemType = isset($getData['itemType']) ? $getData['itemType'] : null;
  1300. $page = isset($getData['page']) ? $getData['page'] : 1;
  1301. $perPage = isset($getData['perPage']) ? $getData['perPage'] : 200;
  1302. $shareType = isset($getData['shareType']) ? $getData['shareType'] : null;
  1303. $config = $this->getMockBuilder('OCP\IConfig')
  1304. ->disableOriginalConstructor()
  1305. ->getMock();
  1306. $config->expects($this->exactly(2))
  1307. ->method('getAppValue')
  1308. ->with('core', $this->anything(), $this->anything())
  1309. ->willReturnMap([
  1310. ['core', 'shareapi_only_share_with_group_members', 'no', $apiSetting],
  1311. ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', $enumSetting],
  1312. ]);
  1313. $this->shareManager->expects($itemType === 'file' || $itemType === 'folder' ? $this->once() : $this->never())
  1314. ->method('allowGroupSharing')
  1315. ->willReturn($allowGroupSharing);
  1316. /** @var \PHPUnit_Framework_MockObject_MockObject|\OCA\Files_Sharing\Controller\ShareesAPIController $sharees */
  1317. $sharees = $this->getMockBuilder('\OCA\Files_Sharing\Controller\ShareesAPIController')
  1318. ->setConstructorArgs([
  1319. 'files_sharing',
  1320. $this->getMockBuilder('OCP\IRequest')->disableOriginalConstructor()->getMock(),
  1321. $this->groupManager,
  1322. $this->userManager,
  1323. $this->contactsManager,
  1324. $config,
  1325. $this->session,
  1326. $this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
  1327. $this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(),
  1328. $this->shareManager
  1329. ])
  1330. ->setMethods(array('searchSharees', 'isRemoteSharingAllowed', 'shareProviderExists'))
  1331. ->getMock();
  1332. $sharees->expects($this->once())
  1333. ->method('searchSharees')
  1334. ->willReturnCallback(function
  1335. ($isearch, $iitemType, $ishareTypes, $ipage, $iperPage)
  1336. use ($search, $itemType, $shareTypes, $page, $perPage) {
  1337. // We are doing strict comparisons here, so we can differ 0/'' and null on shareType/itemType
  1338. $this->assertSame($search, $isearch);
  1339. $this->assertSame($itemType, $iitemType);
  1340. $this->assertSame(count($shareTypes), count($ishareTypes));
  1341. foreach($shareTypes as $expected) {
  1342. $this->assertTrue(in_array($expected, $ishareTypes));
  1343. }
  1344. $this->assertSame($page, $ipage);
  1345. $this->assertSame($perPage, $iperPage);
  1346. return new Http\DataResponse();
  1347. });
  1348. $sharees->expects($this->any())
  1349. ->method('isRemoteSharingAllowed')
  1350. ->with($itemType)
  1351. ->willReturn($remoteSharingEnabled);
  1352. $this->shareManager->expects($this->any())
  1353. ->method('shareProviderExists')
  1354. ->with(\OCP\Share::SHARE_TYPE_EMAIL)
  1355. ->willReturn($emailSharingEnabled);
  1356. $this->assertInstanceOf(Http\DataResponse::class, $sharees->search($search, $itemType, $page, $perPage, $shareType));
  1357. $this->assertSame($shareWithGroupOnly, $this->invokePrivate($sharees, 'shareWithGroupOnly'));
  1358. $this->assertSame($shareeEnumeration, $this->invokePrivate($sharees, 'shareeEnumeration'));
  1359. }
  1360. public function dataSearchInvalid() {
  1361. return [
  1362. // Test invalid pagination
  1363. [[
  1364. 'page' => 0,
  1365. ], 'Invalid page'],
  1366. [[
  1367. 'page' => '0',
  1368. ], 'Invalid page'],
  1369. [[
  1370. 'page' => -1,
  1371. ], 'Invalid page'],
  1372. // Test invalid perPage
  1373. [[
  1374. 'perPage' => 0,
  1375. ], 'Invalid perPage argument'],
  1376. [[
  1377. 'perPage' => '0',
  1378. ], 'Invalid perPage argument'],
  1379. [[
  1380. 'perPage' => -1,
  1381. ], 'Invalid perPage argument'],
  1382. ];
  1383. }
  1384. /**
  1385. * @dataProvider dataSearchInvalid
  1386. *
  1387. * @param array $getData
  1388. * @param string $message
  1389. */
  1390. public function testSearchInvalid($getData, $message) {
  1391. $page = isset($getData['page']) ? $getData['page'] : 1;
  1392. $perPage = isset($getData['perPage']) ? $getData['perPage'] : 200;
  1393. $config = $this->getMockBuilder('OCP\IConfig')
  1394. ->disableOriginalConstructor()
  1395. ->getMock();
  1396. $config->expects($this->never())
  1397. ->method('getAppValue');
  1398. /** @var \PHPUnit_Framework_MockObject_MockObject|\OCA\Files_Sharing\Controller\ShareesAPIController $sharees */
  1399. $sharees = $this->getMockBuilder('\OCA\Files_Sharing\Controller\ShareesAPIController')
  1400. ->setConstructorArgs([
  1401. 'files_sharing',
  1402. $this->getMockBuilder('OCP\IRequest')->disableOriginalConstructor()->getMock(),
  1403. $this->groupManager,
  1404. $this->userManager,
  1405. $this->contactsManager,
  1406. $config,
  1407. $this->session,
  1408. $this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
  1409. $this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(),
  1410. $this->shareManager
  1411. ])
  1412. ->setMethods(array('searchSharees', 'isRemoteSharingAllowed'))
  1413. ->getMock();
  1414. $sharees->expects($this->never())
  1415. ->method('searchSharees');
  1416. $sharees->expects($this->never())
  1417. ->method('isRemoteSharingAllowed');
  1418. try {
  1419. $sharees->search('', null, $page, $perPage, null);
  1420. $this->fail();
  1421. } catch (OCSBadRequestException $e) {
  1422. $this->assertEquals($message, $e->getMessage());
  1423. }
  1424. }
  1425. public function dataIsRemoteSharingAllowed() {
  1426. return [
  1427. ['file', true],
  1428. ['folder', true],
  1429. ['', false],
  1430. ['contacts', false],
  1431. ];
  1432. }
  1433. /**
  1434. * @dataProvider dataIsRemoteSharingAllowed
  1435. *
  1436. * @param string $itemType
  1437. * @param bool $expected
  1438. */
  1439. public function testIsRemoteSharingAllowed($itemType, $expected) {
  1440. $this->assertSame($expected, $this->invokePrivate($this->sharees, 'isRemoteSharingAllowed', [$itemType]));
  1441. }
  1442. public function dataSearchSharees() {
  1443. return [
  1444. ['test', 'folder', [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE], 1, 2, false, [], [], ['results' => [], 'exact' => [], 'exactIdMatch' => false],
  1445. [
  1446. 'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
  1447. 'users' => [],
  1448. 'groups' => [],
  1449. 'remotes' => [],
  1450. 'emails' => [],
  1451. ], false],
  1452. ['test', 'folder', [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE], 1, 2, false, [], [], ['results' => [], 'exact' => [], 'exactIdMatch' => false],
  1453. [
  1454. 'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
  1455. 'users' => [],
  1456. 'groups' => [],
  1457. 'remotes' => [],
  1458. 'emails' => [],
  1459. ], false],
  1460. [
  1461. 'test', 'folder', [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE], 1, 2, false, [
  1462. ['label' => 'test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  1463. ], [
  1464. ['label' => 'testgroup1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'testgroup1']],
  1465. ], [
  1466. 'results' => [['label' => 'testz@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']]], 'exact' => [], 'exactIdMatch' => false,
  1467. ],
  1468. [
  1469. 'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
  1470. 'users' => [
  1471. ['label' => 'test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  1472. ],
  1473. 'groups' => [
  1474. ['label' => 'testgroup1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'testgroup1']],
  1475. ],
  1476. 'remotes' => [
  1477. ['label' => 'testz@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']],
  1478. ],
  1479. 'emails' => [],
  1480. ], true,
  1481. ],
  1482. // No groups requested
  1483. [
  1484. 'test', 'folder', [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_REMOTE], 1, 2, false, [
  1485. ['label' => 'test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  1486. ], null, [
  1487. 'results' => [['label' => 'testz@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']]], 'exact' => [], 'exactIdMatch' => false
  1488. ],
  1489. [
  1490. 'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
  1491. 'users' => [
  1492. ['label' => 'test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  1493. ],
  1494. 'groups' => [],
  1495. 'remotes' => [
  1496. ['label' => 'testz@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']],
  1497. ],
  1498. 'emails' => [],
  1499. ], false,
  1500. ],
  1501. // Share type restricted to user - Only one user
  1502. [
  1503. 'test', 'folder', [Share::SHARE_TYPE_USER], 1, 2, false, [
  1504. ['label' => 'test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  1505. ], null, null,
  1506. [
  1507. 'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
  1508. 'users' => [
  1509. ['label' => 'test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  1510. ],
  1511. 'groups' => [],
  1512. 'remotes' => [],
  1513. 'emails' => [],
  1514. ], false,
  1515. ],
  1516. // Share type restricted to user - Multipage result
  1517. [
  1518. 'test', 'folder', [Share::SHARE_TYPE_USER], 1, 2, false, [
  1519. ['label' => 'test 1', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  1520. ['label' => 'test 2', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']],
  1521. ], null, null,
  1522. [
  1523. 'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
  1524. 'users' => [
  1525. ['label' => 'test 1', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
  1526. ['label' => 'test 2', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']],
  1527. ],
  1528. 'groups' => [],
  1529. 'remotes' => [],
  1530. 'emails' => [],
  1531. ], true,
  1532. ],
  1533. ];
  1534. }
  1535. /**
  1536. * @dataProvider dataSearchSharees
  1537. *
  1538. * @param string $searchTerm
  1539. * @param string $itemType
  1540. * @param array $shareTypes
  1541. * @param int $page
  1542. * @param int $perPage
  1543. * @param bool $shareWithGroupOnly
  1544. * @param array $mockedUserResult
  1545. * @param array $mockedGroupsResult
  1546. * @param array $mockedRemotesResult
  1547. * @param array $expected
  1548. * @param bool $nextLink
  1549. */
  1550. public function testSearchSharees($searchTerm, $itemType, array $shareTypes, $page, $perPage, $shareWithGroupOnly,
  1551. $mockedUserResult, $mockedGroupsResult, $mockedRemotesResult, $expected, $nextLink) {
  1552. /** @var \PHPUnit_Framework_MockObject_MockObject|\OCA\Files_Sharing\Controller\ShareesAPIController $sharees */
  1553. $sharees = $this->getMockBuilder('\OCA\Files_Sharing\Controller\ShareesAPIController')
  1554. ->setConstructorArgs([
  1555. 'files_sharing',
  1556. $this->getMockBuilder('OCP\IRequest')->disableOriginalConstructor()->getMock(),
  1557. $this->groupManager,
  1558. $this->userManager,
  1559. $this->contactsManager,
  1560. $this->getMockBuilder('OCP\IConfig')->disableOriginalConstructor()->getMock(),
  1561. $this->session,
  1562. $this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
  1563. $this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(),
  1564. $this->shareManager
  1565. ])
  1566. ->setMethods(array('getShareesForShareIds', 'getUsers', 'getGroups', 'getRemote'))
  1567. ->getMock();
  1568. $sharees->expects(($mockedUserResult === null) ? $this->never() : $this->once())
  1569. ->method('getUsers')
  1570. ->with($searchTerm)
  1571. ->willReturnCallback(function() use ($sharees, $mockedUserResult) {
  1572. $result = $this->invokePrivate($sharees, 'result');
  1573. $result['users'] = $mockedUserResult;
  1574. $this->invokePrivate($sharees, 'result', [$result]);
  1575. });
  1576. $sharees->expects(($mockedGroupsResult === null) ? $this->never() : $this->once())
  1577. ->method('getGroups')
  1578. ->with($searchTerm)
  1579. ->willReturnCallback(function() use ($sharees, $mockedGroupsResult) {
  1580. $result = $this->invokePrivate($sharees, 'result');
  1581. $result['groups'] = $mockedGroupsResult;
  1582. $this->invokePrivate($sharees, 'result', [$result]);
  1583. });
  1584. $sharees->expects(($mockedRemotesResult === null) ? $this->never() : $this->once())
  1585. ->method('getRemote')
  1586. ->with($searchTerm)
  1587. ->willReturn($mockedRemotesResult);
  1588. $ocs = $this->invokePrivate($sharees, 'searchSharees', [$searchTerm, $itemType, $shareTypes, $page, $perPage, $shareWithGroupOnly]);
  1589. $this->assertInstanceOf('\OCP\AppFramework\Http\DataResponse', $ocs);
  1590. $this->assertEquals($expected, $ocs->getData());
  1591. // Check if next link is set
  1592. if ($nextLink) {
  1593. $headers = $ocs->getHeaders();
  1594. $this->assertArrayHasKey('Link', $headers);
  1595. $this->assertStringStartsWith('<', $headers['Link']);
  1596. $this->assertStringEndsWith('>; rel="next"', $headers['Link']);
  1597. }
  1598. }
  1599. /**
  1600. * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException
  1601. * @expectedExceptionMessage Missing itemType
  1602. */
  1603. public function testSearchShareesNoItemType() {
  1604. $this->invokePrivate($this->sharees, 'searchSharees', ['', null, [], [], 0, 0, false]);
  1605. }
  1606. public function dataGetPaginationLink() {
  1607. return [
  1608. [1, '/ocs/v1.php', ['perPage' => 2], '<?perPage=2&page=2>; rel="next"'],
  1609. [10, '/ocs/v2.php', ['perPage' => 2], '<?perPage=2&page=11>; rel="next"'],
  1610. ];
  1611. }
  1612. /**
  1613. * @dataProvider dataGetPaginationLink
  1614. *
  1615. * @param int $page
  1616. * @param string $scriptName
  1617. * @param array $params
  1618. * @param array $expected
  1619. */
  1620. public function testGetPaginationLink($page, $scriptName, $params, $expected) {
  1621. $this->request->expects($this->once())
  1622. ->method('getScriptName')
  1623. ->willReturn($scriptName);
  1624. $this->assertEquals($expected, $this->invokePrivate($this->sharees, 'getPaginationLink', [$page, $params]));
  1625. }
  1626. public function dataIsV2() {
  1627. return [
  1628. ['/ocs/v1.php', false],
  1629. ['/ocs/v2.php', true],
  1630. ];
  1631. }
  1632. /**
  1633. * @dataProvider dataIsV2
  1634. *
  1635. * @param string $scriptName
  1636. * @param bool $expected
  1637. */
  1638. public function testIsV2($scriptName, $expected) {
  1639. $this->request->expects($this->once())
  1640. ->method('getScriptName')
  1641. ->willReturn($scriptName);
  1642. $this->assertEquals($expected, $this->invokePrivate($this->sharees, 'isV2'));
  1643. }
  1644. /**
  1645. * @dataProvider dataTestSplitUserRemote
  1646. *
  1647. * @param string $remote
  1648. * @param string $expectedUser
  1649. * @param string $expectedUrl
  1650. */
  1651. public function testSplitUserRemote($remote, $expectedUser, $expectedUrl) {
  1652. list($remoteUser, $remoteUrl) = $this->sharees->splitUserRemote($remote);
  1653. $this->assertSame($expectedUser, $remoteUser);
  1654. $this->assertSame($expectedUrl, $remoteUrl);
  1655. }
  1656. public function dataTestSplitUserRemote() {
  1657. $userPrefix = ['user@name', 'username'];
  1658. $protocols = ['', 'http://', 'https://'];
  1659. $remotes = [
  1660. 'localhost',
  1661. 'local.host',
  1662. 'dev.local.host',
  1663. 'dev.local.host/path',
  1664. 'dev.local.host/at@inpath',
  1665. '127.0.0.1',
  1666. '::1',
  1667. '::192.0.2.128',
  1668. '::192.0.2.128/at@inpath',
  1669. ];
  1670. $testCases = [];
  1671. foreach ($userPrefix as $user) {
  1672. foreach ($remotes as $remote) {
  1673. foreach ($protocols as $protocol) {
  1674. $baseUrl = $user . '@' . $protocol . $remote;
  1675. $testCases[] = [$baseUrl, $user, $protocol . $remote];
  1676. $testCases[] = [$baseUrl . '/', $user, $protocol . $remote];
  1677. $testCases[] = [$baseUrl . '/index.php', $user, $protocol . $remote];
  1678. $testCases[] = [$baseUrl . '/index.php/s/token', $user, $protocol . $remote];
  1679. }
  1680. }
  1681. }
  1682. return $testCases;
  1683. }
  1684. public function dataTestSplitUserRemoteError() {
  1685. return array(
  1686. // Invalid path
  1687. array('user@'),
  1688. // Invalid user
  1689. array('@server'),
  1690. array('us/er@server'),
  1691. array('us:er@server'),
  1692. // Invalid splitting
  1693. array('user'),
  1694. array(''),
  1695. array('us/erserver'),
  1696. array('us:erserver'),
  1697. );
  1698. }
  1699. /**
  1700. * @dataProvider dataTestSplitUserRemoteError
  1701. *
  1702. * @param string $id
  1703. * @expectedException \Exception
  1704. */
  1705. public function testSplitUserRemoteError($id) {
  1706. $this->sharees->splitUserRemote($id);
  1707. }
  1708. /**
  1709. * @dataProvider dataTestFixRemoteUrl
  1710. *
  1711. * @param string $url
  1712. * @param string $expected
  1713. */
  1714. public function testFixRemoteUrl($url, $expected) {
  1715. $this->assertSame($expected,
  1716. $this->invokePrivate($this->sharees, 'fixRemoteURL', [$url])
  1717. );
  1718. }
  1719. public function dataTestFixRemoteUrl() {
  1720. return [
  1721. ['http://localhost', 'http://localhost'],
  1722. ['http://localhost/', 'http://localhost'],
  1723. ['http://localhost/index.php', 'http://localhost'],
  1724. ['http://localhost/index.php/s/AShareToken', 'http://localhost'],
  1725. ];
  1726. }
  1727. }