summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-10-13 11:04:22 +0200
committerJoas Schilling <coding@schilljs.com>2016-11-03 12:07:58 +0100
commit07f6747305d23dfb16ad3c63b968f974771aa145 (patch)
tree70011903c7b4eec212260d4af5795034907e0ba9 /apps/dav/tests
parent776622f3de8fab30add0c83bf0331c57615467df (diff)
downloadnextcloud-server-07f6747305d23dfb16ad3c63b968f974771aa145.tar.gz
nextcloud-server-07f6747305d23dfb16ad3c63b968f974771aa145.zip
Move the methods into a new class
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php40
-rw-r--r--apps/dav/tests/unit/CalDAV/CalDavBackendTest.php4
-rw-r--r--apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php57
3 files changed, 67 insertions, 34 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
index 2559ecbbf89..a674c65c286 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
@@ -22,18 +22,15 @@
namespace OCA\DAV\Tests\unit\CalDAV;
-use DateTime;
-use DateTimeZone;
+use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
use OCA\DAV\CalDAV\CalDavBackend;
-use OCA\DAV\CalDAV\Calendar;
use OCA\DAV\Connector\Sabre\Principal;
-use OCP\IL10N;
-use OCP\IConfig;
+use OCP\Activity\IManager as IActivityManager;
+use OCP\IGroupManager;
+use OCP\IUserManager;
+use OCP\IUserSession;
use OCP\Security\ISecureRandom;
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
-use Sabre\DAV\PropPatch;
-use Sabre\DAV\Xml\Property\Href;
-use Sabre\DAVACL\IACL;
use Test\TestCase;
/**
@@ -50,12 +47,10 @@ abstract class AbstractCalDavBackendTest extends TestCase {
/** @var Principal | \PHPUnit_Framework_MockObject_MockObject */
protected $principal;
-
- /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
protected $userManager;
-
- /** var OCP\IConfig */
- protected $config;
+ /** @var ActivityBackend|\PHPUnit_Framework_MockObject_MockObject */
+ protected $activityBackend;
/** @var ISecureRandom */
private $random;
@@ -67,9 +62,10 @@ abstract class AbstractCalDavBackendTest extends TestCase {
public function setUp() {
parent::setUp();
- $this->userManager = $this->getMockBuilder('OCP\IUserManager')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->userManager = $this->createMock(IUserManager::class);
+ $groupManager = $this->createMock(IGroupManager::class);
+ $activityManager = $this->createMock(IActivityManager::class);
+ $userSession = $this->createMock(IUserSession::class);
$this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
->disableOriginalConstructor()
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
@@ -83,15 +79,21 @@ abstract class AbstractCalDavBackendTest extends TestCase {
->willReturn([self::UNIT_TEST_GROUP]);
$db = \OC::$server->getDatabaseConnection();
- $this->config = \OC::$server->getConfig();
$this->random = \OC::$server->getSecureRandom();
- $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->config, $this->random);
- $this->tearDown();
+ $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $groupManager, $this->random, $activityManager, $userSession);
+
+ $this->activityBackend = $this->createMock(ActivityBackend::class);
+ $this->invokePrivate($this->backend, 'activityBackend', [$this->activityBackend]);
+
+ $this->cleanUpBackend();
}
public function tearDown() {
+ $this->cleanUpBackend();
parent::tearDown();
+ }
+ public function cleanUpBackend() {
if (is_null($this->backend)) {
return;
}
diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
index 8349d98cd94..4d60e983b13 100644
--- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
@@ -357,10 +357,8 @@ EOD;
$calendar->setPublishStatus(false);
$this->assertEquals(false, $calendar->getPublishStatus());
- $publicCalendarURI = md5($this->config->getSystemValue('secret', '') . $calendar->getResourceId());
$this->setExpectedException('Sabre\DAV\Exception\NotFound');
- $publicCalendar = $this->backend->getPublicCalendar($publicCalendarURI);
-
+ $this->backend->getPublicCalendar($publicCalendarURI);
}
public function testSubscriptions() {
diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
index 6dfec6d7e1f..c3a3d783e18 100644
--- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
+++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
@@ -2,12 +2,16 @@
namespace OCA\DAV\Tests\unit\CalDAV;
+use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
use OCA\DAV\CalDAV\Calendar;
use OCA\DAV\Connector\Sabre\Principal;
+use OCP\Activity\IManager as IActivityManager;
+use OCP\IGroupManager;
use OCP\IL10N;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\PublicCalendarRoot;
use OCP\IUserManager;
+use OCP\IUserSession;
use OCP\Security\ISecureRandom;
use Test\TestCase;
@@ -27,12 +31,19 @@ class PublicCalendarRootTest extends TestCase {
private $publicCalendarRoot;
/** @var IL10N */
private $l10n;
- /** @var IUserManager */
- private $userManager;
- /** @var Principal */
+ /** @var Principal|\PHPUnit_Framework_MockObject_MockObject */
private $principal;
- /** var IConfig */
- protected $config;
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $userManager;
+ /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $groupManager;
+ /** @var IActivityManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $activityManager;
+ /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
+ protected $userSession;
+ /** @var ActivityBackend|\PHPUnit_Framework_MockObject_MockObject */
+ protected $activityBackend;
+
/** @var ISecureRandom */
private $random;
@@ -40,21 +51,26 @@ class PublicCalendarRootTest extends TestCase {
parent::setUp();
$db = \OC::$server->getDatabaseConnection();
- $this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
- ->disableOriginalConstructor()
- ->getMock();
- $this->config = \OC::$server->getConfig();
- $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock();
+ $this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal');
+ $this->userManager = $this->createMock(IUserManager::class);
+ $groupManager = $this->createMock(IGroupManager::class);
+ $activityManager = $this->createMock(IActivityManager::class);
+ $userSession = $this->createMock(IUserSession::class);
$this->random = \OC::$server->getSecureRandom();
$this->backend = new CalDavBackend(
$db,
$this->principal,
$this->userManager,
- $this->config,
- $this->random
+ $groupManager,
+ $this->random,
+ $activityManager,
+ $userSession
);
+ $this->activityBackend = $this->createMock(ActivityBackend::class);
+ $this->invokePrivate($this->backend, 'activityBackend', [$this->activityBackend]);
+
$this->publicCalendarRoot = new PublicCalendarRoot($this->backend);
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
@@ -79,6 +95,14 @@ class PublicCalendarRootTest extends TestCase {
}
public function testGetChild() {
+ $this->activityBackend->expects($this->exactly(1))
+ ->method('addCalendar');
+ $this->activityBackend->expects($this->never())
+ ->method('updateCalendar');
+ $this->activityBackend->expects($this->never())
+ ->method('deleteCalendar');
+ $this->activityBackend->expects($this->never())
+ ->method('updateCalendarShares');
$calendar = $this->createPublicCalendar();
@@ -93,6 +117,15 @@ class PublicCalendarRootTest extends TestCase {
}
public function testGetChildren() {
+ $this->activityBackend->expects($this->exactly(1))
+ ->method('addCalendar');
+ $this->activityBackend->expects($this->never())
+ ->method('updateCalendar');
+ $this->activityBackend->expects($this->never())
+ ->method('deleteCalendar');
+ $this->activityBackend->expects($this->never())
+ ->method('updateCalendarShares');
+
$this->createPublicCalendar();
$publicCalendars = $this->backend->getPublicCalendars();