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.

CachedSubscriptionObjectTest.php 2.6KB

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. /**
  49. * @expectedException \Sabre\DAV\Exception\MethodNotAllowed
  50. * @expectedExceptionMessage Creating objects in a cached subscription is not allowed
  51. */
  52. public function testPut() {
  53. $backend = $this->createMock(CalDavBackend::class);
  54. $calendarInfo = [
  55. '{http://owncloud.org/ns}owner-principal' => 'user1',
  56. 'principaluri' => 'user2',
  57. 'id' => 666,
  58. 'uri' => 'cal',
  59. ];
  60. $objectData = [
  61. 'uri' => 'foo123'
  62. ];
  63. $calendarObject = new CachedSubscriptionObject($backend, $calendarInfo, $objectData);
  64. $calendarObject->put('');
  65. }
  66. /**
  67. * @expectedException \Sabre\DAV\Exception\MethodNotAllowed
  68. * @expectedExceptionMessage Deleting objects in a cached subscription is not allowed
  69. */
  70. public function testDelete() {
  71. $backend = $this->createMock(CalDavBackend::class);
  72. $calendarInfo = [
  73. '{http://owncloud.org/ns}owner-principal' => 'user1',
  74. 'principaluri' => 'user2',
  75. 'id' => 666,
  76. 'uri' => 'cal',
  77. ];
  78. $objectData = [
  79. 'uri' => 'foo123'
  80. ];
  81. $calendarObject = new CachedSubscriptionObject($backend, $calendarInfo, $objectData);
  82. $calendarObject->delete();
  83. }
  84. }