1<?php 2 3namespace Sabre\CalDAV\Subscriptions; 4 5use Sabre\DAV\Xml\Property\Href; 6use Sabre\DAV\PropPatch; 7 8class SubscriptionTest extends \PHPUnit_Framework_TestCase { 9 10 protected $backend; 11 12 function getSub($override = []) { 13 14 $caldavBackend = new \Sabre\CalDAV\Backend\MockSubscriptionSupport([],[]); 15 16 $info = [ 17 '{http://calendarserver.org/ns/}source' => new Href('http://example.org/src', false), 18 'lastmodified' => date('2013-04-06 11:40:00'), // tomorrow is my birthday! 19 '{DAV:}displayname' => 'displayname', 20 ]; 21 22 23 $id = $caldavBackend->createSubscription('principals/user1', 'uri', array_merge($info, $override)); 24 $subInfo = $caldavBackend->getSubscriptionsForUser('principals/user1'); 25 26 $this->assertEquals(1, count($subInfo)); 27 $subscription = new Subscription($caldavBackend, $subInfo[0]); 28 29 $this->backend = $caldavBackend; 30 return $subscription; 31 32 } 33 34 function testValues() { 35 36 $sub = $this->getSub(); 37 38 $this->assertEquals('uri', $sub->getName()); 39 $this->assertEquals(date('2013-04-06 11:40:00'), $sub->getLastModified()); 40 $this->assertEquals([], $sub->getChildren()); 41 42 $this->assertEquals( 43 [ 44 '{DAV:}displayname' => 'displayname', 45 '{http://calendarserver.org/ns/}source' => new Href('http://example.org/src',false), 46 ], 47 $sub->getProperties(['{DAV:}displayname', '{http://calendarserver.org/ns/}source']) 48 ); 49 50 $this->assertEquals('principals/user1', $sub->getOwner()); 51 $this->assertNull($sub->getGroup()); 52 53 $acl = [ 54 [ 55 'privilege' => '{DAV:}read', 56 'principal' => 'principals/user1', 57 'protected' => true, 58 ], 59 [ 60 'privilege' => '{DAV:}write', 61 'principal' => 'principals/user1', 62 'protected' => true, 63 ], 64 [ 65 'privilege' => '{DAV:}read', 66 'principal' => 'principals/user1/calendar-proxy-write', 67 'protected' => true, 68 ], 69 [ 70 'privilege' => '{DAV:}write', 71 'principal' => 'principals/user1/calendar-proxy-write', 72 'protected' => true, 73 ], 74 [ 75 'privilege' => '{DAV:}read', 76 'principal' => 'principals/user1/calendar-proxy-read', 77 'protected' => true, 78 ] 79 ]; 80 $this->assertEquals($acl, $sub->getACL()); 81 82 $this->assertNull($sub->getSupportedPrivilegeSet()); 83 84 } 85 86 function testValues2() { 87 88 $sub = $this->getSub([ 89 'lastmodified' => null, 90 ]); 91 92 $this->assertEquals(null, $sub->getLastModified()); 93 94 } 95 96 /** 97 * @expectedException \Sabre\DAV\Exception\MethodNotAllowed 98 */ 99 function testSetACL() { 100 101 $sub = $this->getSub(); 102 $sub->setACL([]); 103 104 } 105 106 function testDelete() { 107 108 $sub = $this->getSub(); 109 $sub->delete(); 110 111 $this->assertEquals([], $this->backend->getSubscriptionsForUser('principals1/user1')); 112 113 } 114 115 function testUpdateProperties() { 116 117 $sub = $this->getSub(); 118 $propPatch = new PropPatch([ 119 '{DAV:}displayname' => 'foo', 120 ]); 121 $sub->propPatch($propPatch); 122 $this->assertTrue($propPatch->commit()); 123 124 $this->assertEquals( 125 'foo', 126 $this->backend->getSubscriptionsForUser('principals/user1')[0]['{DAV:}displayname'] 127 ); 128 129 } 130 131 /** 132 * @expectedException \InvalidArgumentException 133 */ 134 function testBadConstruct() { 135 136 $caldavBackend = new \Sabre\CalDAV\Backend\MockSubscriptionSupport([],[]); 137 new Subscription($caldavBackend, []); 138 139 } 140 141} 142