CalendarManagerTest.php 2.8 KB

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