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