From 3921385ed3994c26674ec31606a41899fa8648ee Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 31 Jul 2016 20:18:35 +0200 Subject: [PATCH] fix things (indentation, tests, comments, backend custom implementation --- apps/dav/appinfo/v1/caldav.php | 3 +- apps/dav/lib/AppInfo/Application.php | 83 +++++++- apps/dav/lib/CalDAV/CalDavBackend.php | 49 ++--- apps/dav/lib/CalDAV/PublicCalendarRoot.php | 20 +- .../lib/CalDAV/Publishing/PublishPlugin.php | 199 ++++++++---------- .../lib/CalDAV/Publishing/Xml/Publisher.php | 99 ++++----- apps/dav/lib/Command/CreateCalendar.php | 4 +- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 4 - apps/dav/lib/RootCollection.php | 2 +- .../unit/CalDAV/AbstractCalDavBackendTest.php | 3 +- .../unit/CalDAV/Publishing/PublishingTest.php | 17 +- .../unit/Connector/Sabre/FilesPluginTest.php | 4 +- 12 files changed, 281 insertions(+), 206 deletions(-) diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index 13b4d3119c..d9606f20b7 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -46,7 +46,8 @@ $principalBackend = new Principal( 'principals/' ); $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); diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php index dc3ce7e8bb..8bc43da564 100644 --- a/apps/dav/lib/AppInfo/Application.php +++ b/apps/dav/lib/AppInfo/Application.php @@ -37,8 +37,87 @@ class Application extends App { /** * Application constructor. */ - public function __construct() { - parent::__construct('dav'); + public function __construct (array $urlParams=array()) { + 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() + ); + }); } /** diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 7075ccc460..cdab20f541 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -29,6 +29,7 @@ use OCA\DAV\DAV\Sharing\IShareable; use OCP\DB\QueryBuilder\IQueryBuilder; use OCA\DAV\Connector\Sabre\Principal; use OCA\DAV\DAV\Sharing\Backend; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IUser; use OCP\IUserManager; @@ -119,7 +120,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription /** @var IUserManager */ private $userManager; - /** @var \OCP\IConfig */ + /** @var IConfig */ private $config; /** @@ -128,14 +129,14 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param IDBConnection $db * @param Principal $principalBackend * @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->principalBackend = $principalBackend; $this->userManager = $userManager; $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); - // TODO: inject - $this->config = \OC::$server->getConfig(); + $this->config = $config; } /** @@ -1533,26 +1534,26 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } /** - * @param boolean $value - * @param \OCA\DAV\CalDAV\Calendar $calendar - */ - public function setPublishStatus($value, $calendar) { - $query = $this->db->getQueryBuilder(); - if ($value) { - $query->insert('dav_shares') - ->values([ - 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), - 'type' => $query->createNamedParameter('calendar'), - 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), - 'resourceid' => $query->createNamedParameter($calendar->getResourceId()) - ]); - } else { - $query->delete('dav_shares') - ->Where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); - } - $query->execute(); - } + * @param boolean $value + * @param \OCA\DAV\CalDAV\Calendar $calendar + */ + public function setPublishStatus($value, $calendar) { + $query = $this->db->getQueryBuilder(); + if ($value) { + $query->insert('dav_shares') + ->values([ + 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), + 'type' => $query->createNamedParameter('calendar'), + 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), + 'resourceid' => $query->createNamedParameter($calendar->getResourceId()) + ]); + } else { + $query->delete('dav_shares') + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); + } + $query->execute(); + } /** * @param \OCA\DAV\CalDAV\Calendar $calendar diff --git a/apps/dav/lib/CalDAV/PublicCalendarRoot.php b/apps/dav/lib/CalDAV/PublicCalendarRoot.php index f1ff23ac7e..797074f7e5 100644 --- a/apps/dav/lib/CalDAV/PublicCalendarRoot.php +++ b/apps/dav/lib/CalDAV/PublicCalendarRoot.php @@ -21,14 +21,19 @@ namespace OCA\DAV\CalDAV; use Sabre\DAV\Collection; +use Sabre\DAV\Exception\NotFound; class PublicCalendarRoot extends Collection { /** @var CalDavBackend */ protected $caldavBackend; + /** @var \OCP\IL10N */ + protected $l10n; + function __construct(CalDavBackend $caldavBackend) { $this->caldavBackend = $caldavBackend; + $this->l10n = \OC::$server->getL10N('dav'); } /** @@ -38,21 +43,28 @@ class PublicCalendarRoot extends Collection { return 'public-calendars'; } + /** + * @inheritdoc + */ function getChild($name) { - // TODO: for performance reason this needs to have a custom implementation - return parent::getChild($name); + foreach ($this->caldavBackend->getPublicCalendars() as $calendar) { + 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 */ function getChildren() { - $l10n = \OC::$server->getL10N('dav'); $calendars = $this->caldavBackend->getPublicCalendars(); $children = []; foreach ($calendars as $calendar) { // TODO: maybe implement a new class PublicCalendar ??? - $children[] = new Calendar($this->caldavBackend, $calendar, $l10n); + $children[] = new Calendar($this->caldavBackend, $calendar, $this->l10n); } return $children; diff --git a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php index 4e82d166fc..e0bcfb7ef6 100644 --- a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php +++ b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php @@ -16,9 +16,9 @@ use OCP\IConfig; class PublishPlugin extends ServerPlugin { - const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; + const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; - /** + /** * Reference to SabreDAV server object. * * @var \Sabre\DAV\Server @@ -28,29 +28,30 @@ class PublishPlugin extends ServerPlugin /** * Config instance to get instance secret. * - * @var OCP\IConfig + * @var IConfig */ protected $config; /** * URL Generator for absolute URLs. * - * @var OCP\IURLGenerator + * @var IURLGenerator */ protected $urlGenerator; - /** - * PublishPlugin constructor. - * - * @param IURLGenerator $urlGenerator - */ + /** + * PublishPlugin constructor. + * + * @param IConfig $config + * @param IURLGenerator $urlGenerator + */ public function __construct(IConfig $config, IURLGenerator $urlGenerator) { $this->config = $config; $this->urlGenerator = $urlGenerator; } - /** + /** * This method should return a list of server-features. * * This is for example 'versioning' and is added to the DAV: header @@ -58,7 +59,7 @@ class PublishPlugin extends ServerPlugin * * @return string[] */ - public function getFeatures() + public function getFeatures() { 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('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) { $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) { 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) { - 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. - * - * @param RequestInterface $request - * @param ResponseInterface $response - * - * @return null|bool - */ - public function httpPost(RequestInterface $request, ResponseInterface $response) - { - $path = $request->getPath(); + /** + * We intercept this to handle POST requests on calendars. + * + * @param RequestInterface $request + * @param ResponseInterface $response + * + * @return null|bool + */ + public function httpPost(RequestInterface $request, ResponseInterface $response) + { + $path = $request->getPath(); - // Only handling xml - $contentType = $request->getHeader('Content-Type'); - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { - return; - } + // Only handling xml + $contentType = $request->getHeader('Content-Type'); + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { + return; + } - // Making sure the node exists - try { - $node = $this->server->tree->getNodeForPath($path); - } catch (NotFound $e) { - return; - } + // Making sure the node exists + try { + $node = $this->server->tree->getNodeForPath($path); + } catch (NotFound $e) { + return; + } - $requestBody = $request->getBodyAsString(); + $requestBody = $request->getBodyAsString(); - // If this request handler could not deal with this POST request, it - // will return 'null' and other plugins get a chance to handle the - // request. - // - // However, we already requested the full body. This is a problem, - // because a body can only be read once. This is why we preemptively - // re-populated the request body with the existing data. - $request->setBody($requestBody); + // If this request handler could not deal with this POST request, it + // will return 'null' and other plugins get a chance to handle the + // request. + // + // However, we already requested the full body. This is a problem, + // because a body can only be read once. This is why we preemptively + // re-populated the request body with the existing data. + $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 - if (!$node instanceof Calendar) { - return; - } - $this->server->transactionType = 'post-publish-calendar'; + // We can only deal with IShareableCalendar objects + if (!$node instanceof Calendar) { + return; + } + $this->server->transactionType = 'post-publish-calendar'; - // Getting ACL info - $acl = $this->server->getPlugin('acl'); + // Getting ACL info + $acl = $this->server->getPlugin('acl'); - // If there's no ACL support, we allow everything - if ($acl) { - $acl->checkPrivileges($path, '{DAV:}write'); - } + // If there's no ACL support, we allow everything + if ($acl) { + $acl->checkPrivileges($path, '{DAV:}write'); + } - $node->setPublishStatus(true); + $node->setPublishStatus(true); - // iCloud sends back the 202, so we will too. - $response->setStatus(202); + // iCloud sends back the 202, so we will too. + $response->setStatus(202); - // Adding this because sending a response body may cause issues, - // and I wanted some type of indicator the response was handled. - $response->setHeader('X-Sabre-Status', 'everything-went-well'); + // Adding this because sending a response body may cause issues, + // and I wanted some type of indicator the response was handled. + $response->setHeader('X-Sabre-Status', 'everything-went-well'); - // Breaking the event chain - return false; + // Breaking the event chain + return false; - case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : + case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : - // We can only deal with IShareableCalendar objects - if (!$node instanceof Calendar) { - return; - } - $this->server->transactionType = 'post-unpublish-calendar'; + // We can only deal with IShareableCalendar objects + if (!$node instanceof Calendar) { + return; + } + $this->server->transactionType = 'post-unpublish-calendar'; - // Getting ACL info - $acl = $this->server->getPlugin('acl'); + // Getting ACL info + $acl = $this->server->getPlugin('acl'); - // If there's no ACL support, we allow everything - if ($acl) { - $acl->checkPrivileges($path, '{DAV:}write'); - } + // If there's no ACL support, we allow everything + if ($acl) { + $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, - // and I wanted some type of indicator the response was handled. - $response->setHeader('X-Sabre-Status', 'everything-went-well'); + // Adding this because sending a response body may cause issues, + // and I wanted some type of indicator the response was handled. + $response->setHeader('X-Sabre-Status', 'everything-went-well'); - // Breaking the event chain - return false; + // Breaking the event chain + 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; - } - } + } + } } diff --git a/apps/dav/lib/CalDAV/Publishing/Xml/Publisher.php b/apps/dav/lib/CalDAV/Publishing/Xml/Publisher.php index 45a7fe0257..375954ffaf 100644 --- a/apps/dav/lib/CalDAV/Publishing/Xml/Publisher.php +++ b/apps/dav/lib/CalDAV/Publishing/Xml/Publisher.php @@ -8,57 +8,58 @@ use Sabre\Xml\XmlSerializable; class Publisher implements XmlSerializable { - /** - * @var string $publishUrl - */ - protected $publishUrl; + /** + * @var string $publishUrl + */ + protected $publishUrl; - /** - * @var boolean $isPublished - */ - protected $isPublished; + /** + * @var boolean $isPublished + */ + protected $isPublished; - /** - * @param string $publishUrl - * @param boolean $isPublished - */ - function __construct($publishUrl, $isPublished) { - $this->publishUrl = $publishUrl; - $this->isPublished = $isPublished; - } + /** + * @param string $publishUrl + * @param boolean $isPublished + */ + function __construct($publishUrl, $isPublished) { + $this->publishUrl = $publishUrl; + $this->isPublished = $isPublished; + } - /** - * @return string - */ - function getValue() { - return $this->publishUrl; - } + /** + * @return string + */ + function getValue() { + return $this->publishUrl; + } - /** - * The xmlSerialize metod is called during xml writing. - * - * Use the $writer argument to write its own xml serialization. - * - * An important note: do _not_ create a parent element. Any element - * implementing XmlSerializble should only ever write what's considered - * its 'inner xml'. - * - * The parent of the current element is responsible for writing a - * containing element. - * - * This allows serializers to be re-used for different element names. - * - * If you are opening new elements, you must also close them again. - * - * @param Writer $writer - * @return void - */ - function xmlSerialize(Writer $writer) { - if (!$this->isPublished) { - $writer->write($this->publishUrl); // for pre-publish-url - } else { - $writer->writeElement('{DAV:}href', $this->publishUrl); // for publish-url - } - - } + /** + * The xmlSerialize metod is called during xml writing. + * + * Use the $writer argument to write its own xml serialization. + * + * An important note: do _not_ create a parent element. Any element + * implementing XmlSerializble should only ever write what's considered + * its 'inner xml'. + * + * The parent of the current element is responsible for writing a + * containing element. + * + * This allows serializers to be re-used for different element names. + * + * If you are opening new elements, you must also close them again. + * + * @param Writer $writer + * @return void + */ + function xmlSerialize(Writer $writer) { + if (!$this->isPublished) { + // for pre-publish-url + $writer->write($this->publishUrl); + } else { + // for publish-url + $writer->writeElement('{DAV:}href', $this->publishUrl); + } + } } diff --git a/apps/dav/lib/Command/CreateCalendar.php b/apps/dav/lib/Command/CreateCalendar.php index 0bc6398250..54cb06db66 100644 --- a/apps/dav/lib/Command/CreateCalendar.php +++ b/apps/dav/lib/Command/CreateCalendar.php @@ -44,6 +44,7 @@ class CreateCalendar extends Command { /** * @param IUserManager $userManager + * @param IGroupManager $groupManager * @param IDBConnection $dbConnection */ function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) { @@ -74,9 +75,10 @@ class CreateCalendar extends Command { $this->userManager, $this->groupManager ); + $config = \OC::$server->getConfig(); $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, []); } } diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 7da49e1313..dd5f958ed4 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -244,10 +244,6 @@ class FilesPlugin extends ServerPlugin { * @param 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 $node = $this->tree->getNodeForPath($request->getPath()); if (!($node instanceof IFile)) return; diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php index f7b9c7079a..f99d585021 100644 --- a/apps/dav/lib/RootCollection.php +++ b/apps/dav/lib/RootCollection.php @@ -60,7 +60,7 @@ class RootCollection extends SimpleCollection { $systemPrincipals->disableListing = $disableListing; $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); $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->disableListing = $disableListing; $publicCalendarRoot = new PublicCalendarRoot($caldavBackend); diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php index 0e2e1b0ee5..ebdd4d9f94 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php @@ -75,7 +75,8 @@ abstract class AbstractCalDavBackendTest extends TestCase { ->willReturn([self::UNIT_TEST_GROUP]); $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(); } diff --git a/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php b/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php index b3ff36fc4e..69de507dac 100644 --- a/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php +++ b/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php @@ -4,7 +4,6 @@ namespace OCA\DAV\Tests\unit\CalDAV\Publishing; use OCA\DAV\CalDAV\Calendar; use OCA\DAV\CalDAV\Publishing\PublishPlugin; -use OCA\DAV\Connector\Sabre\Auth; use OCP\IRequest; use OCP\IURLGenerator; use OCP\IConfig; @@ -30,16 +29,16 @@ class PluginTest extends TestCase { public function setUp() { parent::setUp(); - /** @var Auth | \PHPUnit_Framework_MockObject_MockObject $authBackend */ - $authBackend = $this->getMockBuilder('OCA\DAV\DAV\PublicAuth')->disableOriginalConstructor()->getMock(); - $authBackend->method('isDavAuthenticated')->willReturn(true); - - $this->config = $this->getMock('\OCP\IConfig'); + $this->config = $this->getMockBuilder('\OCP\IConfig')-> + disableOriginalConstructor()-> + getMock(); $this->config->expects($this->any())->method('getSystemValue') ->with($this->equalTo('secret')) ->willReturn('mysecret'); - $this->urlGenerator = $this->getMock('OCP\IURLGenerator'); + $this->urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')-> + disableOriginalConstructor()-> + getMock(); /** @var IRequest $request */ $this->plugin = new PublishPlugin($this->config, $this->urlGenerator); @@ -48,8 +47,8 @@ class PluginTest extends TestCase { $this->server = new Server($root); /** @var SimpleCollection $node */ $this->book = $this->getMockBuilder('OCA\DAV\CalDAV\Calendar')-> - disableOriginalConstructor()-> - getMock(); + disableOriginalConstructor()-> + getMock(); $this->book->method('getName')->willReturn('cal1'); $root->addChild($this->book); $this->plugin->initialize($this->server); diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php index 07a55fef63..e2d63868af 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php @@ -471,7 +471,7 @@ class FilesPluginTest extends TestCase { $node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Node') ->disableOriginalConstructor() ->getMock(); - $node->expects($this->at(0)) + $node->expects($this->once()) ->method('getFileInfo') ->willReturn($fileInfoFolderATestTXT); @@ -545,7 +545,7 @@ class FilesPluginTest extends TestCase { ->getMock(); $request - ->expects($this->at(1)) + ->expects($this->once()) ->method('getPath') ->will($this->returnValue('test/somefile.xml'));