summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2017-11-11 11:25:40 +0100
committerGeorg Ehrke <developer@georgehrke.com>2017-11-11 16:17:18 +0100
commit2b51d84b98a5a44c2a42a8498164a35b6822e760 (patch)
tree1a51737c0bdf59b74e1152d27f98fe5f1914263c /apps/dav/tests
parenta87d9860418948a72fbe3d29a2cc5d589be147ec (diff)
downloadnextcloud-server-2b51d84b98a5a44c2a42a8498164a35b6822e760.tar.gz
nextcloud-server-2b51d84b98a5a44c2a42a8498164a35b6822e760.zip
generate birthday calendars in a background job after admin enabled them
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/BackgroundJob/GenerateBirthdayCalendarBackgroundJobTest.php103
-rw-r--r--apps/dav/tests/unit/Controller/BirthdayCalendarControllerTest.php50
2 files changed, 152 insertions, 1 deletions
diff --git a/apps/dav/tests/unit/BackgroundJob/GenerateBirthdayCalendarBackgroundJobTest.php b/apps/dav/tests/unit/BackgroundJob/GenerateBirthdayCalendarBackgroundJobTest.php
new file mode 100644
index 00000000000..010289a745a
--- /dev/null
+++ b/apps/dav/tests/unit/BackgroundJob/GenerateBirthdayCalendarBackgroundJobTest.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017, Georg Ehrke
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\DAV\Tests\unit\BackgroundJob;
+
+use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
+use OCA\DAV\CalDAV\BirthdayService;
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\CalDAV\CalendarHome;
+use OCP\IConfig;
+use Sabre\DAV\MkCol;
+use Test\TestCase;
+
+class GenerateBirthdayCalendarBackgroundJobTest extends TestCase {
+
+ /** @var BirthdayService | \PHPUnit_Framework_MockObject_MockObject */
+ private $birthdayService;
+
+ /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
+ private $config;
+
+ /** @var \OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob */
+ private $backgroundJob;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->birthdayService = $this->createMock(BirthdayService::class);
+ $this->config = $this->createMock(IConfig::class);
+
+ $this->backgroundJob = new GenerateBirthdayCalendarBackgroundJob(
+ $this->birthdayService, $this->config);
+ }
+
+ public function testRun() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('yes'));
+
+ $this->config->expects($this->once())
+ ->method('getUserValue')
+ ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('yes'));
+
+ $this->birthdayService->expects($this->once())
+ ->method('syncUser')
+ ->with('user123');
+
+ $this->backgroundJob->run(['userId' => 'user123']);
+ }
+
+ public function testRunGloballyDisabled() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('no'));
+
+ $this->config->expects($this->never())
+ ->method('getUserValue');
+
+ $this->birthdayService->expects($this->never())
+ ->method('syncUser');
+
+ $this->backgroundJob->run(['userId' => 'user123']);
+ }
+
+ public function testRunUserDisabled() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('yes'));
+
+ $this->config->expects($this->once())
+ ->method('getUserValue')
+ ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('no'));
+
+ $this->birthdayService->expects($this->never())
+ ->method('syncUser');
+
+ $this->backgroundJob->run(['userId' => 'user123']);
+ }
+}
diff --git a/apps/dav/tests/unit/Controller/BirthdayCalendarControllerTest.php b/apps/dav/tests/unit/Controller/BirthdayCalendarControllerTest.php
index 8963546ffee..46ed58df4f9 100644
--- a/apps/dav/tests/unit/Controller/BirthdayCalendarControllerTest.php
+++ b/apps/dav/tests/unit/Controller/BirthdayCalendarControllerTest.php
@@ -23,10 +23,15 @@
namespace OCA\DAV\Tests\Unit\DAV\Controller;
+use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
+use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\Controller\BirthdayCalendarController;
+use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IRequest;
+use OCP\IUser;
+use OCP\IUserManager;
use Test\TestCase;
class BirthdayCalendarControllerTest extends TestCase {
@@ -40,6 +45,15 @@ class BirthdayCalendarControllerTest extends TestCase {
/** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */
private $db;
+ /** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
+ private $jobList;
+
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $userManager;
+
+ /** @var CalDavBackend|\PHPUnit_Framework_MockObject_MockObject */
+ private $caldav;
+
/** @var BirthdayCalendarController|\PHPUnit_Framework_MockObject_MockObject */
private $controller;
@@ -49,9 +63,13 @@ class BirthdayCalendarControllerTest extends TestCase {
$this->config = $this->createMock(IConfig::class);
$this->request = $this->createMock(IRequest::class);
$this->db = $this->createMock(IDBConnection::class);
+ $this->jobList = $this->createMock(IJobList::class);
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->caldav = $this->createMock(CalDavBackend::class);
$this->controller = new BirthdayCalendarController('dav',
- $this->request, $this->db, $this->config);
+ $this->request, $this->db, $this->config, $this->jobList,
+ $this->userManager, $this->caldav);
}
public function testEnable() {
@@ -59,6 +77,31 @@ class BirthdayCalendarControllerTest extends TestCase {
->method('setAppValue')
->with('dav', 'generateBirthdayCalendar', 'yes');
+ $this->userManager->expects($this->once())
+ ->method('callForAllUsers')
+ ->will($this->returnCallback(function($closure) {
+ $user1 = $this->createMock(IUser::class);
+ $user1->method('getUID')->will($this->returnValue('uid1'));
+ $user2 = $this->createMock(IUser::class);
+ $user2->method('getUID')->will($this->returnValue('uid2'));
+ $user3 = $this->createMock(IUser::class);
+ $user3->method('getUID')->will($this->returnValue('uid3'));
+
+ $closure($user1);
+ $closure($user2);
+ $closure($user3);
+ }));
+
+ $this->jobList->expects($this->at(0))
+ ->method('add')
+ ->with(GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid1']);
+ $this->jobList->expects($this->at(1))
+ ->method('add')
+ ->with(GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid2']);
+ $this->jobList->expects($this->at(2))
+ ->method('add')
+ ->with(GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid3']);
+
$response = $this->controller->enable();
$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $response);
}
@@ -67,6 +110,11 @@ class BirthdayCalendarControllerTest extends TestCase {
$this->config->expects($this->once())
->method('setAppValue')
->with('dav', 'generateBirthdayCalendar', 'no');
+ $this->jobList->expects($this->once())
+ ->method('remove')
+ ->with(GenerateBirthdayCalendarBackgroundJob::class);
+ $this->caldav->expects($this->once())
+ ->method('deleteAllBirthdayCalendars');
$response = $this->controller->disable();
$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $response);