]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix things (indentation, tests, comments, backend custom implementation
authorThomas Citharel <tcit@tcit.fr>
Sun, 31 Jul 2016 18:18:35 +0000 (20:18 +0200)
committerLukas Reschke <lukas@statuscode.ch>
Mon, 26 Sep 2016 09:55:39 +0000 (11:55 +0200)
12 files changed:
apps/dav/appinfo/v1/caldav.php
apps/dav/lib/AppInfo/Application.php
apps/dav/lib/CalDAV/CalDavBackend.php
apps/dav/lib/CalDAV/PublicCalendarRoot.php
apps/dav/lib/CalDAV/Publishing/PublishPlugin.php
apps/dav/lib/CalDAV/Publishing/Xml/Publisher.php
apps/dav/lib/Command/CreateCalendar.php
apps/dav/lib/Connector/Sabre/FilesPlugin.php
apps/dav/lib/RootCollection.php
apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php
apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php

index 13b4d3119ca9166fd17c52075519df69fc6baef8..d9606f20b727117a90a51c7a9c299c23aeda1c6f 100644 (file)
@@ -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);
 
index dc3ce7e8bb2b4c3168b16248658b25b127e729b6..8bc43da56492f40389404bb45314fd0e405fa03b 100644 (file)
@@ -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()
+                       );
+               });
        }
 
        /**
index 7075ccc460def2a7e1f144c75fb58c0a6c21912a..cdab20f541efee8dde790a8c6b40cddbc382a06b 100644 (file)
@@ -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
index f1ff23ac7e221d1e02e36ed8ff0c251237a57deb..797074f7e56737b2815a5046456672af197f5922 100644 (file)
 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;
index 4e82d166fc06d432e52b40efbf9f71d46b9fbb65..e0bcfb7ef6aa56476602d4092f36a16a9678d034 100644 (file)
@@ -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;
-        }
-    }
+               }
+       }
 }
index 45a7fe0257b444cf1a513984d615335c72b4ee77..375954ffaf3bf4a58a0236fdfaf8a79697bd3d20 100644 (file)
@@ -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);
+               }
+       }
 }
index 0bc6398250e1025f55ef85336ee818cff650b90c..54cb06db6664fec2ecc345e5b9739182552ffe04 100644 (file)
@@ -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, []);
        }
 }
index 7da49e13130bf8ed000cb0e283581fcc6ff89945..dd5f958ed4c37de552aeb871d917238bd10a03cf 100644 (file)
@@ -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;
index f7b9c7079a0d68153c8b6c321134345e9cdff146..f99d5850212cbcba461430f899eedff7808f1427 100644 (file)
@@ -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);
index 0e2e1b0ee511c0adc08cad5739d29e8fa1044704..ebdd4d9f940bbf32bfd48efdeec15493a4b90a5a 100644 (file)
@@ -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();
        }
index b3ff36fc4ed92f0b75082721f1d5a5136a39d2f1..69de507dac57fe708b1afef019fdeda5e6990f14 100644 (file)
@@ -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);
index 07a55fef63b7d72d5681f009636e3f105e8e4c30..e2d63868af054c3f6057fd0f296c80e3444c5ce8 100644 (file)
@@ -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'));