CalendarManagerTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\Tests\unit\CalDAV;
  7. use OC\Calendar\Manager;
  8. use OCA\DAV\CalDAV\CalDavBackend;
  9. use OCA\DAV\CalDAV\CalendarImpl;
  10. use OCA\DAV\CalDAV\CalendarManager;
  11. use OCP\Calendar\IManager;
  12. use OCP\IConfig;
  13. use OCP\IL10N;
  14. use PHPUnit\Framework\MockObject\MockObject;
  15. use Psr\Log\LoggerInterface;
  16. class CalendarManagerTest extends \Test\TestCase {
  17. /** @var CalDavBackend | MockObject */
  18. private $backend;
  19. /** @var IL10N | MockObject */
  20. private $l10n;
  21. /** @var IConfig|MockObject */
  22. private $config;
  23. /** @var CalendarManager */
  24. private $manager;
  25. /** @var MockObject|LoggerInterface */
  26. private $logger;
  27. protected function setUp(): void {
  28. parent::setUp();
  29. $this->backend = $this->createMock(CalDavBackend::class);
  30. $this->l10n = $this->createMock(IL10N::class);
  31. $this->config = $this->createMock(IConfig::class);
  32. $this->logger = $this->createMock(LoggerInterface::class);
  33. $this->manager = new CalendarManager(
  34. $this->backend,
  35. $this->l10n,
  36. $this->config,
  37. $this->logger
  38. );
  39. }
  40. public function testSetupCalendarProvider(): void {
  41. $this->backend->expects($this->once())
  42. ->method('getCalendarsForUser')
  43. ->with('principals/users/user123')
  44. ->willReturn([
  45. ['id' => 123, 'uri' => 'blablub1'],
  46. ['id' => 456, 'uri' => 'blablub2'],
  47. ]);
  48. /** @var IManager | MockObject $calendarManager */
  49. $calendarManager = $this->createMock(Manager::class);
  50. $registeredIds = [];
  51. $calendarManager->expects($this->exactly(2))
  52. ->method('registerCalendar')
  53. ->willReturnCallback(function ($parameter) use (&$registeredIds): void {
  54. $this->assertInstanceOf(CalendarImpl::class, $parameter);
  55. $registeredIds[] = $parameter->getKey();
  56. });
  57. $this->manager->setupCalendarProvider($calendarManager, 'user123');
  58. $this->assertEquals(['123','456'], $registeredIds);
  59. }
  60. }