CalendarManagerTest.php 2.7 KB

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