summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2017-11-11 01:27:48 +0100
committerGeorg Ehrke <developer@georgehrke.com>2017-11-11 02:15:57 +0100
commitef6f41a16ce2043cab812887f6ccfe790045ad90 (patch)
treeec99cfa9291ee9a111c0d7af36e399a63dee6f94 /apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php
parentd59b3392abf021d0289b5b2ea1a67bc99e8d89da (diff)
downloadnextcloud-server-ef6f41a16ce2043cab812887f6ccfe790045ad90.tar.gz
nextcloud-server-ef6f41a16ce2043cab812887f6ccfe790045ad90.zip
respect admin / user choice about birthday calendars in corresponding hooks
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php')
-rw-r--r--apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php115
1 files changed, 110 insertions, 5 deletions
diff --git a/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php b/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php
index 72b3c57bea6..867168033a4 100644
--- a/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php
+++ b/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php
@@ -28,6 +28,7 @@ use OCA\DAV\CalDAV\BirthdayService;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\DAV\GroupPrincipalBackend;
+use OCP\IConfig;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Reader;
use Test\TestCase;
@@ -42,15 +43,19 @@ class BirthdayServiceTest extends TestCase {
private $cardDav;
/** @var GroupPrincipalBackend | \PHPUnit_Framework_MockObject_MockObject */
private $groupPrincipalBackend;
+ /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
+ private $config;
public function setUp() {
parent::setUp();
- $this->calDav = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
- $this->cardDav = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
- $this->groupPrincipalBackend = $this->getMockBuilder(GroupPrincipalBackend::class)->disableOriginalConstructor()->getMock();
+ $this->calDav = $this->createMock(CalDavBackend::class);
+ $this->cardDav = $this->createMock(CardDavBackend::class);
+ $this->groupPrincipalBackend = $this->createMock(GroupPrincipalBackend::class);
+ $this->config = $this->createMock(IConfig::class);
- $this->service = new BirthdayService($this->calDav, $this->cardDav, $this->groupPrincipalBackend);
+ $this->service = new BirthdayService($this->calDav, $this->cardDav,
+ $this->groupPrincipalBackend, $this->config);
}
/**
@@ -71,7 +76,52 @@ class BirthdayServiceTest extends TestCase {
}
}
+ public function testOnCardDeleteGloballyDisabled() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('no'));
+
+ $this->cardDav->expects($this->never())->method('getAddressBookById');
+
+ $this->service->onCardDeleted(666, 'gump.vcf');
+ }
+
+ public function testOnCardDeleteUserDisabled() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('yes'));
+
+ $this->config->expects($this->once())
+ ->method('getUserValue')
+ ->with('user01', 'dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('no'));
+
+ $this->cardDav->expects($this->once())->method('getAddressBookById')
+ ->with(666)
+ ->willReturn([
+ 'principaluri' => 'principals/users/user01',
+ 'uri' => 'default'
+ ]);
+ $this->cardDav->expects($this->once())->method('getShares')->willReturn([]);
+ $this->calDav->expects($this->never())->method('getCalendarByUri');
+ $this->calDav->expects($this->never())->method('deleteCalendarObject');
+
+ $this->service->onCardDeleted(666, 'gump.vcf');
+ }
+
public function testOnCardDeleted() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('yes'));
+
+ $this->config->expects($this->once())
+ ->method('getUserValue')
+ ->with('user01', 'dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('yes'));
+
$this->cardDav->expects($this->once())->method('getAddressBookById')
->with(666)
->willReturn([
@@ -91,10 +141,65 @@ class BirthdayServiceTest extends TestCase {
$this->service->onCardDeleted(666, 'gump.vcf');
}
+ public function testOnCardChangedGloballyDisabled() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('no'));
+
+ $this->cardDav->expects($this->never())->method('getAddressBookById');
+
+ $service = $this->getMockBuilder(BirthdayService::class)
+ ->setMethods(['buildDateFromContact', 'birthdayEvenChanged'])
+ ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config])
+ ->getMock();
+
+ $service->onCardChanged(666, 'gump.vcf', '');
+ }
+
+ public function testOnCardChangedUserDisabled() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('yes'));
+
+ $this->config->expects($this->once())
+ ->method('getUserValue')
+ ->with('user01', 'dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('no'));
+
+ $this->cardDav->expects($this->once())->method('getAddressBookById')
+ ->with(666)
+ ->willReturn([
+ 'principaluri' => 'principals/users/user01',
+ 'uri' => 'default'
+ ]);
+ $this->cardDav->expects($this->once())->method('getShares')->willReturn([]);
+ $this->calDav->expects($this->never())->method('getCalendarByUri');
+
+ /** @var BirthdayService | \PHPUnit_Framework_MockObject_MockObject $service */
+ $service = $this->getMockBuilder(BirthdayService::class)
+ ->setMethods(['buildDateFromContact', 'birthdayEvenChanged'])
+ ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config])
+ ->getMock();
+
+ $service->onCardChanged(666, 'gump.vcf', '');
+ }
+
/**
* @dataProvider providesCardChanges
*/
public function testOnCardChanged($expectedOp) {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('yes'));
+
+ $this->config->expects($this->once())
+ ->method('getUserValue')
+ ->with('user01', 'dav', 'generateBirthdayCalendar', 'yes')
+ ->will($this->returnValue('yes'));
+
$this->cardDav->expects($this->once())->method('getAddressBookById')
->with(666)
->willReturn([
@@ -111,7 +216,7 @@ class BirthdayServiceTest extends TestCase {
/** @var BirthdayService | \PHPUnit_Framework_MockObject_MockObject $service */
$service = $this->getMockBuilder(BirthdayService::class)
->setMethods(['buildDateFromContact', 'birthdayEvenChanged'])
- ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend])
+ ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config])
->getMock();
if ($expectedOp === 'delete') {