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