Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1819187
PluginTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Size
3 KB
Subscribers
None
PluginTest.php
View Options
<?php
namespace
Sabre\DAV\Auth
;
use
Sabre\HTTP
;
use
Sabre\DAV
;
require_once
'Sabre/HTTP/ResponseMock.php'
;
class
PluginTest
extends
\PHPUnit_Framework_TestCase
{
function
testInit
()
{
$fakeServer
=
new
DAV\Server
(
new
DAV\SimpleCollection
(
'bla'
));
$plugin
=
new
Plugin
(
new
Backend\Mock
(),
'realm'
);
$this
->
assertTrue
(
$plugin
instanceof
Plugin
);
$fakeServer
->
addPlugin
(
$plugin
);
$this
->
assertEquals
(
$plugin
,
$fakeServer
->
getPlugin
(
'auth'
));
$this
->
assertInternalType
(
'array'
,
$plugin
->
getPluginInfo
());
}
/**
* @depends testInit
*/
function
testAuthenticate
()
{
$fakeServer
=
new
DAV\Server
(
new
DAV\SimpleCollection
(
'bla'
));
$plugin
=
new
Plugin
(
new
Backend\Mock
());
$fakeServer
->
addPlugin
(
$plugin
);
$this
->
assertTrue
(
$fakeServer
->
emit
(
'beforeMethod'
,
[
new
HTTP\Request
(),
new
HTTP\Response
()])
);
}
/**
* @depends testInit
* @expectedException Sabre\DAV\Exception\NotAuthenticated
*/
function
testAuthenticateFail
()
{
$fakeServer
=
new
DAV\Server
(
new
DAV\SimpleCollection
(
'bla'
));
$backend
=
new
Backend\Mock
();
$backend
->
fail
=
true
;
$plugin
=
new
Plugin
(
$backend
);
$fakeServer
->
addPlugin
(
$plugin
);
$fakeServer
->
emit
(
'beforeMethod'
,
[
new
HTTP\Request
(),
new
HTTP\Response
()]);
}
/**
* @depends testAuthenticate
*/
function
testMultipleBackend
()
{
$fakeServer
=
new
DAV\Server
(
new
DAV\SimpleCollection
(
'bla'
));
$backend1
=
new
Backend\Mock
();
$backend2
=
new
Backend\Mock
();
$backend2
->
fail
=
true
;
$plugin
=
new
Plugin
();
$plugin
->
addBackend
(
$backend1
);
$plugin
->
addBackend
(
$backend2
);
$fakeServer
->
addPlugin
(
$plugin
);
$fakeServer
->
emit
(
'beforeMethod'
,
[
new
HTTP\Request
(),
new
HTTP\Response
()]);
$this
->
assertEquals
(
'principals/admin'
,
$plugin
->
getCurrentPrincipal
());
}
/**
* @depends testInit
* @expectedException Sabre\DAV\Exception
*/
function
testNoAuthBackend
()
{
$fakeServer
=
new
DAV\Server
(
new
DAV\SimpleCollection
(
'bla'
));
$plugin
=
new
Plugin
();
$fakeServer
->
addPlugin
(
$plugin
);
$fakeServer
->
emit
(
'beforeMethod'
,
[
new
HTTP\Request
(),
new
HTTP\Response
()]);
}
/**
* @depends testInit
* @expectedException Sabre\DAV\Exception
*/
function
testInvalidCheckResponse
()
{
$fakeServer
=
new
DAV\Server
(
new
DAV\SimpleCollection
(
'bla'
));
$backend
=
new
Backend\Mock
();
$backend
->
invalidCheckResponse
=
true
;
$plugin
=
new
Plugin
(
$backend
);
$fakeServer
->
addPlugin
(
$plugin
);
$fakeServer
->
emit
(
'beforeMethod'
,
[
new
HTTP\Request
(),
new
HTTP\Response
()]);
}
/**
* @depends testAuthenticate
*/
function
testGetCurrentPrincipal
()
{
$fakeServer
=
new
DAV\Server
(
new
DAV\SimpleCollection
(
'bla'
));
$plugin
=
new
Plugin
(
new
Backend\Mock
());
$fakeServer
->
addPlugin
(
$plugin
);
$fakeServer
->
emit
(
'beforeMethod'
,
[
new
HTTP\Request
(),
new
HTTP\Response
()]);
$this
->
assertEquals
(
'principals/admin'
,
$plugin
->
getCurrentPrincipal
());
}
/**
* @depends testAuthenticate
*/
function
testGetCurrentUser
()
{
$fakeServer
=
new
DAV\Server
(
new
DAV\SimpleCollection
(
'bla'
));
$plugin
=
new
Plugin
(
new
Backend\Mock
());
$fakeServer
->
addPlugin
(
$plugin
);
$fakeServer
->
emit
(
'beforeMethod'
,
[
new
HTTP\Request
(),
new
HTTP\Response
()]);
$this
->
assertEquals
(
'admin'
,
$plugin
->
getCurrentUser
());
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Dec 21, 10:38 AM (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
914500
Default Alt Text
PluginTest.php (3 KB)
Attached To
rDAVCAL DokuWiki DAVCal PlugIn
Event Timeline
Log In to Comment