1
0

CalendarManagerTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\Tests\unit\CalDAV;
  27. use OC\Calendar\Manager;
  28. use OCA\DAV\CalDAV\CalDavBackend;
  29. use OCA\DAV\CalDAV\CalendarImpl;
  30. use OCA\DAV\CalDAV\CalendarManager;
  31. use OCP\Calendar\IManager;
  32. use OCP\IConfig;
  33. use OCP\IL10N;
  34. use PHPUnit\Framework\MockObject\MockObject;
  35. use Psr\Log\LoggerInterface;
  36. class CalendarManagerTest extends \Test\TestCase {
  37. /** @var CalDavBackend | MockObject */
  38. private $backend;
  39. /** @var IL10N | MockObject */
  40. private $l10n;
  41. /** @var IConfig|MockObject */
  42. private $config;
  43. /** @var CalendarManager */
  44. private $manager;
  45. /** @var MockObject|LoggerInterface */
  46. private $logger;
  47. protected function setUp(): void {
  48. parent::setUp();
  49. $this->backend = $this->createMock(CalDavBackend::class);
  50. $this->l10n = $this->createMock(IL10N::class);
  51. $this->config = $this->createMock(IConfig::class);
  52. $this->logger = $this->createMock(LoggerInterface::class);
  53. $this->manager = new CalendarManager(
  54. $this->backend,
  55. $this->l10n,
  56. $this->config,
  57. $this->logger
  58. );
  59. }
  60. public function testSetupCalendarProvider(): void {
  61. $this->backend->expects($this->once())
  62. ->method('getCalendarsForUser')
  63. ->with('principals/users/user123')
  64. ->willReturn([
  65. ['id' => 123, 'uri' => 'blablub1'],
  66. ['id' => 456, 'uri' => 'blablub2'],
  67. ]);
  68. /** @var IManager | MockObject $calendarManager */
  69. $calendarManager = $this->createMock(Manager::class);
  70. $registeredIds = [];
  71. $calendarManager->expects($this->exactly(2))
  72. ->method('registerCalendar')
  73. ->willReturnCallback(function ($parameter) use (&$registeredIds): void {
  74. $this->assertInstanceOf(CalendarImpl::class, $parameter);
  75. $registeredIds[] = $parameter->getKey();
  76. });
  77. $this->manager->setupCalendarProvider($calendarManager, 'user123');
  78. $this->assertEquals(['123','456'], $registeredIds);
  79. }
  80. }