aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php
blob: 64cedd14295c73c82d42f4524eae22b8036211cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php

namespace Sabre\DAVACL;

use Sabre\DAV;
use Sabre\HTTP;


require_once 'Sabre/DAVACL/MockPrincipal.php';

class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase {

    function testUpdatePropertiesPassthrough() {

        $tree = array(
            new DAV\SimpleCollection('foo'),
        );
        $server = new DAV\Server($tree);
        $server->addPlugin(new Plugin());

        $result = $server->updateProperties('foo', array(
            '{DAV:}foo' => 'bar',
        ));

        $expected = array(
            '{DAV:}foo' => 403,
        );

        $this->assertEquals($expected, $result);

    }

    function testRemoveGroupMembers() {

        $tree = array(
            new MockPrincipal('foo','foo'),
        );
        $server = new DAV\Server($tree);
        $server->addPlugin(new Plugin());

        $result = $server->updateProperties('foo', array(
            '{DAV:}group-member-set' => null,
        ));

        $expected = array(
            '{DAV:}group-member-set' => 204
        );

        $this->assertEquals($expected, $result);
        $this->assertEquals(array(),$tree[0]->getGroupMemberSet());

    }

    function testSetGroupMembers() {

        $tree = [
            new MockPrincipal('foo','foo'),
        ];
        $server = new DAV\Server($tree);
        $server->addPlugin(new Plugin());

        $result = $server->updateProperties('foo', [
            '{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar','/baz'], true),
        ]);

        $expected = [
            '{DAV:}group-member-set' => 200
        ];

        $this->assertEquals($expected, $result);
        $this->assertEquals(['bar', 'baz'],$tree[0]->getGroupMemberSet());

    }

    /**
     * @expectedException Sabre\DAV\Exception
     */
    function testSetBadValue() {

        $tree = array(
            new MockPrincipal('foo','foo'),
        );
        $server = new DAV\Server($tree);
        $server->addPlugin(new Plugin());

        $result = $server->updateProperties('foo', array(
            '{DAV:}group-member-set' => new \StdClass(),
        ));

    }

    function testSetBadNode() {

        $tree = [
            new DAV\SimpleCollection('foo'),
        ];
        $server = new DAV\Server($tree);
        $server->addPlugin(new Plugin());

        $result = $server->updateProperties('foo', [
            '{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar','/baz'],false),
        ]);

        $expected = [
            '{DAV:}group-member-set' => 403,
        ];

        $this->assertEquals($expected, $result);

    }
}