fix things (indentation, tests, comments, backend custom implementation

This commit is contained in:
Thomas Citharel 2016-07-31 20:18:35 +02:00 committed by Lukas Reschke
parent ebf23778f5
commit 3921385ed3
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
12 changed files with 281 additions and 206 deletions

View File

@ -46,7 +46,8 @@ $principalBackend = new Principal(
'principals/' 'principals/'
); );
$db = \OC::$server->getDatabaseConnection(); $db = \OC::$server->getDatabaseConnection();
$calDavBackend = new CalDavBackend($db, $principalBackend, \OC::$server->getUserManager()); $config = \OC::$server->getConfig();
$calDavBackend = new CalDavBackend($db, $principalBackend, \OC::$server->getUserManager(), $config);
$debugging = \OC::$server->getConfig()->getSystemValue('debug', false); $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);

View File

@ -37,8 +37,87 @@ class Application extends App {
/** /**
* Application constructor. * Application constructor.
*/ */
public function __construct() { public function __construct (array $urlParams=array()) {
parent::__construct('dav'); parent::__construct('dav', $urlParams);
$container = $this->getContainer();
$container->registerService('ContactsManager', function($c) {
/** @var IAppContainer $c */
return new ContactsManager(
$c->query('CardDavBackend')
);
});
$container->registerService('HookManager', function($c) {
/** @var IAppContainer $c */
return new HookManager(
$c->getServer()->getUserManager(),
$c->query('SyncService'),
$c->query('CalDavBackend'),
$c->query('CardDavBackend')
);
});
$container->registerService('SyncService', function($c) {
/** @var IAppContainer $c */
return new SyncService(
$c->query('CardDavBackend'),
$c->getServer()->getUserManager(),
$c->getServer()->getLogger()
);
});
$container->registerService('CardDavBackend', function($c) {
/** @var IAppContainer $c */
$db = $c->getServer()->getDatabaseConnection();
$dispatcher = $c->getServer()->getEventDispatcher();
$principal = new Principal(
$c->getServer()->getUserManager(),
$c->getServer()->getGroupManager()
);
return new CardDavBackend($db, $principal, $c->getServer()->getUserManager(), $dispatcher);
});
$container->registerService('CalDavBackend', function($c) {
/** @var IAppContainer $c */
$db = $c->getServer()->getDatabaseConnection();
$config = $c->getServer()->getConfig();
$principal = new Principal(
$c->getServer()->getUserManager(),
$c->getServer()->getGroupManager()
);
return new CalDavBackend($db, $principal, $c->getServer()->getUserManager(), $config);
});
$container->registerService('BirthdayService', function($c) {
/** @var IAppContainer $c */
$g = new GroupPrincipalBackend(
$c->getServer()->getGroupManager()
);
return new BirthdayService(
$c->query('CalDavBackend'),
$c->query('CardDavBackend'),
$g
);
});
$container->registerService('OCA\DAV\Migration\Classification', function ($c) {
/** @var IAppContainer $c */
return new Classification(
$c->query('CalDavBackend'),
$c->getServer()->getUserManager()
);
});
$container->registerService('OCA\DAV\Migration\GenerateBirthdays', function ($c) {
/** @var IAppContainer $c */
/** @var BirthdayService $b */
$b = $c->query('BirthdayService');
return new GenerateBirthdays(
$b,
$c->getServer()->getUserManager()
);
});
} }
/** /**

View File

@ -29,6 +29,7 @@ use OCA\DAV\DAV\Sharing\IShareable;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCA\DAV\Connector\Sabre\Principal; use OCA\DAV\Connector\Sabre\Principal;
use OCA\DAV\DAV\Sharing\Backend; use OCA\DAV\DAV\Sharing\Backend;
use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
@ -119,7 +120,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
/** @var IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var \OCP\IConfig */ /** @var IConfig */
private $config; private $config;
/** /**
@ -128,14 +129,14 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @param IDBConnection $db * @param IDBConnection $db
* @param Principal $principalBackend * @param Principal $principalBackend
* @param IUserManager $userManager * @param IUserManager $userManager
* @param IConfig $config
*/ */
public function __construct(IDBConnection $db, Principal $principalBackend, IUserManager $userManager) { public function __construct(IDBConnection $db, Principal $principalBackend, IUserManager $userManager, IConfig $config) {
$this->db = $db; $this->db = $db;
$this->principalBackend = $principalBackend; $this->principalBackend = $principalBackend;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar');
// TODO: inject $this->config = $config;
$this->config = \OC::$server->getConfig();
} }
/** /**
@ -1533,26 +1534,26 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
} }
/** /**
* @param boolean $value * @param boolean $value
* @param \OCA\DAV\CalDAV\Calendar $calendar * @param \OCA\DAV\CalDAV\Calendar $calendar
*/ */
public function setPublishStatus($value, $calendar) { public function setPublishStatus($value, $calendar) {
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
if ($value) { if ($value) {
$query->insert('dav_shares') $query->insert('dav_shares')
->values([ ->values([
'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()),
'type' => $query->createNamedParameter('calendar'), 'type' => $query->createNamedParameter('calendar'),
'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC),
'resourceid' => $query->createNamedParameter($calendar->getResourceId()) 'resourceid' => $query->createNamedParameter($calendar->getResourceId())
]); ]);
} else { } else {
$query->delete('dav_shares') $query->delete('dav_shares')
->Where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId())))
->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC)));
} }
$query->execute(); $query->execute();
} }
/** /**
* @param \OCA\DAV\CalDAV\Calendar $calendar * @param \OCA\DAV\CalDAV\Calendar $calendar

View File

@ -21,14 +21,19 @@
namespace OCA\DAV\CalDAV; namespace OCA\DAV\CalDAV;
use Sabre\DAV\Collection; use Sabre\DAV\Collection;
use Sabre\DAV\Exception\NotFound;
class PublicCalendarRoot extends Collection { class PublicCalendarRoot extends Collection {
/** @var CalDavBackend */ /** @var CalDavBackend */
protected $caldavBackend; protected $caldavBackend;
/** @var \OCP\IL10N */
protected $l10n;
function __construct(CalDavBackend $caldavBackend) { function __construct(CalDavBackend $caldavBackend) {
$this->caldavBackend = $caldavBackend; $this->caldavBackend = $caldavBackend;
$this->l10n = \OC::$server->getL10N('dav');
} }
/** /**
@ -38,21 +43,28 @@ class PublicCalendarRoot extends Collection {
return 'public-calendars'; return 'public-calendars';
} }
/**
* @inheritdoc
*/
function getChild($name) { function getChild($name) {
// TODO: for performance reason this needs to have a custom implementation foreach ($this->caldavBackend->getPublicCalendars() as $calendar) {
return parent::getChild($name); if ($calendar['uri'] === $name) {
// TODO: maybe implement a new class PublicCalendar ???
return new Calendar($this->caldavBackend, $calendar, $this->l10n);
}
}
throw new NotFound('Node with name \'' . $name . '\' could not be found');
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
function getChildren() { function getChildren() {
$l10n = \OC::$server->getL10N('dav');
$calendars = $this->caldavBackend->getPublicCalendars(); $calendars = $this->caldavBackend->getPublicCalendars();
$children = []; $children = [];
foreach ($calendars as $calendar) { foreach ($calendars as $calendar) {
// TODO: maybe implement a new class PublicCalendar ??? // TODO: maybe implement a new class PublicCalendar ???
$children[] = new Calendar($this->caldavBackend, $calendar, $l10n); $children[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
} }
return $children; return $children;

View File

@ -16,9 +16,9 @@ use OCP\IConfig;
class PublishPlugin extends ServerPlugin class PublishPlugin extends ServerPlugin
{ {
const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
/** /**
* Reference to SabreDAV server object. * Reference to SabreDAV server object.
* *
* @var \Sabre\DAV\Server * @var \Sabre\DAV\Server
@ -28,29 +28,30 @@ class PublishPlugin extends ServerPlugin
/** /**
* Config instance to get instance secret. * Config instance to get instance secret.
* *
* @var OCP\IConfig * @var IConfig
*/ */
protected $config; protected $config;
/** /**
* URL Generator for absolute URLs. * URL Generator for absolute URLs.
* *
* @var OCP\IURLGenerator * @var IURLGenerator
*/ */
protected $urlGenerator; protected $urlGenerator;
/** /**
* PublishPlugin constructor. * PublishPlugin constructor.
* *
* @param IURLGenerator $urlGenerator * @param IConfig $config
*/ * @param IURLGenerator $urlGenerator
*/
public function __construct(IConfig $config, IURLGenerator $urlGenerator) public function __construct(IConfig $config, IURLGenerator $urlGenerator)
{ {
$this->config = $config; $this->config = $config;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
} }
/** /**
* This method should return a list of server-features. * This method should return a list of server-features.
* *
* This is for example 'versioning' and is added to the DAV: header * This is for example 'versioning' and is added to the DAV: header
@ -58,7 +59,7 @@ class PublishPlugin extends ServerPlugin
* *
* @return string[] * @return string[]
*/ */
public function getFeatures() public function getFeatures()
{ {
return ['oc-calendar-publishing']; // May have to be changed to be detected return ['oc-calendar-publishing']; // May have to be changed to be detected
} }
@ -92,10 +93,9 @@ class PublishPlugin extends ServerPlugin
$this->server->on('method:POST', [$this, 'httpPost']); $this->server->on('method:POST', [$this, 'httpPost']);
$this->server->on('propFind', [$this, 'propFind']); $this->server->on('propFind', [$this, 'propFind']);
// $this->server->on('method:OPTIONS', [$this, 'httpOptions'], 5);
} }
public function propFind(PropFind $propFind, INode $node) public function propFind(PropFind $propFind, INode $node)
{ {
if ($node instanceof Calendar) { if ($node instanceof Calendar) {
$token = md5($this->config->getSystemValue('secret', '').$node->getResourceId()); $token = md5($this->config->getSystemValue('secret', '').$node->getResourceId());
@ -104,130 +104,113 @@ class PublishPlugin extends ServerPlugin
$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node, $publishUrl) { $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node, $publishUrl) {
if ($node->getPublishStatus()) { if ($node->getPublishStatus()) {
return new Publisher($publishUrl, true); // We return the publish-url only if the calendar is published. // We return the publish-url only if the calendar is published.
return new Publisher($publishUrl, true);
} }
}); });
$propFind->handle('{'.self::NS_CALENDARSERVER.'}pre-publish-url', function () use ($node, $publishUrl) { $propFind->handle('{'.self::NS_CALENDARSERVER.'}pre-publish-url', function () use ($node, $publishUrl) {
return new Publisher($publishUrl, false); // The pre-publish-url is always returned // The pre-publish-url is always returned
return new Publisher($publishUrl, false);
}); });
} }
} }
/** /**
* We intercept this to handle POST requests on calendars. * We intercept this to handle POST requests on calendars.
* *
* @param RequestInterface $request * @param RequestInterface $request
* @param ResponseInterface $response * @param ResponseInterface $response
* *
* @return null|bool * @return null|bool
*/ */
public function httpPost(RequestInterface $request, ResponseInterface $response) public function httpPost(RequestInterface $request, ResponseInterface $response)
{ {
$path = $request->getPath(); $path = $request->getPath();
// Only handling xml // Only handling xml
$contentType = $request->getHeader('Content-Type'); $contentType = $request->getHeader('Content-Type');
if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
return; return;
} }
// Making sure the node exists // Making sure the node exists
try { try {
$node = $this->server->tree->getNodeForPath($path); $node = $this->server->tree->getNodeForPath($path);
} catch (NotFound $e) { } catch (NotFound $e) {
return; return;
} }
$requestBody = $request->getBodyAsString(); $requestBody = $request->getBodyAsString();
// If this request handler could not deal with this POST request, it // If this request handler could not deal with this POST request, it
// will return 'null' and other plugins get a chance to handle the // will return 'null' and other plugins get a chance to handle the
// request. // request.
// //
// However, we already requested the full body. This is a problem, // However, we already requested the full body. This is a problem,
// because a body can only be read once. This is why we preemptively // because a body can only be read once. This is why we preemptively
// re-populated the request body with the existing data. // re-populated the request body with the existing data.
$request->setBody($requestBody); $request->setBody($requestBody);
$message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
switch ($documentType) { switch ($documentType) {
case '{'.self::NS_CALENDARSERVER.'}publish-calendar' : case '{'.self::NS_CALENDARSERVER.'}publish-calendar' :
// We can only deal with IShareableCalendar objects // We can only deal with IShareableCalendar objects
if (!$node instanceof Calendar) { if (!$node instanceof Calendar) {
return; return;
} }
$this->server->transactionType = 'post-publish-calendar'; $this->server->transactionType = 'post-publish-calendar';
// Getting ACL info // Getting ACL info
$acl = $this->server->getPlugin('acl'); $acl = $this->server->getPlugin('acl');
// If there's no ACL support, we allow everything // If there's no ACL support, we allow everything
if ($acl) { if ($acl) {
$acl->checkPrivileges($path, '{DAV:}write'); $acl->checkPrivileges($path, '{DAV:}write');
} }
$node->setPublishStatus(true); $node->setPublishStatus(true);
// iCloud sends back the 202, so we will too. // iCloud sends back the 202, so we will too.
$response->setStatus(202); $response->setStatus(202);
// Adding this because sending a response body may cause issues, // Adding this because sending a response body may cause issues,
// and I wanted some type of indicator the response was handled. // and I wanted some type of indicator the response was handled.
$response->setHeader('X-Sabre-Status', 'everything-went-well'); $response->setHeader('X-Sabre-Status', 'everything-went-well');
// Breaking the event chain // Breaking the event chain
return false; return false;
case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' :
// We can only deal with IShareableCalendar objects // We can only deal with IShareableCalendar objects
if (!$node instanceof Calendar) { if (!$node instanceof Calendar) {
return; return;
} }
$this->server->transactionType = 'post-unpublish-calendar'; $this->server->transactionType = 'post-unpublish-calendar';
// Getting ACL info // Getting ACL info
$acl = $this->server->getPlugin('acl'); $acl = $this->server->getPlugin('acl');
// If there's no ACL support, we allow everything // If there's no ACL support, we allow everything
if ($acl) { if ($acl) {
$acl->checkPrivileges($path, '{DAV:}write'); $acl->checkPrivileges($path, '{DAV:}write');
} }
$node->setPublishStatus(false); $node->setPublishStatus(false);
$response->setStatus(200); $response->setStatus(200);
// Adding this because sending a response body may cause issues, // Adding this because sending a response body may cause issues,
// and I wanted some type of indicator the response was handled. // and I wanted some type of indicator the response was handled.
$response->setHeader('X-Sabre-Status', 'everything-went-well'); $response->setHeader('X-Sabre-Status', 'everything-went-well');
// Breaking the event chain // Breaking the event chain
return false; return false;
} }
} }
public function httpOptions(RequestInterface $request, ResponseInterface $response) {
if ($request->getPath() == 'public-calendars') {
$methods = $this->server->getAllowedMethods($request->getPath());
$response->setHeader('Allow', strtoupper(implode(', ', $methods)));
$features = ['1', '3', 'extended-mkcol'];
$response->setHeader('DAV', implode(', ', $features));
$response->setHeader('MS-Author-Via', 'DAV');
$response->setHeader('Accept-Ranges', 'bytes');
$response->setHeader('Content-Length', '0');
$response->setStatus(200);
// Sending back false will interupt the event chain and tell the server
// we've handled this method.
return false;
}
}
} }

