UpcomingEventsControllerTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Tests\Unit\DAV\Service;
  8. use OCA\DAV\CalDAV\UpcomingEvent;
  9. use OCA\DAV\CalDAV\UpcomingEventsService;
  10. use OCA\DAV\Controller\UpcomingEventsController;
  11. use OCP\IRequest;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. use PHPUnit\Framework\TestCase;
  14. class UpcomingEventsControllerTest extends TestCase {
  15. private IRequest|MockObject $request;
  16. private UpcomingEventsService|MockObject $service;
  17. protected function setUp(): void {
  18. parent::setUp();
  19. $this->request = $this->createMock(IRequest::class);
  20. $this->service = $this->createMock(UpcomingEventsService::class);
  21. }
  22. public function testGetEventsAnonymously(): void {
  23. $controller = new UpcomingEventsController(
  24. $this->request,
  25. null,
  26. $this->service,
  27. );
  28. $response = $controller->getEvents('https://cloud.example.com/call/123');
  29. self::assertNull($response->getData());
  30. self::assertSame(401, $response->getStatus());
  31. }
  32. public function testGetEventsByLocation(): void {
  33. $controller = new UpcomingEventsController(
  34. $this->request,
  35. 'u1',
  36. $this->service,
  37. );
  38. $this->service->expects(self::once())
  39. ->method('getEvents')
  40. ->with('u1', 'https://cloud.example.com/call/123')
  41. ->willReturn([
  42. new UpcomingEvent(
  43. 'abc-123',
  44. null,
  45. 'personal',
  46. 123,
  47. 'Test',
  48. 'https://cloud.example.com/call/123',
  49. null,
  50. ),
  51. ]);
  52. $response = $controller->getEvents('https://cloud.example.com/call/123');
  53. self::assertNotNull($response->getData());
  54. self::assertIsArray($response->getData());
  55. self::assertCount(1, $response->getData()['events']);
  56. self::assertSame(200, $response->getStatus());
  57. $event1 = $response->getData()['events'][0];
  58. self::assertEquals('abc-123', $event1['uri']);
  59. }
  60. }