CalendarHomeTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2017, Georg Ehrke
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  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, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\DAV\Tests\unit\CalDAV;
  24. use OCA\DAV\CalDAV\CalDavBackend;
  25. use OCA\DAV\CalDAV\CalendarHome;
  26. use Sabre\DAV\MkCol;
  27. use Test\TestCase;
  28. class CalendarHomeTest extends TestCase {
  29. /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject */
  30. private $backend;
  31. /** @var array */
  32. private $principalInfo = [];
  33. /** @var CalendarHome */
  34. private $calendarHome;
  35. protected function setUp() {
  36. parent::setUp();
  37. $this->backend = $this->createMock(CalDavBackend::class);
  38. $this->principalInfo = [
  39. 'uri' => 'user-principal-123',
  40. ];
  41. $this->calendarHome = new CalendarHome($this->backend,
  42. $this->principalInfo);
  43. }
  44. public function testCreateCalendarValidName() {
  45. /** @var MkCol | \PHPUnit_Framework_MockObject_MockObject $mkCol */
  46. $mkCol = $this->createMock(MkCol::class);
  47. $mkCol->method('getResourceType')
  48. ->will($this->returnValue(['{DAV:}collection',
  49. '{urn:ietf:params:xml:ns:caldav}calendar']));
  50. $mkCol->method('getRemainingValues')
  51. ->will($this->returnValue(['... properties ...']));
  52. $this->backend->expects($this->once())
  53. ->method('createCalendar')
  54. ->with('user-principal-123', 'name123', ['... properties ...']);
  55. $this->calendarHome->createExtendedCollection('name123', $mkCol);
  56. }
  57. /**
  58. * @expectedException \Sabre\DAV\Exception\MethodNotAllowed
  59. * @expectedExceptionMessage The resource you tried to create has a reserved name
  60. */
  61. public function testCreateCalendarReservedName() {
  62. /** @var MkCol | \PHPUnit_Framework_MockObject_MockObject $mkCol */
  63. $mkCol = $this->createMock(MkCol::class);
  64. $this->calendarHome->createExtendedCollection('contact_birthdays', $mkCol);
  65. }
  66. }