EventsSearchProviderTest.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020, Georg Ehrke
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  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
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\DAV\Tests\unit\Search;
  26. use OCA\DAV\CalDAV\CalDavBackend;
  27. use OCA\DAV\Search\EventsSearchProvider;
  28. use OCP\App\IAppManager;
  29. use OCP\IL10N;
  30. use OCP\IURLGenerator;
  31. use OCP\IUser;
  32. use OCP\Search\ISearchQuery;
  33. use OCP\Search\SearchResult;
  34. use OCP\Search\SearchResultEntry;
  35. use Sabre\VObject\Reader;
  36. use Test\TestCase;
  37. class EventsSearchProviderTest extends TestCase {
  38. /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
  39. private $appManager;
  40. /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
  41. private $l10n;
  42. /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
  43. private $urlGenerator;
  44. /** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject */
  45. private $backend;
  46. /** @var EventsSearchProvider */
  47. private $provider;
  48. // NO SUMMARY
  49. private $vEvent0 = 'BEGIN:VCALENDAR'.PHP_EOL.
  50. 'VERSION:2.0'.PHP_EOL.
  51. 'PRODID:-//Apple Inc.//Mac OS X 10.11.6//EN'.PHP_EOL.
  52. 'CALSCALE:GREGORIAN'.PHP_EOL.
  53. 'BEGIN:VEVENT'.PHP_EOL.
  54. 'CREATED:20161004T144433Z'.PHP_EOL.
  55. 'UID:85560E76-1B0D-47E1-A735-21625767FCA4'.PHP_EOL.
  56. 'DTEND;VALUE=DATE:20161008'.PHP_EOL.
  57. 'TRANSP:TRANSPARENT'.PHP_EOL.
  58. 'DTSTART;VALUE=DATE:20161005'.PHP_EOL.
  59. 'DTSTAMP:20161004T144437Z'.PHP_EOL.
  60. 'SEQUENCE:0'.PHP_EOL.
  61. 'END:VEVENT'.PHP_EOL.
  62. 'END:VCALENDAR';
  63. // TIMED SAME DAY
  64. private $vEvent1 = 'BEGIN:VCALENDAR'.PHP_EOL.
  65. 'VERSION:2.0'.PHP_EOL.
  66. 'PRODID:-//Tests//'.PHP_EOL.
  67. 'CALSCALE:GREGORIAN'.PHP_EOL.
  68. 'BEGIN:VTIMEZONE'.PHP_EOL.
  69. 'TZID:Europe/Berlin'.PHP_EOL.
  70. 'BEGIN:DAYLIGHT'.PHP_EOL.
  71. 'TZOFFSETFROM:+0100'.PHP_EOL.
  72. 'RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU'.PHP_EOL.
  73. 'DTSTART:19810329T020000'.PHP_EOL.
  74. 'TZNAME:GMT+2'.PHP_EOL.
  75. 'TZOFFSETTO:+0200'.PHP_EOL.
  76. 'END:DAYLIGHT'.PHP_EOL.
  77. 'BEGIN:STANDARD'.PHP_EOL.
  78. 'TZOFFSETFROM:+0200'.PHP_EOL.
  79. 'RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU'.PHP_EOL.
  80. 'DTSTART:19961027T030000'.PHP_EOL.
  81. 'TZNAME:GMT+1'.PHP_EOL.
  82. 'TZOFFSETTO:+0100'.PHP_EOL.
  83. 'END:STANDARD'.PHP_EOL.
  84. 'END:VTIMEZONE'.PHP_EOL.
  85. 'BEGIN:VEVENT'.PHP_EOL.
  86. 'CREATED:20160809T163629Z'.PHP_EOL.
  87. 'UID:0AD16F58-01B3-463B-A215-FD09FC729A02'.PHP_EOL.
  88. 'DTEND;TZID=Europe/Berlin:20160816T100000'.PHP_EOL.
  89. 'TRANSP:OPAQUE'.PHP_EOL.
  90. 'SUMMARY:Test Europe Berlin'.PHP_EOL.
  91. 'DTSTART;TZID=Europe/Berlin:20160816T090000'.PHP_EOL.
  92. 'DTSTAMP:20160809T163632Z'.PHP_EOL.
  93. 'SEQUENCE:0'.PHP_EOL.
  94. 'END:VEVENT'.PHP_EOL.
  95. 'END:VCALENDAR';
  96. // TIMED DIFFERENT DAY
  97. private $vEvent2 = 'BEGIN:VCALENDAR'.PHP_EOL.
  98. 'VERSION:2.0'.PHP_EOL.
  99. 'PRODID:-//Tests//'.PHP_EOL.
  100. 'CALSCALE:GREGORIAN'.PHP_EOL.
  101. 'BEGIN:VTIMEZONE'.PHP_EOL.
  102. 'TZID:Europe/Berlin'.PHP_EOL.
  103. 'BEGIN:DAYLIGHT'.PHP_EOL.
  104. 'TZOFFSETFROM:+0100'.PHP_EOL.
  105. 'RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU'.PHP_EOL.
  106. 'DTSTART:19810329T020000'.PHP_EOL.
  107. 'TZNAME:GMT+2'.PHP_EOL.
  108. 'TZOFFSETTO:+0200'.PHP_EOL.
  109. 'END:DAYLIGHT'.PHP_EOL.
  110. 'BEGIN:STANDARD'.PHP_EOL.
  111. 'TZOFFSETFROM:+0200'.PHP_EOL.
  112. 'RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU'.PHP_EOL.
  113. 'DTSTART:19961027T030000'.PHP_EOL.
  114. 'TZNAME:GMT+1'.PHP_EOL.
  115. 'TZOFFSETTO:+0100'.PHP_EOL.
  116. 'END:STANDARD'.PHP_EOL.
  117. 'END:VTIMEZONE'.PHP_EOL.
  118. 'BEGIN:VEVENT'.PHP_EOL.
  119. 'CREATED:20160809T163629Z'.PHP_EOL.
  120. 'UID:0AD16F58-01B3-463B-A215-FD09FC729A02'.PHP_EOL.
  121. 'DTEND;TZID=Europe/Berlin:20160817T100000'.PHP_EOL.
  122. 'TRANSP:OPAQUE'.PHP_EOL.
  123. 'SUMMARY:Test Europe Berlin'.PHP_EOL.
  124. 'DTSTART;TZID=Europe/Berlin:20160816T090000'.PHP_EOL.
  125. 'DTSTAMP:20160809T163632Z'.PHP_EOL.
  126. 'SEQUENCE:0'.PHP_EOL.
  127. 'END:VEVENT'.PHP_EOL.
  128. 'END:VCALENDAR';
  129. // ALL-DAY ONE-DAY
  130. private $vEvent3 = 'BEGIN:VCALENDAR'.PHP_EOL.
  131. 'VERSION:2.0'.PHP_EOL.
  132. 'PRODID:-//Apple Inc.//Mac OS X 10.11.6//EN'.PHP_EOL.
  133. 'CALSCALE:GREGORIAN'.PHP_EOL.
  134. 'BEGIN:VEVENT'.PHP_EOL.
  135. 'CREATED:20161004T144433Z'.PHP_EOL.
  136. 'UID:85560E76-1B0D-47E1-A735-21625767FCA4'.PHP_EOL.
  137. 'DTEND;VALUE=DATE:20161006'.PHP_EOL.
  138. 'TRANSP:TRANSPARENT'.PHP_EOL.
  139. 'DTSTART;VALUE=DATE:20161005'.PHP_EOL.
  140. 'DTSTAMP:20161004T144437Z'.PHP_EOL.
  141. 'SEQUENCE:0'.PHP_EOL.
  142. 'END:VEVENT'.PHP_EOL.
  143. 'END:VCALENDAR';
  144. // ALL-DAY MULTIPLE DAYS
  145. private $vEvent4 = 'BEGIN:VCALENDAR'.PHP_EOL.
  146. 'VERSION:2.0'.PHP_EOL.
  147. 'PRODID:-//Apple Inc.//Mac OS X 10.11.6//EN'.PHP_EOL.
  148. 'CALSCALE:GREGORIAN'.PHP_EOL.
  149. 'BEGIN:VEVENT'.PHP_EOL.
  150. 'CREATED:20161004T144433Z'.PHP_EOL.
  151. 'UID:85560E76-1B0D-47E1-A735-21625767FCA4'.PHP_EOL.
  152. 'DTEND;VALUE=DATE:20161008'.PHP_EOL.
  153. 'TRANSP:TRANSPARENT'.PHP_EOL.
  154. 'DTSTART;VALUE=DATE:20161005'.PHP_EOL.
  155. 'DTSTAMP:20161004T144437Z'.PHP_EOL.
  156. 'SEQUENCE:0'.PHP_EOL.
  157. 'END:VEVENT'.PHP_EOL.
  158. 'END:VCALENDAR';
  159. // DURATION
  160. private $vEvent5 = 'BEGIN:VCALENDAR'.PHP_EOL.
  161. 'VERSION:2.0'.PHP_EOL.
  162. 'PRODID:-//Apple Inc.//Mac OS X 10.11.6//EN'.PHP_EOL.
  163. 'CALSCALE:GREGORIAN'.PHP_EOL.
  164. 'BEGIN:VEVENT'.PHP_EOL.
  165. 'CREATED:20161004T144433Z'.PHP_EOL.
  166. 'UID:85560E76-1B0D-47E1-A735-21625767FCA4'.PHP_EOL.
  167. 'DURATION:P5D'.PHP_EOL.
  168. 'TRANSP:TRANSPARENT'.PHP_EOL.
  169. 'DTSTART;VALUE=DATE:20161005'.PHP_EOL.
  170. 'DTSTAMP:20161004T144437Z'.PHP_EOL.
  171. 'SEQUENCE:0'.PHP_EOL.
  172. 'END:VEVENT'.PHP_EOL.
  173. 'END:VCALENDAR';
  174. // NO DTEND - DATE
  175. private $vEvent6 = 'BEGIN:VCALENDAR'.PHP_EOL.
  176. 'VERSION:2.0'.PHP_EOL.
  177. 'PRODID:-//Apple Inc.//Mac OS X 10.11.6//EN'.PHP_EOL.
  178. 'CALSCALE:GREGORIAN'.PHP_EOL.
  179. 'BEGIN:VEVENT'.PHP_EOL.
  180. 'CREATED:20161004T144433Z'.PHP_EOL.
  181. 'UID:85560E76-1B0D-47E1-A735-21625767FCA4'.PHP_EOL.
  182. 'TRANSP:TRANSPARENT'.PHP_EOL.
  183. 'DTSTART;VALUE=DATE:20161005'.PHP_EOL.
  184. 'DTSTAMP:20161004T144437Z'.PHP_EOL.
  185. 'SEQUENCE:0'.PHP_EOL.
  186. 'END:VEVENT'.PHP_EOL.
  187. 'END:VCALENDAR';
  188. // NO DTEND - DATE-TIME
  189. private $vEvent7 = 'BEGIN:VCALENDAR'.PHP_EOL.
  190. 'VERSION:2.0'.PHP_EOL.
  191. 'PRODID:-//Tests//'.PHP_EOL.
  192. 'CALSCALE:GREGORIAN'.PHP_EOL.
  193. 'BEGIN:VTIMEZONE'.PHP_EOL.
  194. 'TZID:Europe/Berlin'.PHP_EOL.
  195. 'BEGIN:DAYLIGHT'.PHP_EOL.
  196. 'TZOFFSETFROM:+0100'.PHP_EOL.
  197. 'RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU'.PHP_EOL.
  198. 'DTSTART:19810329T020000'.PHP_EOL.
  199. 'TZNAME:GMT+2'.PHP_EOL.
  200. 'TZOFFSETTO:+0200'.PHP_EOL.
  201. 'END:DAYLIGHT'.PHP_EOL.
  202. 'BEGIN:STANDARD'.PHP_EOL.
  203. 'TZOFFSETFROM:+0200'.PHP_EOL.
  204. 'RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU'.PHP_EOL.
  205. 'DTSTART:19961027T030000'.PHP_EOL.
  206. 'TZNAME:GMT+1'.PHP_EOL.
  207. 'TZOFFSETTO:+0100'.PHP_EOL.
  208. 'END:STANDARD'.PHP_EOL.
  209. 'END:VTIMEZONE'.PHP_EOL.
  210. 'BEGIN:VEVENT'.PHP_EOL.
  211. 'CREATED:20160809T163629Z'.PHP_EOL.
  212. 'UID:0AD16F58-01B3-463B-A215-FD09FC729A02'.PHP_EOL.
  213. 'TRANSP:OPAQUE'.PHP_EOL.
  214. 'SUMMARY:Test Europe Berlin'.PHP_EOL.
  215. 'DTSTART;TZID=Europe/Berlin:20160816T090000'.PHP_EOL.
  216. 'DTSTAMP:20160809T163632Z'.PHP_EOL.
  217. 'SEQUENCE:0'.PHP_EOL.
  218. 'END:VEVENT'.PHP_EOL.
  219. 'END:VCALENDAR';
  220. protected function setUp(): void {
  221. parent::setUp();
  222. $this->appManager = $this->createMock(IAppManager::class);
  223. $this->l10n = $this->createMock(IL10N::class);
  224. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  225. $this->backend = $this->createMock(CalDavBackend::class);
  226. $this->provider = new EventsSearchProvider(
  227. $this->appManager,
  228. $this->l10n,
  229. $this->urlGenerator,
  230. $this->backend
  231. );
  232. }
  233. public function testGetId(): void {
  234. $this->assertEquals('calendar', $this->provider->getId());
  235. }
  236. public function testGetName(): void {
  237. $this->l10n->expects($this->exactly(1))
  238. ->method('t')
  239. ->with('Events')
  240. ->willReturnArgument(0);
  241. $this->assertEquals('Events', $this->provider->getName());
  242. }
  243. public function testSearchAppDisabled(): void {
  244. $user = $this->createMock(IUser::class);
  245. $query = $this->createMock(ISearchQuery::class);
  246. $this->appManager->expects($this->once())
  247. ->method('isEnabledForUser')
  248. ->with('calendar', $user)
  249. ->willReturn(false);
  250. $this->l10n->expects($this->exactly(1))
  251. ->method('t')
  252. ->willReturnArgument(0);
  253. $this->backend->expects($this->never())
  254. ->method('getCalendarsForUser');
  255. $this->backend->expects($this->never())
  256. ->method('getSubscriptionsForUser');
  257. $this->backend->expects($this->never())
  258. ->method('searchPrincipalUri');
  259. $actual = $this->provider->search($user, $query);
  260. $data = $actual->jsonSerialize();
  261. $this->assertInstanceOf(SearchResult::class, $actual);
  262. $this->assertEquals('Events', $data['name']);
  263. $this->assertEmpty($data['entries']);
  264. $this->assertFalse($data['isPaginated']);
  265. $this->assertNull($data['cursor']);
  266. }
  267. public function testSearch(): void {
  268. $user = $this->createMock(IUser::class);
  269. $user->method('getUID')->willReturn('john.doe');
  270. $query = $this->createMock(ISearchQuery::class);
  271. $query->method('getTerm')->willReturn('search term');
  272. $query->method('getLimit')->willReturn(5);
  273. $query->method('getCursor')->willReturn(20);
  274. $this->appManager->expects($this->once())
  275. ->method('isEnabledForUser')
  276. ->with('calendar', $user)
  277. ->willReturn(true);
  278. $this->l10n->method('t')->willReturnArgument(0);
  279. $this->backend->expects($this->once())
  280. ->method('getCalendarsForUser')
  281. ->with('principals/users/john.doe')
  282. ->willReturn([
  283. [
  284. 'id' => 99,
  285. 'principaluri' => 'principals/users/john.doe',
  286. 'uri' => 'calendar-uri-99',
  287. ], [
  288. 'id' => 123,
  289. 'principaluri' => 'principals/users/john.doe',
  290. 'uri' => 'calendar-uri-123',
  291. ]
  292. ]);
  293. $this->backend->expects($this->once())
  294. ->method('getSubscriptionsForUser')
  295. ->with('principals/users/john.doe')
  296. ->willReturn([
  297. [
  298. 'id' => 1337,
  299. 'principaluri' => 'principals/users/john.doe',
  300. 'uri' => 'subscription-uri-1337',
  301. ]
  302. ]);
  303. $this->backend->expects($this->once())
  304. ->method('searchPrincipalUri')
  305. ->with('principals/users/john.doe', 'search term', ['VEVENT'],
  306. ['SUMMARY', 'LOCATION', 'DESCRIPTION', 'ATTENDEE', 'ORGANIZER', 'CATEGORIES'],
  307. ['ATTENDEE' => ['CN'], 'ORGANIZER' => ['CN']],
  308. ['limit' => 5, 'offset' => 20])
  309. ->willReturn([
  310. [
  311. 'calendarid' => 99,
  312. 'calendartype' => CalDavBackend::CALENDAR_TYPE_CALENDAR,
  313. 'uri' => 'event0.ics',
  314. 'calendardata' => $this->vEvent0,
  315. ],
  316. [
  317. 'calendarid' => 123,
  318. 'calendartype' => CalDavBackend::CALENDAR_TYPE_CALENDAR,
  319. 'uri' => 'event1.ics',
  320. 'calendardata' => $this->vEvent1,
  321. ],
  322. [
  323. 'calendarid' => 1337,
  324. 'calendartype' => CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION,
  325. 'uri' => 'event2.ics',
  326. 'calendardata' => $this->vEvent2,
  327. ]
  328. ]);
  329. $provider = $this->getMockBuilder(EventsSearchProvider::class)
  330. ->setConstructorArgs([
  331. $this->appManager,
  332. $this->l10n,
  333. $this->urlGenerator,
  334. $this->backend,
  335. ])
  336. ->setMethods([
  337. 'getDeepLinkToCalendarApp',
  338. 'generateSubline',
  339. ])
  340. ->getMock();
  341. $provider->expects($this->exactly(3))
  342. ->method('generateSubline')
  343. ->willReturn('subline');
  344. $provider->expects($this->exactly(3))
  345. ->method('getDeepLinkToCalendarApp')
  346. ->withConsecutive(
  347. ['principals/users/john.doe', 'calendar-uri-99', 'event0.ics'],
  348. ['principals/users/john.doe', 'calendar-uri-123', 'event1.ics'],
  349. ['principals/users/john.doe', 'subscription-uri-1337', 'event2.ics']
  350. )
  351. ->willReturn('deep-link-to-calendar');
  352. $actual = $provider->search($user, $query);
  353. $data = $actual->jsonSerialize();
  354. $this->assertInstanceOf(SearchResult::class, $actual);
  355. $this->assertEquals('Events', $data['name']);
  356. $this->assertCount(3, $data['entries']);
  357. $this->assertTrue($data['isPaginated']);
  358. $this->assertEquals(23, $data['cursor']);
  359. $result0 = $data['entries'][0];
  360. $result0Data = $result0->jsonSerialize();
  361. $result1 = $data['entries'][1];
  362. $result1Data = $result1->jsonSerialize();
  363. $result2 = $data['entries'][2];
  364. $result2Data = $result2->jsonSerialize();
  365. $this->assertInstanceOf(SearchResultEntry::class, $result0);
  366. $this->assertEmpty($result0Data['thumbnailUrl']);
  367. $this->assertEquals('Untitled event', $result0Data['title']);
  368. $this->assertEquals('subline', $result0Data['subline']);
  369. $this->assertEquals('deep-link-to-calendar', $result0Data['resourceUrl']);
  370. $this->assertEquals('icon-calendar-dark', $result0Data['icon']);
  371. $this->assertFalse($result0Data['rounded']);
  372. $this->assertInstanceOf(SearchResultEntry::class, $result1);
  373. $this->assertEmpty($result1Data['thumbnailUrl']);
  374. $this->assertEquals('Test Europe Berlin', $result1Data['title']);
  375. $this->assertEquals('subline', $result1Data['subline']);
  376. $this->assertEquals('deep-link-to-calendar', $result1Data['resourceUrl']);
  377. $this->assertEquals('icon-calendar-dark', $result1Data['icon']);
  378. $this->assertFalse($result1Data['rounded']);
  379. $this->assertInstanceOf(SearchResultEntry::class, $result2);
  380. $this->assertEmpty($result2Data['thumbnailUrl']);
  381. $this->assertEquals('Test Europe Berlin', $result2Data['title']);
  382. $this->assertEquals('subline', $result2Data['subline']);
  383. $this->assertEquals('deep-link-to-calendar', $result2Data['resourceUrl']);
  384. $this->assertEquals('icon-calendar-dark', $result2Data['icon']);
  385. $this->assertFalse($result2Data['rounded']);
  386. }
  387. public function testGetDeepLinkToCalendarApp(): void {
  388. $this->urlGenerator->expects($this->at(0))
  389. ->method('linkTo')
  390. ->with('', 'remote.php')
  391. ->willReturn('link-to-remote.php');
  392. $this->urlGenerator->expects($this->at(1))
  393. ->method('linkToRoute')
  394. ->with('calendar.view.index')
  395. ->willReturn('link-to-route-calendar/');
  396. $this->urlGenerator->expects($this->at(2))
  397. ->method('getAbsoluteURL')
  398. ->with('link-to-route-calendar/edit/bGluay10by1yZW1vdGUucGhwL2Rhdi9jYWxlbmRhcnMvam9obi5kb2UvZm9vL2Jhci5pY3M=')
  399. ->willReturn('absolute-url-to-route');
  400. $actual = self::invokePrivate($this->provider, 'getDeepLinkToCalendarApp', ['principals/users/john.doe', 'foo', 'bar.ics']);
  401. $this->assertEquals('absolute-url-to-route', $actual);
  402. }
  403. /**
  404. * @param string $ics
  405. * @param string $expectedSubline
  406. *
  407. * @dataProvider generateSublineDataProvider
  408. */
  409. public function testGenerateSubline(string $ics, string $expectedSubline): void {
  410. $vCalendar = Reader::read($ics, Reader::OPTION_FORGIVING);
  411. $eventComponent = $vCalendar->VEVENT;
  412. $this->l10n->method('l')
  413. ->willReturnCallback(static function (string $type, \DateTime $date, $_):string {
  414. if ($type === 'time') {
  415. return $date->format('H:i');
  416. }
  417. return $date->format('m-d');
  418. });
  419. $actual = self::invokePrivate($this->provider, 'generateSubline', [$eventComponent]);
  420. $this->assertEquals($expectedSubline, $actual);
  421. }
  422. public function generateSublineDataProvider(): array {
  423. return [
  424. [$this->vEvent1, '08-16 09:00 - 10:00'],
  425. [$this->vEvent2, '08-16 09:00 - 08-17 10:00'],
  426. [$this->vEvent3, '10-05'],
  427. [$this->vEvent4, '10-05 - 10-07'],
  428. [$this->vEvent5, '10-05 - 10-09'],
  429. [$this->vEvent6, '10-05'],
  430. [$this->vEvent7, '08-16 09:00 - 09:00'],
  431. ];
  432. }
  433. }