You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CalendarManagerTest.php 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. class CalendarManagerTest extends \Test\TestCase {
  35. /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject */
  36. private $backend;
  37. /** @var IL10N | \PHPUnit_Framework_MockObject_MockObject */
  38. private $l10n;
  39. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  40. private $config;
  41. /** @var CalendarManager */
  42. private $manager;
  43. protected function setUp(): void {
  44. parent::setUp();
  45. $this->backend = $this->createMock(CalDavBackend::class);
  46. $this->l10n = $this->createMock(IL10N::class);
  47. $this->config = $this->createMock(IConfig::class);
  48. $this->manager = new CalendarManager($this->backend,
  49. $this->l10n, $this->config);
  50. }
  51. public function testSetupCalendarProvider() {
  52. $this->backend->expects($this->once())
  53. ->method('getCalendarsForUser')
  54. ->with('principals/users/user123')
  55. ->willReturn([
  56. ['id' => 123, 'uri' => 'blablub1'],
  57. ['id' => 456, 'uri' => 'blablub2'],
  58. ]);
  59. /** @var IManager | \PHPUnit_Framework_MockObject_MockObject $calendarManager */
  60. $calendarManager = $this->createMock(Manager::class);
  61. $calendarManager->expects($this->at(0))
  62. ->method('registerCalendar')
  63. ->willReturnCallback(function() {
  64. $parameter = func_get_arg(0);
  65. $this->assertInstanceOf(CalendarImpl::class, $parameter);
  66. $this->assertEquals(123, $parameter->getKey());
  67. });
  68. $calendarManager->expects($this->at(1))
  69. ->method('registerCalendar')
  70. ->willReturnCallback(function() {
  71. $parameter = func_get_arg(0);
  72. $this->assertInstanceOf(CalendarImpl::class, $parameter);
  73. $this->assertEquals(456, $parameter->getKey());
  74. });
  75. $this->manager->setupCalendarProvider($calendarManager, 'user123');
  76. }
  77. }