View File

@ -8,57 +8,58 @@ use Sabre\Xml\XmlSerializable;
class Publisher implements XmlSerializable { class Publisher implements XmlSerializable {
/** /**
* @var string $publishUrl * @var string $publishUrl
*/ */
protected $publishUrl; protected $publishUrl;
/** /**
* @var boolean $isPublished * @var boolean $isPublished
*/ */
protected $isPublished; protected $isPublished;
/** /**
* @param string $publishUrl * @param string $publishUrl
* @param boolean $isPublished * @param boolean $isPublished
*/ */
function __construct($publishUrl, $isPublished) { function __construct($publishUrl, $isPublished) {
$this->publishUrl = $publishUrl; $this->publishUrl = $publishUrl;
$this->isPublished = $isPublished; $this->isPublished = $isPublished;
} }
/** /**
* @return string * @return string
*/ */
function getValue() { function getValue() {
return $this->publishUrl; return $this->publishUrl;
} }
/** /**
* The xmlSerialize metod is called during xml writing. * The xmlSerialize metod is called during xml writing.
* *
* Use the $writer argument to write its own xml serialization. * Use the $writer argument to write its own xml serialization.
* *
* An important note: do _not_ create a parent element. Any element * An important note: do _not_ create a parent element. Any element
* implementing XmlSerializble should only ever write what's considered * implementing XmlSerializble should only ever write what's considered
* its 'inner xml'. * its 'inner xml'.
* *
* The parent of the current element is responsible for writing a * The parent of the current element is responsible for writing a
* containing element. * containing element.
* *
* This allows serializers to be re-used for different element names. * This allows serializers to be re-used for different element names.
* *
* If you are opening new elements, you must also close them again. * If you are opening new elements, you must also close them again.
* *
* @param Writer $writer * @param Writer $writer
* @return void * @return void
*/ */
function xmlSerialize(Writer $writer) { function xmlSerialize(Writer $writer) {
if (!$this->isPublished) { if (!$this->isPublished) {
$writer->write($this->publishUrl); // for pre-publish-url // for pre-publish-url
} else { $writer->write($this->publishUrl);
$writer->writeElement('{DAV:}href', $this->publishUrl); // for publish-url } else {
} // for publish-url
$writer->writeElement('{DAV:}href', $this->publishUrl);
} }
}
} }

