CachedSubscriptionObjectTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 Georg Ehrke
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\DAV\Tests\unit\CalDAV;
  23. use OCA\DAV\CalDAV\CachedSubscriptionObject;
  24. use OCA\DAV\CalDAV\CalDavBackend;
  25. use OCA\DAV\CalDAV\Calendar;
  26. use OCA\DAV\CalDAV\CalendarImpl;
  27. class CachedSubscriptionObjectTest extends \Test\TestCase {
  28. public function testGet() {
  29. $backend = $this->createMock(CalDavBackend::class);
  30. $calendarInfo = [
  31. '{http://owncloud.org/ns}owner-principal' => 'user1',
  32. 'principaluri' => 'user2',
  33. 'id' => 666,
  34. 'uri' => 'cal',
  35. ];
  36. $objectData = [
  37. 'uri' => 'foo123'
  38. ];
  39. $backend->expects($this->once())
  40. ->method('getCalendarObject')
  41. ->with(666, 'foo123', 1)
  42. ->will($this->returnValue([
  43. 'calendardata' => 'BEGIN...',
  44. ]));
  45. $calendarObject = new CachedSubscriptionObject($backend, $calendarInfo, $objectData);
  46. $this->assertEquals('BEGIN...', $calendarObject->get());
  47. }
  48. public function testPut() {
  49. $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);
  50. $this->expectExceptionMessage('Creating objects in a cached subscription is not allowed');
  51. $backend = $this->createMock(CalDavBackend::class);
  52. $calendarInfo = [
  53. '{http://owncloud.org/ns}owner-principal' => 'user1',
  54. 'principaluri' => 'user2',
  55. 'id' => 666,
  56. 'uri' => 'cal',
  57. ];
  58. $objectData = [
  59. 'uri' => 'foo123'
  60. ];
  61. $calendarObject = new CachedSubscriptionObject($backend, $calendarInfo, $objectData);
  62. $calendarObject->put('');
  63. }
  64. public function testDelete() {
  65. $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);
  66. $this->expectExceptionMessage('Deleting objects in a cached subscription is not allowed');
  67. $backend = $this->createMock(CalDavBackend::class);
  68. $calendarInfo = [
  69. '{http://owncloud.org/ns}owner-principal' => 'user1',
  70. 'principaluri' => 'user2',
  71. 'id' => 666,
  72. 'uri' => 'cal',
  73. ];
  74. $objectData = [
  75. 'uri' => 'foo123'
  76. ];
  77. $calendarObject = new CachedSubscriptionObject($backend, $calendarInfo, $objectData);
  78. $calendarObject->delete();
  79. }
  80. }