PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Sabre/CalDAV/SharedCalendarTest.php

https://github.com/KOLANICH/SabreDAV
PHP | 212 lines | 179 code | 30 blank | 3 comment | 1 complexity | a11ef4ad1179f0ae608d3d1ce822f983 MD5 | raw file
Possible License(s): BSD-3-Clause
  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\Mock(
  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:}write',
  53. 'principal' => 'principals/owner',
  54. 'protected' => true,
  55. ),
  56. array(
  57. 'privilege' => '{DAV:}read',
  58. 'principal' => 'principals/owner/calendar-proxy-write',
  59. 'protected' => true,
  60. ),
  61. array(
  62. 'privilege' => '{DAV:}write',
  63. 'principal' => 'principals/owner/calendar-proxy-write',
  64. 'protected' => true,
  65. ),
  66. array(
  67. 'privilege' => '{DAV:}read',
  68. 'principal' => 'principals/owner/calendar-proxy-read',
  69. 'protected' => true,
  70. ),
  71. array(
  72. 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
  73. 'principal' => '{DAV:}authenticated',
  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:}write',
  98. 'principal' => 'principals/owner',
  99. 'protected' => true,
  100. ),
  101. array(
  102. 'privilege' => '{DAV:}read',
  103. 'principal' => 'principals/owner/calendar-proxy-write',
  104. 'protected' => true,
  105. ),
  106. array(
  107. 'privilege' => '{DAV:}write',
  108. 'principal' => 'principals/owner/calendar-proxy-write',
  109. 'protected' => true,
  110. ),
  111. array(
  112. 'privilege' => '{DAV:}read',
  113. 'principal' => 'principals/owner/calendar-proxy-read',
  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:}write',
  138. 'principal' => 'principals/owner',
  139. 'protected' => true,
  140. ),
  141. array(
  142. 'privilege' => '{DAV:}read',
  143. 'principal' => 'principals/owner/calendar-proxy-write',
  144. 'protected' => true,
  145. ),
  146. array(
  147. 'privilege' => '{DAV:}write',
  148. 'principal' => 'principals/owner/calendar-proxy-write',
  149. 'protected' => true,
  150. ),
  151. array(
  152. 'privilege' => '{DAV:}read',
  153. 'principal' => 'principals/owner/calendar-proxy-read',
  154. 'protected' => true,
  155. ),
  156. array(
  157. 'privilege' => '{DAV:}read',
  158. 'principal' => 'principals/sharee',
  159. 'protected' => true,
  160. ),
  161. );
  162. $props = array(
  163. 'id' => 1,
  164. '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
  165. '{http://sabredav.org/ns}owner-principal' => 'principals/owner',
  166. '{http://sabredav.org/ns}read-only' => true,
  167. 'principaluri' => 'principals/sharee',
  168. );
  169. $this->assertEquals($expected, $this->getInstance($props)->getChildACL());
  170. }
  171. /**
  172. * @expectedException InvalidArgumentException
  173. */
  174. public function testCreateInstanceMissingArg() {
  175. $this->getInstance(array(
  176. 'id' => 1,
  177. '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
  178. '{http://sabredav.org/ns}read-only' => false,
  179. 'principaluri' => 'principals/sharee',
  180. ));
  181. }
  182. }