diff options
author | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-09-30 10:29:27 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-10-14 10:12:43 +0200 |
commit | 5cd90d41162d4d33d397c7c42e86a38168ec87ca (patch) | |
tree | 63f1f83f83a23db82f37ae7e7a0cc379d92c9837 /apps/dav/tests | |
parent | 92c24a91fac434f0de188d3f39d8f6cf1012f527 (diff) | |
download | nextcloud-server-5cd90d41162d4d33d397c7c42e86a38168ec87ca.tar.gz nextcloud-server-5cd90d41162d4d33d397c7c42e86a38168ec87ca.zip |
[9.2] Sync deathdate and anniversary to birthday calendar (#25655)
* Sync deathdate and anniversary to birthday calendar (which should be renamed maybe)
* Sync deathdate and anniversary to birthday calendar (which should be renamed maybe)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php b/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php index 7c772184fef..40a6330ddb8 100644 --- a/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php +++ b/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php @@ -41,16 +41,16 @@ class BirthdayServiceTest extends TestCase { /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject */ private $cardDav; /** @var GroupPrincipalBackend | \PHPUnit_Framework_MockObject_MockObject */ - private $groupPrincialBackend; + private $groupPrincipalBackend; public function setUp() { parent::setUp(); - $this->calDav = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock(); - $this->cardDav = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')->disableOriginalConstructor()->getMock(); - $this->groupPrincialBackend = $this->getMockBuilder('OCA\DAV\DAV\GroupPrincipalBackend')->disableOriginalConstructor()->getMock(); + $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->service = new BirthdayService($this->calDav, $this->cardDav, $this->groupPrincialBackend); + $this->service = new BirthdayService($this->calDav, $this->cardDav, $this->groupPrincipalBackend); } /** @@ -59,7 +59,7 @@ class BirthdayServiceTest extends TestCase { * @param string | null $data */ public function testBuildBirthdayFromContact($nullExpected, $data) { - $cal = $this->service->buildBirthdayFromContact($data); + $cal = $this->service->buildDateFromContact($data, 'BDAY', '*'); if ($nullExpected) { $this->assertNull($cal); } else { @@ -83,7 +83,9 @@ class BirthdayServiceTest extends TestCase { ->willReturn([ 'id' => 1234 ]); - $this->calDav->expects($this->once())->method('deleteCalendarObject')->with(1234, 'default-gump.vcf.ics'); + $this->calDav->expects($this->at(1))->method('deleteCalendarObject')->with(1234, 'default-gump.vcf.ics'); + $this->calDav->expects($this->at(2))->method('deleteCalendarObject')->with(1234, 'default-gump.vcf-death.ics'); + $this->calDav->expects($this->at(3))->method('deleteCalendarObject')->with(1234, 'default-gump.vcf-anniversary.ics'); $this->cardDav->expects($this->once())->method('getShares')->willReturn([]); $this->service->onCardDeleted(666, 'gump.vcf'); @@ -107,26 +109,37 @@ class BirthdayServiceTest extends TestCase { $this->cardDav->expects($this->once())->method('getShares')->willReturn([]); /** @var BirthdayService | \PHPUnit_Framework_MockObject_MockObject $service */ - $service = $this->getMockBuilder('\OCA\DAV\CalDAV\BirthdayService') - ->setMethods(['buildBirthdayFromContact', 'birthdayEvenChanged']) - ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincialBackend]) + $service = $this->getMockBuilder(BirthdayService::class) + ->setMethods(['buildDateFromContact', 'birthdayEvenChanged']) + ->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend]) ->getMock(); if ($expectedOp === 'delete') { - $this->calDav->expects($this->once())->method('getCalendarObject')->willReturn(''); - $service->expects($this->once())->method('buildBirthdayFromContact')->willReturn(null); - $this->calDav->expects($this->once())->method('deleteCalendarObject')->with(1234, 'default-gump.vcf.ics'); + $this->calDav->expects($this->exactly(3))->method('getCalendarObject')->willReturn(''); + $service->expects($this->exactly(3))->method('buildDateFromContact')->willReturn(null); + $this->calDav->expects($this->exactly(3))->method('deleteCalendarObject')->withConsecutive( + [1234, 'default-gump.vcf.ics'], + [1234, 'default-gump.vcf-death.ics'], + [1234, 'default-gump.vcf-anniversary.ics'] + ); } if ($expectedOp === 'create') { - $service->expects($this->once())->method('buildBirthdayFromContact')->willReturn(new VCalendar()); - $this->calDav->expects($this->once())->method('createCalendarObject')->with(1234, 'default-gump.vcf.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 3.5.0//EN\r\nCALSCALE:GREGORIAN\r\nEND:VCALENDAR\r\n"); + $service->expects($this->exactly(3))->method('buildDateFromContact')->willReturn(new VCalendar()); + $this->calDav->expects($this->exactly(3))->method('createCalendarObject')->withConsecutive( + [1234, 'default-gump.vcf.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 3.5.0//EN\r\nCALSCALE:GREGORIAN\r\nEND:VCALENDAR\r\n"], + [1234, 'default-gump.vcf-death.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 3.5.0//EN\r\nCALSCALE:GREGORIAN\r\nEND:VCALENDAR\r\n"], + [1234, 'default-gump.vcf-anniversary.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 3.5.0//EN\r\nCALSCALE:GREGORIAN\r\nEND:VCALENDAR\r\n"] + ); } if ($expectedOp === 'update') { - $service->expects($this->once())->method('buildBirthdayFromContact')->willReturn(new VCalendar()); - $service->expects($this->once())->method('birthdayEvenChanged')->willReturn(true); - $this->calDav->expects($this->once())->method('getCalendarObject')->willReturn([ - 'calendardata' => '']); - $this->calDav->expects($this->once())->method('updateCalendarObject')->with(1234, 'default-gump.vcf.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 3.5.0//EN\r\nCALSCALE:GREGORIAN\r\nEND:VCALENDAR\r\n"); + $service->expects($this->exactly(3))->method('buildDateFromContact')->willReturn(new VCalendar()); + $service->expects($this->exactly(3))->method('birthdayEvenChanged')->willReturn(true); + $this->calDav->expects($this->exactly(3))->method('getCalendarObject')->willReturn(['calendardata' => '']); + $this->calDav->expects($this->exactly(3))->method('updateCalendarObject')->withConsecutive( + [1234, 'default-gump.vcf.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 3.5.0//EN\r\nCALSCALE:GREGORIAN\r\nEND:VCALENDAR\r\n"], + [1234, 'default-gump.vcf-death.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 3.5.0//EN\r\nCALSCALE:GREGORIAN\r\nEND:VCALENDAR\r\n"], + [1234, 'default-gump.vcf-anniversary.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 3.5.0//EN\r\nCALSCALE:GREGORIAN\r\nEND:VCALENDAR\r\n"] + ); } $service->onCardChanged(666, 'gump.vcf', ''); @@ -162,7 +175,7 @@ class BirthdayServiceTest extends TestCase { '{http://owncloud.org/ns}principal' => 'principals/groups/users' ], ]); - $this->groupPrincialBackend->expects($this->once())->method('getGroupMemberSet') + $this->groupPrincipalBackend->expects($this->once())->method('getGroupMemberSet') ->willReturn([ [ 'uri' => 'principals/users/user01', |