0012204: allow account loginname instead of contact displayname
[tine20] / tests / tine20 / Tinebase / WebDav / Plugin / OwnCloudTest.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-2015 Metaways Infosystems GmbH (http://www.metaways.de)
9  * @author      Lars Kneschke <l.kneschke@metaways.de>
10  */
11
12
13 /**
14  * Test class for Tinebase_WebDav_Plugin_OwnCloud
15  */
16 class Tinebase_WebDav_Plugin_OwnCloudTest extends Tinebase_WebDav_Plugin_AbstractBaseTest
17 {
18     /**
19      * Runs the test methods of this class.
20      *
21      * @access public
22      * @static
23      */
24     public static function main()
25     {
26         $suite  = new PHPUnit_Framework_TestSuite('Tine 2.0 Plugin OwnCloud Tests');
27         PHPUnit_TextUI_TestRunner::run($suite);
28     }
29
30     /**
31      * Sets up the fixture.
32      * This method is called before a test is executed.
33      *
34      * @access protected
35      */
36     protected function setUp()
37     {
38         parent::setUp();
39         
40         $this->plugin = new Tinebase_WebDav_Plugin_OwnCloud();
41         
42         $this->server->addPlugin($this->plugin);
43     }
44
45     /**
46      * tear down tests
47      */
48     protected function tearDown()
49     {
50         parent::tearDown();
51         Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, false);
52     }
53
54     /**
55      * test getPluginName method
56      */
57     public function testGetPluginName()
58     {
59         $pluginName = $this->plugin->getPluginName();
60         
61         $this->assertEquals('Tinebase_WebDav_Plugin_OwnCloud', $pluginName);
62     }
63     
64     /**
65      * test testGetProperties method
66      */
67     public function testGetProperties()
68     {
69         $body = '<?xml version="1.0" encoding="utf-8"?>
70                  <propfind xmlns="DAV:">
71                     <prop>
72                         <getlastmodified xmlns="DAV:"/>
73                         <getcontentlength xmlns="DAV:"/>
74                         <resourcetype xmlns="DAV:"/>
75                         <getetag xmlns="DAV:"/>
76                         <id xmlns="http://owncloud.org/ns"/>
77                     </prop>
78                  </propfind>';
79
80         $request = new Sabre\HTTP\Request(array(
81             'REQUEST_METHOD' => 'PROPFIND',
82             'REQUEST_URI'    => '/remote.php/webdav/' . Tinebase_Core::getUser()->accountDisplayName,
83             'HTTP_DEPTH'     => '0',
84         ));
85         $request->setBody($body);
86
87         $this->server->httpRequest = $request;
88         $this->server->exec();
89         //var_dump($this->response->body);
90         $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
91         
92         $responseDoc = new DOMDocument();
93         $responseDoc->loadXML($this->response->body);
94         //$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
95         $xpath = new DomXPath($responseDoc);
96         $xpath->registerNamespace('owncloud', 'http://owncloud.org/ns');
97         
98         $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/owncloud:id');
99         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
100         $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
101     }
102     
103     /**
104      * test testGetProperties method with alternate loginname config
105      */
106     public function testGetProperties2()
107     {
108         Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, true);
109         
110         $body = '<?xml version="1.0" encoding="utf-8"?>
111                  <propfind xmlns="DAV:">
112                     <prop>
113                         <getlastmodified xmlns="DAV:"/>
114                         <getcontentlength xmlns="DAV:"/>
115                         <resourcetype xmlns="DAV:"/>
116                         <getetag xmlns="DAV:"/>
117                         <id xmlns="http://owncloud.org/ns"/>
118                     </prop>
119                  </propfind>';
120     
121         $request = new Sabre\HTTP\Request(array(
122                 'REQUEST_METHOD' => 'PROPFIND',
123                 'REQUEST_URI'    => '/remote.php/webdav/' . Tinebase_Core::getUser()->accountLoginName,
124                 'HTTP_DEPTH'     => '0',
125         ));
126         $request->setBody($body);
127     
128         $this->server->httpRequest = $request;
129         $this->server->exec();
130         //var_dump($this->response->body);
131         $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
132     
133         $responseDoc = new DOMDocument();
134         $responseDoc->loadXML($this->response->body);
135         //$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
136         $xpath = new DomXPath($responseDoc);
137         $xpath->registerNamespace('owncloud', 'http://owncloud.org/ns');
138     
139         $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/owncloud:id');
140         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
141         $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
142     }
143 }