1<?php
2
3namespace Sabre\DAVACL;
4
5use Sabre\DAV;
6use Sabre\HTTP;
7
8
9class PrincipalCollectionTest extends \PHPUnit_Framework_TestCase {
10
11    public function testBasic() {
12
13        $backend = new PrincipalBackend\Mock();
14        $pc = new PrincipalCollection($backend);
15        $this->assertTrue($pc instanceof PrincipalCollection);
16
17        $this->assertEquals('principals',$pc->getName());
18
19    }
20
21    /**
22     * @depends testBasic
23     */
24    public function testGetChildren() {
25
26        $backend = new PrincipalBackend\Mock();
27        $pc = new PrincipalCollection($backend);
28
29        $children = $pc->getChildren();
30        $this->assertTrue(is_array($children));
31
32        foreach($children as $child) {
33            $this->assertTrue($child instanceof IPrincipal);
34        }
35
36    }
37
38    /**
39     * @depends testBasic
40     * @expectedException Sabre\DAV\Exception\MethodNotAllowed
41     */
42    public function testGetChildrenDisable() {
43
44        $backend = new PrincipalBackend\Mock();
45        $pc = new PrincipalCollection($backend);
46        $pc->disableListing = true;
47
48        $children = $pc->getChildren();
49
50    }
51
52    public function testFindByUri() {
53
54        $backend = new PrincipalBackend\Mock();
55        $pc = new PrincipalCollection($backend);
56        $this->assertEquals('principals/user1', $pc->findByUri('mailto:user1.sabredav@sabredav.org'));
57        $this->assertNull($pc->findByUri('mailto:fake.user.sabredav@sabredav.org'));
58        $this->assertNull($pc->findByUri(''));
59    }
60
61}
62