a887099e293b456f6dea5113a562949994ef0f87
[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-2014 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
17 /**
18  * Test class for Tinebase_WebDav_Plugin_OwnCloud
19  */
20 class Tinebase_WebDav_Plugin_OwnCloudTest extends TestCase
21 {
22     /**
23      * 
24      * @var Sabre\DAV\Server
25      */
26     protected $server;
27     
28     /**
29      * Runs the test methods of this class.
30      *
31      * @access public
32      * @static
33      */
34     public static function main()
35     {
36         $suite  = new PHPUnit_Framework_TestSuite('Tine 2.0 Plugin OwnCloud Tests');
37         PHPUnit_TextUI_TestRunner::run($suite);
38     }
39
40     /**
41      * Sets up the fixture.
42      * This method is called before a test is executed.
43      *
44      * @access protected
45      */
46     protected function setUp()
47     {
48         parent::setUp();
49         
50         $this->server = new Sabre\DAV\Server(new Tinebase_WebDav_Root());
51         
52         $this->plugin = new Tinebase_WebDav_Plugin_OwnCloud();
53         
54         $this->server->addPlugin($this->plugin);
55         
56         $this->response = new Sabre\HTTP\ResponseMock();
57         $this->server->httpResponse = $this->response;
58     }
59
60     /**
61      * test getPluginName method
62      */
63     public function testGetPluginName()
64     {
65         $pluginName = $this->plugin->getPluginName();
66         
67         $this->assertEquals('Tinebase_WebDav_Plugin_OwnCloud', $pluginName);
68     }
69     
70     /**
71      * test testGetProperties method
72      */
73     public function testGetProperties()
74     {
75         $body = '<?xml version="1.0" encoding="utf-8"?>
76                  <propfind xmlns="DAV:">
77                     <prop>
78                         <getlastmodified xmlns="DAV:"/>
79                         <getcontentlength xmlns="DAV:"/>
80                         <resourcetype xmlns="DAV:"/>
81                         <getetag xmlns="DAV:"/>
82                         <id xmlns="http://owncloud.org/ns"/>
83                     </prop>
84                  </propfind>';
85
86         $request = new Sabre\HTTP\Request(array(
87             'REQUEST_METHOD' => 'PROPFIND',
88             'REQUEST_URI'    => '/remote.php/webdav/' . Tinebase_Core::getUser()->accountDisplayName,
89             'HTTP_DEPTH'     => '0',
90         ));
91         $request->setBody($body);
92
93         $this->server->httpRequest = $request;
94         $this->server->exec();
95         //var_dump($this->response->body);
96         $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
97         
98         $responseDoc = new DOMDocument();
99         $responseDoc->loadXML($this->response->body);
100         //$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
101         $xpath = new DomXPath($responseDoc);
102         $xpath->registerNamespace('owncloud', 'http://owncloud.org/ns');
103         
104         $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/owncloud:id');
105         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
106         $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
107     }
108 }