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