View File

@ -44,6 +44,7 @@ class CreateCalendar extends Command {
/** /**
* @param IUserManager $userManager * @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IDBConnection $dbConnection * @param IDBConnection $dbConnection
*/ */
function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) { function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
@ -74,9 +75,10 @@ class CreateCalendar extends Command {
$this->userManager, $this->userManager,
$this->groupManager $this->groupManager
); );
$config = \OC::$server->getConfig();
$name = $input->getArgument('name'); $name = $input->getArgument('name');
$caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager); $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $config);
$caldav->createCalendar("principals/users/$user", $name, []); $caldav->createCalendar("principals/users/$user", $name, []);
} }
} }

View File

@ -244,10 +244,6 @@ class FilesPlugin extends ServerPlugin {
* @param ResponseInterface $response * @param ResponseInterface $response
*/ */
function httpGet(RequestInterface $request, ResponseInterface $response) { function httpGet(RequestInterface $request, ResponseInterface $response) {
// Exclude published calendars
// TODO : Find a better way to do this
if (explode('/', $request->getPath())[0] === 'public-calendars') return;
// Only handle valid files // Only handle valid files
$node = $this->tree->getNodeForPath($request->getPath()); $node = $this->tree->getNodeForPath($request->getPath());
if (!($node instanceof IFile)) return; if (!($node instanceof IFile)) return;

View File

@ -60,7 +60,7 @@ class RootCollection extends SimpleCollection {
$systemPrincipals->disableListing = $disableListing; $systemPrincipals->disableListing = $disableListing;
$filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
$filesCollection->disableListing = $disableListing; $filesCollection->disableListing = $disableListing;
$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager()); $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $config);
$calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
$calendarRoot->disableListing = $disableListing; $calendarRoot->disableListing = $disableListing;
$publicCalendarRoot = new PublicCalendarRoot($caldavBackend); $publicCalendarRoot = new PublicCalendarRoot($caldavBackend);

View File

@ -75,7 +75,8 @@ abstract class AbstractCalDavBackendTest extends TestCase {
->willReturn([self::UNIT_TEST_GROUP]); ->willReturn([self::UNIT_TEST_GROUP]);
$db = \OC::$server->getDatabaseConnection(); $db = \OC::$server->getDatabaseConnection();
$this->backend = new CalDavBackend($db, $this->principal, $this->userManager); $config = \OC::$server->getConfig();
$this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $config);
$this->tearDown(); $this->tearDown();
} }

