1<?php 2 3namespace Sabre\DAVACL; 4 5use Sabre\DAV; 6use Sabre\HTTP; 7 8 9require_once 'Sabre/DAVACL/MockPrincipal.php'; 10 11class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { 12 13 function testUpdatePropertiesPassthrough() { 14 15 $tree = array( 16 new DAV\SimpleCollection('foo'), 17 ); 18 $server = new DAV\Server($tree); 19 $server->addPlugin(new Plugin()); 20 21 $result = $server->updateProperties('foo', array( 22 '{DAV:}foo' => 'bar', 23 )); 24 25 $expected = array( 26 '{DAV:}foo' => 403, 27 ); 28 29 $this->assertEquals($expected, $result); 30 31 } 32 33 function testRemoveGroupMembers() { 34 35 $tree = array( 36 new MockPrincipal('foo','foo'), 37 ); 38 $server = new DAV\Server($tree); 39 $server->addPlugin(new Plugin()); 40 41 $result = $server->updateProperties('foo', array( 42 '{DAV:}group-member-set' => null, 43 )); 44 45 $expected = array( 46 '{DAV:}group-member-set' => 204 47 ); 48 49 $this->assertEquals($expected, $result); 50 $this->assertEquals(array(),$tree[0]->getGroupMemberSet()); 51 52 } 53 54 function testSetGroupMembers() { 55 56 $tree = [ 57 new MockPrincipal('foo','foo'), 58 ]; 59 $server = new DAV\Server($tree); 60 $server->addPlugin(new Plugin()); 61 62 $result = $server->updateProperties('foo', [ 63 '{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar','/baz'], true), 64 ]); 65 66 $expected = [ 67 '{DAV:}group-member-set' => 200 68 ]; 69 70 $this->assertEquals($expected, $result); 71 $this->assertEquals(['bar', 'baz'],$tree[0]->getGroupMemberSet()); 72 73 } 74 75 /** 76 * @expectedException Sabre\DAV\Exception 77 */ 78 function testSetBadValue() { 79 80 $tree = array( 81 new MockPrincipal('foo','foo'), 82 ); 83 $server = new DAV\Server($tree); 84 $server->addPlugin(new Plugin()); 85 86 $result = $server->updateProperties('foo', array( 87 '{DAV:}group-member-set' => new \StdClass(), 88 )); 89 90 } 91 92 function testSetBadNode() { 93 94 $tree = [ 95 new DAV\SimpleCollection('foo'), 96 ]; 97 $server = new DAV\Server($tree); 98 $server->addPlugin(new Plugin()); 99 100 $result = $server->updateProperties('foo', [ 101 '{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar','/baz'],false), 102 ]); 103 104 $expected = [ 105 '{DAV:}group-member-set' => 403, 106 ]; 107 108 $this->assertEquals($expected, $result); 109 110 } 111} 112