1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\CardDAV; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\DAV\MkCol; 6*a1a3b679SAndreas Boehler 7*a1a3b679SAndreas Boehlerclass AddressBookHomeTest extends \PHPUnit_Framework_TestCase { 8*a1a3b679SAndreas Boehler 9*a1a3b679SAndreas Boehler /** 10*a1a3b679SAndreas Boehler * @var Sabre\CardDAV\AddressBookHome 11*a1a3b679SAndreas Boehler */ 12*a1a3b679SAndreas Boehler protected $s; 13*a1a3b679SAndreas Boehler protected $backend; 14*a1a3b679SAndreas Boehler 15*a1a3b679SAndreas Boehler function setUp() { 16*a1a3b679SAndreas Boehler 17*a1a3b679SAndreas Boehler $this->backend = new Backend\Mock(); 18*a1a3b679SAndreas Boehler $this->s = new AddressBookHome( 19*a1a3b679SAndreas Boehler $this->backend, 20*a1a3b679SAndreas Boehler 'principals/user1' 21*a1a3b679SAndreas Boehler ); 22*a1a3b679SAndreas Boehler 23*a1a3b679SAndreas Boehler } 24*a1a3b679SAndreas Boehler 25*a1a3b679SAndreas Boehler function testGetName() { 26*a1a3b679SAndreas Boehler 27*a1a3b679SAndreas Boehler $this->assertEquals('user1', $this->s->getName()); 28*a1a3b679SAndreas Boehler 29*a1a3b679SAndreas Boehler } 30*a1a3b679SAndreas Boehler 31*a1a3b679SAndreas Boehler /** 32*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\MethodNotAllowed 33*a1a3b679SAndreas Boehler */ 34*a1a3b679SAndreas Boehler function testSetName() { 35*a1a3b679SAndreas Boehler 36*a1a3b679SAndreas Boehler $this->s->setName('user2'); 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas Boehler } 39*a1a3b679SAndreas Boehler 40*a1a3b679SAndreas Boehler /** 41*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\MethodNotAllowed 42*a1a3b679SAndreas Boehler */ 43*a1a3b679SAndreas Boehler function testDelete() { 44*a1a3b679SAndreas Boehler 45*a1a3b679SAndreas Boehler $this->s->delete(); 46*a1a3b679SAndreas Boehler 47*a1a3b679SAndreas Boehler } 48*a1a3b679SAndreas Boehler 49*a1a3b679SAndreas Boehler function testGetLastModified() { 50*a1a3b679SAndreas Boehler 51*a1a3b679SAndreas Boehler $this->assertNull($this->s->getLastModified()); 52*a1a3b679SAndreas Boehler 53*a1a3b679SAndreas Boehler } 54*a1a3b679SAndreas Boehler 55*a1a3b679SAndreas Boehler /** 56*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\MethodNotAllowed 57*a1a3b679SAndreas Boehler */ 58*a1a3b679SAndreas Boehler function testCreateFile() { 59*a1a3b679SAndreas Boehler 60*a1a3b679SAndreas Boehler $this->s->createFile('bla'); 61*a1a3b679SAndreas Boehler 62*a1a3b679SAndreas Boehler } 63*a1a3b679SAndreas Boehler 64*a1a3b679SAndreas Boehler /** 65*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\MethodNotAllowed 66*a1a3b679SAndreas Boehler */ 67*a1a3b679SAndreas Boehler function testCreateDirectory() { 68*a1a3b679SAndreas Boehler 69*a1a3b679SAndreas Boehler $this->s->createDirectory('bla'); 70*a1a3b679SAndreas Boehler 71*a1a3b679SAndreas Boehler } 72*a1a3b679SAndreas Boehler 73*a1a3b679SAndreas Boehler function testGetChild() { 74*a1a3b679SAndreas Boehler 75*a1a3b679SAndreas Boehler $child = $this->s->getChild('book1'); 76*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\CardDAV\\AddressBook', $child); 77*a1a3b679SAndreas Boehler $this->assertEquals('book1', $child->getName()); 78*a1a3b679SAndreas Boehler 79*a1a3b679SAndreas Boehler } 80*a1a3b679SAndreas Boehler 81*a1a3b679SAndreas Boehler /** 82*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\NotFound 83*a1a3b679SAndreas Boehler */ 84*a1a3b679SAndreas Boehler function testGetChild404() { 85*a1a3b679SAndreas Boehler 86*a1a3b679SAndreas Boehler $this->s->getChild('book2'); 87*a1a3b679SAndreas Boehler 88*a1a3b679SAndreas Boehler } 89*a1a3b679SAndreas Boehler 90*a1a3b679SAndreas Boehler function testGetChildren() { 91*a1a3b679SAndreas Boehler 92*a1a3b679SAndreas Boehler $children = $this->s->getChildren(); 93*a1a3b679SAndreas Boehler $this->assertEquals(1, count($children)); 94*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\CardDAV\\AddressBook', $children[0]); 95*a1a3b679SAndreas Boehler $this->assertEquals('book1', $children[0]->getName()); 96*a1a3b679SAndreas Boehler 97*a1a3b679SAndreas Boehler } 98*a1a3b679SAndreas Boehler 99*a1a3b679SAndreas Boehler function testCreateExtendedCollection() { 100*a1a3b679SAndreas Boehler 101*a1a3b679SAndreas Boehler $resourceType = [ 102*a1a3b679SAndreas Boehler '{' . Plugin::NS_CARDDAV . '}addressbook', 103*a1a3b679SAndreas Boehler '{DAV:}collection', 104*a1a3b679SAndreas Boehler ]; 105*a1a3b679SAndreas Boehler $this->s->createExtendedCollection('book2', new MkCol($resourceType, ['{DAV:}displayname' => 'a-book 2'])); 106*a1a3b679SAndreas Boehler 107*a1a3b679SAndreas Boehler $this->assertEquals(array( 108*a1a3b679SAndreas Boehler 'id' => 'book2', 109*a1a3b679SAndreas Boehler 'uri' => 'book2', 110*a1a3b679SAndreas Boehler '{DAV:}displayname' => 'a-book 2', 111*a1a3b679SAndreas Boehler 'principaluri' => 'principals/user1', 112*a1a3b679SAndreas Boehler ), $this->backend->addressBooks[1]); 113*a1a3b679SAndreas Boehler 114*a1a3b679SAndreas Boehler } 115*a1a3b679SAndreas Boehler 116*a1a3b679SAndreas Boehler /** 117*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\InvalidResourceType 118*a1a3b679SAndreas Boehler */ 119*a1a3b679SAndreas Boehler function testCreateExtendedCollectionInvalid() { 120*a1a3b679SAndreas Boehler 121*a1a3b679SAndreas Boehler $resourceType = array( 122*a1a3b679SAndreas Boehler '{DAV:}collection', 123*a1a3b679SAndreas Boehler ); 124*a1a3b679SAndreas Boehler $this->s->createExtendedCollection('book2', new MkCol($resourceType, array('{DAV:}displayname' => 'a-book 2'))); 125*a1a3b679SAndreas Boehler 126*a1a3b679SAndreas Boehler } 127*a1a3b679SAndreas Boehler 128*a1a3b679SAndreas Boehler 129*a1a3b679SAndreas Boehler function testACLMethods() { 130*a1a3b679SAndreas Boehler 131*a1a3b679SAndreas Boehler $this->assertEquals('principals/user1', $this->s->getOwner()); 132*a1a3b679SAndreas Boehler $this->assertNull($this->s->getGroup()); 133*a1a3b679SAndreas Boehler $this->assertEquals(array( 134*a1a3b679SAndreas Boehler array( 135*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}read', 136*a1a3b679SAndreas Boehler 'principal' => 'principals/user1', 137*a1a3b679SAndreas Boehler 'protected' => true, 138*a1a3b679SAndreas Boehler ), 139*a1a3b679SAndreas Boehler array( 140*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}write', 141*a1a3b679SAndreas Boehler 'principal' => 'principals/user1', 142*a1a3b679SAndreas Boehler 'protected' => true, 143*a1a3b679SAndreas Boehler ), 144*a1a3b679SAndreas Boehler ), $this->s->getACL()); 145*a1a3b679SAndreas Boehler 146*a1a3b679SAndreas Boehler } 147*a1a3b679SAndreas Boehler 148*a1a3b679SAndreas Boehler /** 149*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\MethodNotAllowed 150*a1a3b679SAndreas Boehler */ 151*a1a3b679SAndreas Boehler function testSetACL() { 152*a1a3b679SAndreas Boehler 153*a1a3b679SAndreas Boehler $this->s->setACL(array()); 154*a1a3b679SAndreas Boehler 155*a1a3b679SAndreas Boehler } 156*a1a3b679SAndreas Boehler 157*a1a3b679SAndreas Boehler function testGetSupportedPrivilegeSet() { 158*a1a3b679SAndreas Boehler 159*a1a3b679SAndreas Boehler $this->assertNull( 160*a1a3b679SAndreas Boehler $this->s->getSupportedPrivilegeSet() 161*a1a3b679SAndreas Boehler ); 162*a1a3b679SAndreas Boehler 163*a1a3b679SAndreas Boehler } 164*a1a3b679SAndreas Boehler} 165