1<?php
2
3namespace Sabre\CardDAV;
4
5use Sabre\DAV;
6use Sabre\DAV\Xml\Property\Href;
7
8class PluginTest extends AbstractPluginTest {
9
10    function testConstruct() {
11
12        $this->assertEquals('{' . Plugin::NS_CARDDAV . '}addressbook', $this->server->resourceTypeMapping['Sabre\\CardDAV\\IAddressBook']);
13
14        $this->assertTrue(in_array('addressbook', $this->plugin->getFeatures()));
15        $this->assertEquals('carddav', $this->plugin->getPluginInfo()['name']);
16
17    }
18
19    function testSupportedReportSet() {
20
21        $this->assertEquals(array(
22            '{' . Plugin::NS_CARDDAV . '}addressbook-multiget',
23            '{' . Plugin::NS_CARDDAV . '}addressbook-query',
24        ), $this->plugin->getSupportedReportSet('addressbooks/user1/book1'));
25
26    }
27
28    function testSupportedReportSetEmpty() {
29
30        $this->assertEquals(array(
31        ), $this->plugin->getSupportedReportSet(''));
32
33    }
34
35    function testAddressBookHomeSet() {
36
37        $result = $this->server->getProperties('principals/user1', array('{' . Plugin::NS_CARDDAV . '}addressbook-home-set'));
38
39        $this->assertEquals(1, count($result));
40        $this->assertTrue(isset($result['{' . Plugin::NS_CARDDAV . '}addressbook-home-set']));
41        $this->assertEquals('addressbooks/user1/', $result['{' . Plugin::NS_CARDDAV . '}addressbook-home-set']->getHref());
42
43    }
44
45    function testDirectoryGateway() {
46
47        $result = $this->server->getProperties('principals/user1', array('{' . Plugin::NS_CARDDAV . '}directory-gateway'));
48
49        $this->assertEquals(1, count($result));
50        $this->assertTrue(isset($result['{' . Plugin::NS_CARDDAV . '}directory-gateway']));
51        $this->assertEquals(array('directory'), $result['{' . Plugin::NS_CARDDAV . '}directory-gateway']->getHrefs());
52
53    }
54
55    function testReportPassThrough() {
56
57        $this->assertNull($this->plugin->report('{DAV:}foo', new \DomDocument()));
58
59    }
60
61    function testHTMLActionsPanel() {
62
63        $output = '';
64        $r = $this->server->emit('onHTMLActionsPanel', [$this->server->tree->getNodeForPath('addressbooks/user1'), &$output]);
65        $this->assertFalse($r);
66
67        $this->assertTrue(!!strpos($output,'Display name'));
68
69    }
70
71    function testAddressbookPluginProperties() {
72
73        $ns = '{' . Plugin::NS_CARDDAV . '}';
74        $propFind = new DAV\PropFind('addressbooks/user1/book1', [
75            $ns . 'supported-address-data',
76            $ns . 'supported-collation-set',
77        ]);
78        $node = $this->server->tree->getNodeForPath('addressbooks/user1/book1');
79        $this->plugin->propFindEarly($propFind, $node);
80
81        $this->assertInstanceOf(
82            'Sabre\\CardDAV\\Xml\\Property\\SupportedAddressData',
83            $propFind->get($ns . 'supported-address-data')
84        );
85        $this->assertInstanceOf(
86            'Sabre\\CardDAV\\Xml\\Property\\SupportedCollationSet',
87            $propFind->get($ns . 'supported-collation-set')
88        );
89
90
91    }
92
93    function testGetTransform() {
94
95        $request = new \Sabre\HTTP\Request('GET', '/addressbooks/user1/book1/card1', ['Accept: application/vcard+json']);
96        $response = new \Sabre\HTTP\ResponseMock();
97        $this->server->invokeMethod($request, $response);
98
99        $this->assertEquals(200, $response->getStatus());
100
101    }
102
103}
104