1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV\Principal; 4*a1a3b679SAndreas Boehleruse Sabre\DAVACL; 5*a1a3b679SAndreas Boehler 6*a1a3b679SAndreas Boehlerclass UserTest extends \PHPUnit_Framework_TestCase { 7*a1a3b679SAndreas Boehler 8*a1a3b679SAndreas Boehler function getInstance() { 9*a1a3b679SAndreas Boehler 10*a1a3b679SAndreas Boehler $backend = new DAVACL\PrincipalBackend\Mock(); 11*a1a3b679SAndreas Boehler $backend->addPrincipal(array( 12*a1a3b679SAndreas Boehler 'uri' => 'principals/user/calendar-proxy-read', 13*a1a3b679SAndreas Boehler )); 14*a1a3b679SAndreas Boehler $backend->addPrincipal(array( 15*a1a3b679SAndreas Boehler 'uri' => 'principals/user/calendar-proxy-write', 16*a1a3b679SAndreas Boehler )); 17*a1a3b679SAndreas Boehler $backend->addPrincipal(array( 18*a1a3b679SAndreas Boehler 'uri' => 'principals/user/random', 19*a1a3b679SAndreas Boehler )); 20*a1a3b679SAndreas Boehler return new User($backend, array( 21*a1a3b679SAndreas Boehler 'uri' => 'principals/user', 22*a1a3b679SAndreas Boehler )); 23*a1a3b679SAndreas Boehler 24*a1a3b679SAndreas Boehler } 25*a1a3b679SAndreas Boehler 26*a1a3b679SAndreas Boehler /** 27*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\Forbidden 28*a1a3b679SAndreas Boehler */ 29*a1a3b679SAndreas Boehler function testCreateFile() { 30*a1a3b679SAndreas Boehler 31*a1a3b679SAndreas Boehler $u = $this->getInstance(); 32*a1a3b679SAndreas Boehler $u->createFile('test'); 33*a1a3b679SAndreas Boehler 34*a1a3b679SAndreas Boehler } 35*a1a3b679SAndreas Boehler 36*a1a3b679SAndreas Boehler /** 37*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\Forbidden 38*a1a3b679SAndreas Boehler */ 39*a1a3b679SAndreas Boehler function testCreateDirectory() { 40*a1a3b679SAndreas Boehler 41*a1a3b679SAndreas Boehler $u = $this->getInstance(); 42*a1a3b679SAndreas Boehler $u->createDirectory('test'); 43*a1a3b679SAndreas Boehler 44*a1a3b679SAndreas Boehler } 45*a1a3b679SAndreas Boehler 46*a1a3b679SAndreas Boehler function testGetChildProxyRead() { 47*a1a3b679SAndreas Boehler 48*a1a3b679SAndreas Boehler $u = $this->getInstance(); 49*a1a3b679SAndreas Boehler $child = $u->getChild('calendar-proxy-read'); 50*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyRead', $child); 51*a1a3b679SAndreas Boehler 52*a1a3b679SAndreas Boehler } 53*a1a3b679SAndreas Boehler 54*a1a3b679SAndreas Boehler function testGetChildProxyWrite() { 55*a1a3b679SAndreas Boehler 56*a1a3b679SAndreas Boehler $u = $this->getInstance(); 57*a1a3b679SAndreas Boehler $child = $u->getChild('calendar-proxy-write'); 58*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyWrite', $child); 59*a1a3b679SAndreas Boehler 60*a1a3b679SAndreas Boehler } 61*a1a3b679SAndreas Boehler 62*a1a3b679SAndreas Boehler /** 63*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\NotFound 64*a1a3b679SAndreas Boehler */ 65*a1a3b679SAndreas Boehler function testGetChildNotFound() { 66*a1a3b679SAndreas Boehler 67*a1a3b679SAndreas Boehler $u = $this->getInstance(); 68*a1a3b679SAndreas Boehler $child = $u->getChild('foo'); 69*a1a3b679SAndreas Boehler 70*a1a3b679SAndreas Boehler } 71*a1a3b679SAndreas Boehler 72*a1a3b679SAndreas Boehler /** 73*a1a3b679SAndreas Boehler * @expectedException Sabre\DAV\Exception\NotFound 74*a1a3b679SAndreas Boehler */ 75*a1a3b679SAndreas Boehler function testGetChildNotFound2() { 76*a1a3b679SAndreas Boehler 77*a1a3b679SAndreas Boehler $u = $this->getInstance(); 78*a1a3b679SAndreas Boehler $child = $u->getChild('random'); 79*a1a3b679SAndreas Boehler 80*a1a3b679SAndreas Boehler } 81*a1a3b679SAndreas Boehler 82*a1a3b679SAndreas Boehler function testGetChildren() { 83*a1a3b679SAndreas Boehler 84*a1a3b679SAndreas Boehler $u = $this->getInstance(); 85*a1a3b679SAndreas Boehler $children = $u->getChildren(); 86*a1a3b679SAndreas Boehler $this->assertEquals(2, count($children)); 87*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyRead', $children[0]); 88*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyWrite', $children[1]); 89*a1a3b679SAndreas Boehler 90*a1a3b679SAndreas Boehler } 91*a1a3b679SAndreas Boehler 92*a1a3b679SAndreas Boehler function testChildExist() { 93*a1a3b679SAndreas Boehler 94*a1a3b679SAndreas Boehler $u = $this->getInstance(); 95*a1a3b679SAndreas Boehler $this->assertTrue($u->childExists('calendar-proxy-read')); 96*a1a3b679SAndreas Boehler $this->assertTrue($u->childExists('calendar-proxy-write')); 97*a1a3b679SAndreas Boehler $this->assertFalse($u->childExists('foo')); 98*a1a3b679SAndreas Boehler 99*a1a3b679SAndreas Boehler } 100*a1a3b679SAndreas Boehler 101*a1a3b679SAndreas Boehler function testGetACL() { 102*a1a3b679SAndreas Boehler 103*a1a3b679SAndreas Boehler $expected = array( 104*a1a3b679SAndreas Boehler array( 105*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}read', 106*a1a3b679SAndreas Boehler 'principal' => '{DAV:}authenticated', 107*a1a3b679SAndreas Boehler 'protected' => true, 108*a1a3b679SAndreas Boehler ), 109*a1a3b679SAndreas Boehler array( 110*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}read', 111*a1a3b679SAndreas Boehler 'principal' => 'principals/user/calendar-proxy-read', 112*a1a3b679SAndreas Boehler 'protected' => true, 113*a1a3b679SAndreas Boehler ), 114*a1a3b679SAndreas Boehler array( 115*a1a3b679SAndreas Boehler 'privilege' => '{DAV:}read', 116*a1a3b679SAndreas Boehler 'principal' => 'principals/user/calendar-proxy-write', 117*a1a3b679SAndreas Boehler 'protected' => true, 118*a1a3b679SAndreas Boehler ), 119*a1a3b679SAndreas Boehler ); 120*a1a3b679SAndreas Boehler 121*a1a3b679SAndreas Boehler $u = $this->getInstance(); 122*a1a3b679SAndreas Boehler $this->assertEquals($expected, $u->getACL()); 123*a1a3b679SAndreas Boehler 124*a1a3b679SAndreas Boehler } 125*a1a3b679SAndreas Boehler 126*a1a3b679SAndreas Boehler} 127