CalendarManagerTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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() {
  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. $calendarManager->expects($this->at(0))
  71. ->method('registerCalendar')
  72. ->willReturnCallback(function () {
  73. $parameter = func_get_arg(0);
  74. $this->assertInstanceOf(CalendarImpl::class, $parameter);
  75. $this->assertEquals(123, $parameter->getKey());
  76. });
  77. $calendarManager->expects($this->at(1))
  78. ->method('registerCalendar')
  79. ->willReturnCallback(function () {
  80. $parameter = func_get_arg(0);
  81. $this->assertInstanceOf(CalendarImpl::class, $parameter);
  82. $this->assertEquals(456, $parameter->getKey());
  83. });
  84. $this->manager->setupCalendarProvider($calendarManager, 'user123');
  85. }
  86. }