]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/Auth/PluginTest.php
e89f4c5a16fffe30f96be76884f9fc8d75613cde
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / Auth / PluginTest.php
1 <?php
2
3 require_once 'Sabre/DAV/Auth/MockBackend.php';
4 require_once 'Sabre/HTTP/ResponseMock.php';
5
6 class Sabre_DAV_Auth_PluginTest extends PHPUnit_Framework_TestCase {
7
8     function testInit() {
9
10         $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla')));
11         $plugin = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(),'realm');
12         $this->assertTrue($plugin instanceof Sabre_DAV_Auth_Plugin);
13         $fakeServer->addPlugin($plugin);
14         $this->assertEquals($plugin, $fakeServer->getPlugin('auth'));
15
16     }
17
18     /**
19      * @depends testInit
20      */
21     function testAuthenticate() {
22
23         $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla')));
24         $plugin = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(),'realm');
25         $fakeServer->addPlugin($plugin);
26         $fakeServer->broadCastEvent('beforeMethod',array('GET','/'));
27
28     }
29
30
31
32     /**
33      * @depends testInit
34      * @expectedException Sabre_DAV_Exception_NotAuthenticated
35      */
36     function testAuthenticateFail() {
37
38         $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla')));
39         $plugin = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(),'failme');
40         $fakeServer->addPlugin($plugin);
41         $fakeServer->broadCastEvent('beforeMethod',array('GET','/'));
42
43     }
44
45     function testReportPassThrough() {
46
47         $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla')));
48         $plugin = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(),'realm');
49         $fakeServer->addPlugin($plugin);
50
51         $request = new Sabre_HTTP_Request(array(
52             'REQUEST_METHOD' => 'REPORT',
53             'HTTP_CONTENT_TYPE' => 'application/xml',
54             'REQUEST_URI' => '/',
55         ));
56         $request->setBody('<?xml version="1.0"?><s:somereport xmlns:s="http://www.rooftopsolutions.nl/NS/example" />');
57
58         $fakeServer->httpRequest = $request;
59         $fakeServer->httpResponse = new Sabre_HTTP_ResponseMock();
60         $fakeServer->exec();
61
62         $this->assertEquals('HTTP/1.1 501 Not Implemented', $fakeServer->httpResponse->status);
63
64     }
65
66     /**
67      * @depends testInit
68      */
69     function testGetCurrentUserPrincipal() {
70
71         $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla')));
72         $plugin = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(),'realm');
73         $fakeServer->addPlugin($plugin);
74         $fakeServer->broadCastEvent('beforeMethod',array('GET','/'));
75         $this->assertEquals('admin', $plugin->getCurrentUser());
76
77     }
78
79 }
80