3 require_once 'Sabre/DAV/Auth/MockBackend.php';
4 require_once 'Sabre/HTTP/ResponseMock.php';
6 class Sabre_DAV_Auth_PluginTest extends PHPUnit_Framework_TestCase {
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'));
21 function testAuthenticate() {
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','/'));
34 * @expectedException Sabre_DAV_Exception_NotAuthenticated
36 function testAuthenticateFail() {
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','/'));
45 function testReportPassThrough() {
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);
51 $request = new Sabre_HTTP_Request(array(
52 'REQUEST_METHOD' => 'REPORT',
53 'HTTP_CONTENT_TYPE' => 'application/xml',
56 $request->setBody('<?xml version="1.0"?><s:somereport xmlns:s="http://www.rooftopsolutions.nl/NS/example" />');
58 $fakeServer->httpRequest = $request;
59 $fakeServer->httpResponse = new Sabre_HTTP_ResponseMock();
62 $this->assertEquals('HTTP/1.1 501 Not Implemented', $fakeServer->httpResponse->status);
69 function testGetCurrentUserPrincipal() {
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());