1
0

CachedSubscriptionObjectTest.php 2.8 KB

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