CachedSubscriptionObjectTest.php 2.8 KB

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