SharedCalendarTest.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace Sabre\CalDAV;
  3. use Sabre\DAVACL;
  4. class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
  5. protected $backend;
  6. function getInstance(array $props = null) {
  7. if (is_null($props)) {
  8. $props = array(
  9. 'id' => 1,
  10. '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
  11. '{http://sabredav.org/ns}owner-principal' => 'principals/owner',
  12. '{http://sabredav.org/ns}read-only' => false,
  13. 'principaluri' => 'principals/sharee',
  14. );
  15. }
  16. $this->backend = new Backend\MockSharing(
  17. array($props),
  18. array(),
  19. array()
  20. );
  21. $this->backend->updateShares(1, array(
  22. array(
  23. 'href' => 'mailto:removeme@example.org',
  24. 'commonName' => 'To be removed',
  25. 'readOnly' => true,
  26. ),
  27. ), array());
  28. return new SharedCalendar($this->backend, $props);
  29. }
  30. function testGetSharedUrl() {
  31. $this->assertEquals('calendars/owner/original', $this->getInstance()->getSharedUrl());
  32. }
  33. function testGetShares() {
  34. $this->assertEquals(array(array(
  35. 'href' => 'mailto:removeme@example.org',
  36. 'commonName' => 'To be removed',
  37. 'readOnly' => true,
  38. 'status' => SharingPlugin::STATUS_NORESPONSE,
  39. )), $this->getInstance()->getShares());
  40. }
  41. function testGetOwner() {
  42. $this->assertEquals('principals/owner', $this->getInstance()->getOwner());
  43. }
  44. function testGetACL() {
  45. $expected = array(
  46. array(
  47. 'privilege' => '{DAV:}read',
  48. 'principal' => 'principals/owner',
  49. 'protected' => true,
  50. ),
  51. array(
  52. 'privilege' => '{DAV:}read',
  53. 'principal' => 'principals/owner/calendar-proxy-write',
  54. 'protected' => true,
  55. ),
  56. array(
  57. 'privilege' => '{DAV:}read',
  58. 'principal' => 'principals/owner/calendar-proxy-read',
  59. 'protected' => true,
  60. ),
  61. array(
  62. 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
  63. 'principal' => '{DAV:}authenticated',
  64. 'protected' => true,
  65. ),
  66. array(
  67. 'privilege' => '{DAV:}write',
  68. 'principal' => 'principals/owner',
  69. 'protected' => true,
  70. ),
  71. array(
  72. 'privilege' => '{DAV:}write',
  73. 'principal' => 'principals/owner/calendar-proxy-write',
  74. 'protected' => true,
  75. ),
  76. array(
  77. 'privilege' => '{DAV:}read',
  78. 'principal' => 'principals/sharee',
  79. 'protected' => true,
  80. ),
  81. array(
  82. 'privilege' => '{DAV:}write',
  83. 'principal' => 'principals/sharee',
  84. 'protected' => true,
  85. ),
  86. );
  87. $this->assertEquals($expected, $this->getInstance()->getACL());
  88. }
  89. function testGetChildACL() {
  90. $expected = array(
  91. array(
  92. 'privilege' => '{DAV:}read',
  93. 'principal' => 'principals/owner',
  94. 'protected' => true,
  95. ),
  96. array(
  97. 'privilege' => '{DAV:}read',
  98. 'principal' => 'principals/owner/calendar-proxy-write',
  99. 'protected' => true,
  100. ),
  101. array(
  102. 'privilege' => '{DAV:}read',
  103. 'principal' => 'principals/owner/calendar-proxy-read',
  104. 'protected' => true,
  105. ),
  106. array(
  107. 'privilege' => '{DAV:}write',
  108. 'principal' => 'principals/owner',
  109. 'protected' => true,
  110. ),
  111. array(
  112. 'privilege' => '{DAV:}write',
  113. 'principal' => 'principals/owner/calendar-proxy-write',
  114. 'protected' => true,
  115. ),
  116. array(
  117. 'privilege' => '{DAV:}read',
  118. 'principal' => 'principals/sharee',
  119. 'protected' => true,
  120. ),
  121. array(
  122. 'privilege' => '{DAV:}write',
  123. 'principal' => 'principals/sharee',
  124. 'protected' => true,
  125. ),
  126. );
  127. $this->assertEquals($expected, $this->getInstance()->getChildACL());
  128. }
  129. function testGetChildACLReadOnly() {
  130. $expected = array(
  131. array(
  132. 'privilege' => '{DAV:}read',
  133. 'principal' => 'principals/owner',
  134. 'protected' => true,
  135. ),
  136. array(
  137. 'privilege' => '{DAV:}read',
  138. 'principal' => 'principals/owner/calendar-proxy-write',
  139. 'protected' => true,
  140. ),
  141. array(
  142. 'privilege' => '{DAV:}read',
  143. 'principal' => 'principals/owner/calendar-proxy-read',
  144. 'protected' => true,
  145. ),
  146. array(
  147. 'privilege' => '{DAV:}read',
  148. 'principal' => 'principals/sharee',
  149. 'protected' => true,
  150. ),
  151. );
  152. $props = array(
  153. 'id' => 1,
  154. '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
  155. '{http://sabredav.org/ns}owner-principal' => 'principals/owner',
  156. '{http://sabredav.org/ns}read-only' => true,
  157. 'principaluri' => 'principals/sharee',
  158. );
  159. $this->assertEquals($expected, $this->getInstance($props)->getChildACL());
  160. }
  161. /**
  162. * @expectedException InvalidArgumentException
  163. */
  164. public function testCreateInstanceMissingArg() {
  165. $this->getInstance(array(
  166. 'id' => 1,
  167. '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
  168. '{http://sabredav.org/ns}read-only' => false,
  169. 'principaluri' => 'principals/sharee',
  170. ));
  171. }
  172. }