0011428: support caldav sync token
[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      * test getPluginName method
47      */
48     public function testGetPluginName()
49     {
50         $pluginName = $this->plugin->getPluginName();
51         
52         $this->assertEquals('Tinebase_WebDav_Plugin_OwnCloud', $pluginName);
53     }
54     
55     /**
56      * test testGetProperties method
57      */
58     public function testGetProperties()
59     {
60         $body = '<?xml version="1.0" encoding="utf-8"?>
61                  <propfind xmlns="DAV:">
62                     <prop>
63                         <getlastmodified xmlns="DAV:"/>
64                         <getcontentlength xmlns="DAV:"/>
65                         <resourcetype xmlns="DAV:"/>
66                         <getetag xmlns="DAV:"/>
67                         <id xmlns="http://owncloud.org/ns"/>
68                     </prop>
69                  </propfind>';
70
71         $request = new Sabre\HTTP\Request(array(
72             'REQUEST_METHOD' => 'PROPFIND',
73             'REQUEST_URI'    => '/remote.php/webdav/' . Tinebase_Core::getUser()->accountDisplayName,
74             'HTTP_DEPTH'     => '0',
75         ));
76         $request->setBody($body);
77
78         $this->server->httpRequest = $request;
79         $this->server->exec();
80         //var_dump($this->response->body);
81         $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
82         
83         $responseDoc = new DOMDocument();
84         $responseDoc->loadXML($this->response->body);
85         //$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
86         $xpath = new DomXPath($responseDoc);
87         $xpath->registerNamespace('owncloud', 'http://owncloud.org/ns');
88         
89         $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/owncloud:id');
90         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
91         $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
92     }
93 }