0011428: support caldav sync token
[tine20] / tests / tine20 / Tinebase / WebDav / Plugin / PrincipalSearchTest.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Tinebase
6  * @subpackage  WebDav
7  * @license     http://www.gnu.org/licenses/agpl.html
8  * @copyright   Copyright (c) 2013-2015 Metaways Infosystems GmbH (http://www.metaways.de)
9  * @author      Lars Kneschke <l.kneschke@metaways.de>
10  */
11
12 /**
13  * Test helper
14  */
15 require_once 'vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php';
16
17 /**
18  * Test class for Tinebase_WebDav_Plugin_OwnCloud
19  */
20 class Tinebase_WebDav_Plugin_PrincipalSearchTest extends Tinebase_WebDav_Plugin_AbstractBaseTest
21 {
22     /**
23      * Sets up the fixture.
24      * This method is called before a test is executed.
25      *
26      * @access protected
27      */
28     protected function setUp()
29     {
30         parent::setUp();
31         
32         $mockBackend = new Sabre\DAV\Auth\Backend\Mock();
33         $mockBackend->defaultUser = Tinebase_Core::getUser()->contact_id;
34         
35         $plugin = new Sabre\DAV\Auth\Plugin($mockBackend,'realm');
36         $this->server->addPlugin($plugin);
37         
38         $aclPlugin = new \Sabre\DAVACL\Plugin();
39         $aclPlugin->defaultUsernamePath    = Tinebase_WebDav_PrincipalBackend::PREFIX_USERS;
40         $aclPlugin->principalCollectionSet = array (Tinebase_WebDav_PrincipalBackend::PREFIX_USERS, Tinebase_WebDav_PrincipalBackend::PREFIX_GROUPS);
41         $this->server->addPlugin($aclPlugin);
42         
43         $this->server->addPlugin(new \Sabre\CalDAV\Plugin());
44         $this->server->addPlugin(new \Sabre\CalDAV\SharingPlugin());
45         
46         $this->plugin = new Tinebase_WebDav_Plugin_PrincipalSearch();
47         $this->server->addPlugin($this->plugin);
48     }
49
50     /**
51      * test getPluginName method
52      */
53     public function testGetPluginName()
54     {
55         $pluginName = $this->plugin->getPluginName();
56         
57         $this->assertEquals('calendarserverPrincipalSearch', $pluginName);
58     }
59     
60     /**
61      * test testGetProperties method
62      */
63     public function testGetProperties()
64     {
65         $body = '<?xml version="1.0" encoding="utf-8"?>
66                  <A:calendarserver-principal-search xmlns:A="http://calendarserver.org/ns/" context="attendee">
67                     <A:search-token>Administrators</A:search-token>
68                     <A:limit>
69                         <A:nresults>50</A:nresults>
70                     </A:limit>
71                     <B:prop xmlns:B="DAV:">
72                         <C:calendar-user-address-set xmlns:C="urn:ietf:params:xml:ns:caldav"/>
73                         <C:calendar-user-type xmlns:C="urn:ietf:params:xml:ns:caldav"/>
74                         <A:record-type/>
75                         <A:first-name/>
76                         <A:last-name/>
77                     </B:prop>
78                 </A:calendarserver-principal-search>';
79
80         $request = new Sabre\HTTP\Request(array(
81             'REQUEST_METHOD' => 'REPORT',
82             'REQUEST_URI'    => '/principals'
83         ));
84         $request->setBody($body);
85
86         $this->server->httpRequest = $request;
87         $this->server->exec();
88         //var_dump($this->response->body);
89         $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
90         
91         $responseDoc = new DOMDocument();
92         $responseDoc->loadXML($this->response->body);
93         #$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
94         $xpath = new DomXPath($responseDoc);
95         $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav');
96         
97         $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:calendar-user-address-set');
98         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
99         $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
100         
101         $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:calendar-user-type');
102         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
103         $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
104         
105         #$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-datetime');
106         #$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
107         #$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
108         
109         #$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-date');
110         #$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
111         #$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
112     }
113 }