CalendarHomeSubscriptionsTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace Sabre\CalDAV;
  3. use
  4. Sabre\DAV\MkCol,
  5. Sabre\DAVACL;
  6. class CalendarHomeSubscriptionsTest extends \PHPUnit_Framework_TestCase {
  7. protected $backend;
  8. function getInstance() {
  9. $props = [
  10. '{DAV:}displayname' => 'baz',
  11. '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/test.ics'),
  12. ];
  13. $principal = [
  14. 'uri' => 'principals/user1'
  15. ];
  16. $this->backend = new Backend\MockSubscriptionSupport([], []);
  17. $this->backend->createSubscription('principals/user1', 'uri', $props);
  18. return new CalendarHome($this->backend, $principal);
  19. }
  20. function testSimple() {
  21. $instance = $this->getInstance();
  22. $this->assertEquals('user1', $instance->getName());
  23. }
  24. function testGetChildren() {
  25. $instance = $this->getInstance();
  26. $children = $instance->getChildren();
  27. $this->assertEquals(1, count($children));
  28. foreach($children as $child) {
  29. if ($child instanceof Subscriptions\Subscription) {
  30. return;
  31. }
  32. }
  33. $this->fail('There were no subscription nodes in the calendar home');
  34. }
  35. function testCreateSubscription() {
  36. $instance = $this->getInstance();
  37. $rt = ['{DAV:}collection', '{http://calendarserver.org/ns/}subscribed'];
  38. $props = [
  39. '{DAV:}displayname' => 'baz',
  40. '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/test2.ics'),
  41. ];
  42. $instance->createExtendedCollection('sub2', new MkCol($rt, $props));
  43. $children = $instance->getChildren();
  44. $this->assertEquals(2, count($children));
  45. }
  46. /**
  47. * @expectedException \Sabre\DAV\Exception\InvalidResourceType
  48. */
  49. function testNoSubscriptionSupport() {
  50. $principal = [
  51. 'uri' => 'principals/user1'
  52. ];
  53. $backend = new Backend\Mock([], []);
  54. $uC = new CalendarHome($backend, $principal);
  55. $rt = ['{DAV:}collection', '{http://calendarserver.org/ns/}subscribed'];
  56. $props = [
  57. '{DAV:}displayname' => 'baz',
  58. '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/test2.ics'),
  59. ];
  60. $uC->createExtendedCollection('sub2', new MkCol($rt, $props));
  61. }
  62. }