View File

@ -4,7 +4,6 @@ namespace OCA\DAV\Tests\unit\CalDAV\Publishing;
use OCA\DAV\CalDAV\Calendar; use OCA\DAV\CalDAV\Calendar;
use OCA\DAV\CalDAV\Publishing\PublishPlugin; use OCA\DAV\CalDAV\Publishing\PublishPlugin;
use OCA\DAV\Connector\Sabre\Auth;
use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IConfig; use OCP\IConfig;
@ -30,16 +29,16 @@ class PluginTest extends TestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
/** @var Auth | \PHPUnit_Framework_MockObject_MockObject $authBackend */ $this->config = $this->getMockBuilder('\OCP\IConfig')->
$authBackend = $this->getMockBuilder('OCA\DAV\DAV\PublicAuth')->disableOriginalConstructor()->getMock(); disableOriginalConstructor()->
$authBackend->method('isDavAuthenticated')->willReturn(true); getMock();
$this->config = $this->getMock('\OCP\IConfig');
$this->config->expects($this->any())->method('getSystemValue') $this->config->expects($this->any())->method('getSystemValue')
->with($this->equalTo('secret')) ->with($this->equalTo('secret'))
->willReturn('mysecret'); ->willReturn('mysecret');
$this->urlGenerator = $this->getMock('OCP\IURLGenerator'); $this->urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')->
disableOriginalConstructor()->
getMock();
/** @var IRequest $request */ /** @var IRequest $request */
$this->plugin = new PublishPlugin($this->config, $this->urlGenerator); $this->plugin = new PublishPlugin($this->config, $this->urlGenerator);
@ -48,8 +47,8 @@ class PluginTest extends TestCase {
$this->server = new Server($root); $this->server = new Server($root);
/** @var SimpleCollection $node */ /** @var SimpleCollection $node */
$this->book = $this->getMockBuilder('OCA\DAV\CalDAV\Calendar')-> $this->book = $this->getMockBuilder('OCA\DAV\CalDAV\Calendar')->
disableOriginalConstructor()-> disableOriginalConstructor()->
getMock(); getMock();
$this->book->method('getName')->willReturn('cal1'); $this->book->method('getName')->willReturn('cal1');
$root->addChild($this->book); $root->addChild($this->book);
$this->plugin->initialize($this->server); $this->plugin->initialize($this->server);

View File

@ -471,7 +471,7 @@ class FilesPluginTest extends TestCase {
$node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Node') $node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Node')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$node->expects($this->at(0)) $node->expects($this->once())
->method('getFileInfo') ->method('getFileInfo')
->willReturn($fileInfoFolderATestTXT); ->willReturn($fileInfoFolderATestTXT);
@ -545,7 +545,7 @@ class FilesPluginTest extends TestCase {
->getMock(); ->getMock();
$request $request
->expects($this->at(1)) ->expects($this->once())
->method('getPath') ->method('getPath')
->will($this->returnValue('test/somefile.xml')); ->will($this->returnValue('test/somefile.xml'));