diff options
Diffstat (limited to 'apps/dav/tests/unit/CalDAV')
7 files changed, 233 insertions, 15 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php index 3f3b744e5ab..eef69aadf40 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php @@ -66,7 +66,7 @@ abstract class AbstractCalDavBackend extends TestCase { $this->userManager = $this->createMock(IUserManager::class); $this->groupManager = $this->createMock(IGroupManager::class); $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - $this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal') + $this->principal = $this->getMockBuilder(Principal::class) ->disableOriginalConstructor() ->setMethods(['getPrincipalByPath', 'getGroupMembership']) ->getMock(); diff --git a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php index d8d15e8f1f7..dd48d8172d3 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php @@ -108,11 +108,13 @@ class BackendTest extends TestCase { [Calendar::SUBJECT_ADD, [ 'principaluri' => 'principal/user/admin', 'id' => 42, + 'uri' => 'this-uri', '{DAV:}displayname' => 'Name of calendar', ], [], [], '', 'admin', null, ['admin']], [Calendar::SUBJECT_ADD, [ 'principaluri' => 'principal/user/admin', 'id' => 42, + 'uri' => 'this-uri', '{DAV:}displayname' => 'Name of calendar', ], [], [], 'test2', 'test2', null, ['admin']], @@ -122,17 +124,20 @@ class BackendTest extends TestCase { [Calendar::SUBJECT_UPDATE, [ 'principaluri' => 'principal/user/admin', 'id' => 42, + 'uri' => 'this-uri', '{DAV:}displayname' => 'Name of calendar', ], ['shares'], [], '', 'admin', null, ['admin']], // Visible change [Calendar::SUBJECT_UPDATE, [ 'principaluri' => 'principal/user/admin', 'id' => 42, + 'uri' => 'this-uri', '{DAV:}displayname' => 'Name of calendar', ], ['shares'], ['{DAV:}displayname' => 'Name'], '', 'admin', ['user1'], ['user1', 'admin']], [Calendar::SUBJECT_UPDATE, [ 'principaluri' => 'principal/user/admin', 'id' => 42, + 'uri' => 'this-uri', '{DAV:}displayname' => 'Name of calendar', ], ['shares'], ['{DAV:}displayname' => 'Name'], 'test2', 'test2', ['user1'], ['user1', 'admin']], @@ -141,16 +146,19 @@ class BackendTest extends TestCase { [Calendar::SUBJECT_DELETE, [ 'principaluri' => 'principal/user/admin', 'id' => 42, + 'uri' => 'this-uri', '{DAV:}displayname' => 'Name of calendar', ], ['shares'], [], '', 'admin', [], ['admin']], [Calendar::SUBJECT_DELETE, [ 'principaluri' => 'principal/user/admin', 'id' => 42, + 'uri' => 'this-uri', '{DAV:}displayname' => 'Name of calendar', ], ['shares'], [], '', 'admin', ['user1'], ['user1', 'admin']], [Calendar::SUBJECT_DELETE, [ 'principaluri' => 'principal/user/admin', 'id' => 42, + 'uri' => 'this-uri', '{DAV:}displayname' => 'Name of calendar', ], ['shares'], [], 'test2', 'test2', ['user1'], ['user1', 'admin']], ]; diff --git a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php index 85eb439f100..adffaf27ded 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php @@ -24,6 +24,7 @@ namespace OCA\DAV\Tests\unit\CalDAV\Activity\Provider; use OCA\DAV\CalDAV\Activity\Provider\Base; use OCP\Activity\IEvent; use OCP\Activity\IProvider; +use OCP\IL10N; use OCP\IUser; use OCP\IUserManager; use Test\TestCase; @@ -113,22 +114,51 @@ class BaseTest extends TestCase { public function dataGenerateCalendarParameter() { return [ + [['id' => 23, 'uri' => 'foo', 'name' => 'bar'], 'bar'], + [['id' => 42, 'uri' => 'foo', 'name' => 'Personal'], 'Personal'], + [['id' => 42, 'uri' => 'personal', 'name' => 'bar'], 'bar'], + [['id' => 42, 'uri' => 'personal', 'name' => 'Personal'], 't(Personal)'], + ]; + } + + /** + * @dataProvider dataGenerateCalendarParameter + * @param array $data + * @param string $name + */ + public function testGenerateCalendarParameter(array $data, $name) { + $l = $this->createMock(IL10N::class); + $l->expects($this->any()) + ->method('t') + ->willReturnCallback(function($string, $args) { + return 't(' . vsprintf($string, $args) . ')'; + }); + + $this->assertEquals([ + 'type' => 'calendar', + 'id' => $data['id'], + 'name' => $name, + ], $this->invokePrivate($this->provider, 'generateCalendarParameter', [$data, $l])); + } + + public function dataGenerateLegacyCalendarParameter() { + return [ [23, 'c1'], [42, 'c2'], ]; } /** - * @dataProvider dataGenerateCalendarParameter + * @dataProvider dataGenerateLegacyCalendarParameter * @param int $id * @param string $name */ - public function testGenerateCalendarParameter($id, $name) { + public function testGenerateLegacyCalendarParameter($id, $name) { $this->assertEquals([ 'type' => 'calendar', 'id' => $id, 'name' => $name, - ], $this->invokePrivate($this->provider, 'generateCalendarParameter', [$id, $name])); + ], $this->invokePrivate($this->provider, 'generateLegacyCalendarParameter', [$id, $name])); } public function dataGenerateGroupParameter() { diff --git a/apps/dav/tests/unit/CalDAV/CalendarTest.php b/apps/dav/tests/unit/CalDAV/CalendarTest.php index d9ea25b268c..3fb29fd0c6b 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarTest.php @@ -38,7 +38,7 @@ class CalendarTest extends TestCase { public function setUp() { parent::setUp(); - $this->l10n = $this->getMockBuilder('\OCP\IL10N') + $this->l10n = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor()->getMock(); $this->l10n ->expects($this->any()) @@ -381,4 +381,184 @@ EOD; [2, true] ]; } + + public function testRemoveVAlarms() { + $publicObjectData = <<<EOD +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Nextcloud calendar v1.5.6 +CALSCALE:GREGORIAN +BEGIN:VEVENT +CREATED:20171022T125130 +DTSTAMP:20171022T125130 +LAST-MODIFIED:20171022T125130 +UID:PPL24TH8UGOWE94XET87ER +SUMMARY:Foo bar blub +CLASS:PUBLIC +STATUS:CONFIRMED +DTSTART;VALUE=DATE:20171024 +DTEND;VALUE=DATE:20171025 +BEGIN:VALARM +ACTION:AUDIO +TRIGGER:-PT15M +END:VALARM +END:VEVENT +END:VCALENDAR + +EOD; + + $confidentialObjectData = <<<EOD +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Nextcloud calendar v1.5.6 +CALSCALE:GREGORIAN +BEGIN:VEVENT +CREATED:20171022T125130 +DTSTAMP:20171022T125130 +LAST-MODIFIED:20171022T125130 +UID:PPL24TH8UGOWE94XET87ER +SUMMARY:Foo bar blub +CLASS:CONFIDENTIAL +STATUS:CONFIRMED +DTSTART;VALUE=DATE:20171024 +DTEND;VALUE=DATE:20171025 +BEGIN:VALARM +ACTION:AUDIO +TRIGGER:-PT15M +END:VALARM +END:VEVENT +END:VCALENDAR + +EOD; + + $publicObjectDataWithoutVAlarm = <<<EOD +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Nextcloud calendar v1.5.6 +CALSCALE:GREGORIAN +BEGIN:VEVENT +CREATED:20171022T125130 +DTSTAMP:20171022T125130 +LAST-MODIFIED:20171022T125130 +UID:PPL24TH8UGOWE94XET87ER +SUMMARY:Foo bar blub +CLASS:PUBLIC +STATUS:CONFIRMED +DTSTART;VALUE=DATE:20171024 +DTEND;VALUE=DATE:20171025 +END:VEVENT +END:VCALENDAR + +EOD; + + $confidentialObjectCleaned = <<<EOD +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Nextcloud calendar v1.5.6 +CALSCALE:GREGORIAN +BEGIN:VEVENT +CREATED:20171022T125130 +UID:PPL24TH8UGOWE94XET87ER +SUMMARY:Busy +CLASS:CONFIDENTIAL +DTSTART;VALUE=DATE:20171024 +DTEND;VALUE=DATE:20171025 +END:VEVENT +END:VCALENDAR + +EOD; + + + + $publicObject = ['uri' => 'event-0', + 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC, + 'calendardata' => $publicObjectData]; + + $confidentialObject = ['uri' => 'event-1', + 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, + 'calendardata' => $confidentialObjectData]; + + /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ + $backend = $this->createMock(CalDavBackend::class); + $backend->expects($this->any()) + ->method('getCalendarObjects') + ->willReturn([$publicObject, $confidentialObject]); + + $backend->expects($this->any()) + ->method('getMultipleCalendarObjects') + ->with(666, ['event-0', 'event-1']) + ->willReturn([$publicObject, $confidentialObject]); + + $backend->expects($this->any()) + ->method('getCalendarObject') + ->will($this->returnCallback(function($cId, $uri) use($publicObject, $confidentialObject) { + switch($uri) { + case 'event-0': + return $publicObject; + + case 'event-1': + return $confidentialObject; + + default: + throw new \Exception('unexpected uri'); + } + })); + + $backend->expects($this->any()) + ->method('applyShareAcl') + ->willReturnArgument(1); + + $calendarInfoOwner = [ + '{http://owncloud.org/ns}owner-principal' => 'user1', + 'principaluri' => 'user1', + 'id' => 666, + 'uri' => 'cal', + ]; + $calendarInfoSharedRW = [ + '{http://owncloud.org/ns}owner-principal' => 'user1', + 'principaluri' => 'user2', + 'id' => 666, + 'uri' => 'cal', + ]; + $calendarInfoSharedRO = [ + '{http://owncloud.org/ns}owner-principal' => 'user1', + '{http://owncloud.org/ns}read-only' => true, + 'principaluri' => 'user2', + 'id' => 666, + 'uri' => 'cal', + ]; + + $ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n); + $rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n); + $roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n); + + $this->assertEquals(count($ownerCalendar->getChildren()), 2); + $this->assertEquals(count($rwCalendar->getChildren()), 2); + $this->assertEquals(count($roCalendar->getChildren()), 2); + + // calendar data shall not be altered for the owner + $this->assertEquals($ownerCalendar->getChild('event-0')->get(), $publicObjectData); + $this->assertEquals($ownerCalendar->getChild('event-1')->get(), $confidentialObjectData); + + // valarms shall not be removed for read-write shares + $this->assertEquals( + $this->fixLinebreak($rwCalendar->getChild('event-0')->get()), + $this->fixLinebreak($publicObjectData)); + $this->assertEquals( + $this->fixLinebreak($rwCalendar->getChild('event-1')->get()), + $this->fixLinebreak($confidentialObjectCleaned)); + + // valarms shall be removed for read-only shares + $this->assertEquals( + $this->fixLinebreak($roCalendar->getChild('event-0')->get()), + $this->fixLinebreak($publicObjectDataWithoutVAlarm)); + $this->assertEquals( + $this->fixLinebreak($roCalendar->getChild('event-1')->get()), + $this->fixLinebreak($confidentialObjectCleaned)); + + } + + private function fixLinebreak($str) { + return preg_replace('~(*BSR_ANYCRLF)\R~', "\r\n", $str); + } } diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php index ec767f3dbd8..29ab503e082 100644 --- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php +++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php @@ -65,7 +65,7 @@ class PublicCalendarRootTest extends TestCase { $this->publicCalendarRoot = new PublicCalendarRoot($this->backend); - $this->l10n = $this->getMockBuilder('\OCP\IL10N') + $this->l10n = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor()->getMock(); } diff --git a/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php b/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php index 69de507dac5..b60c567e9f1 100644 --- a/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php +++ b/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php @@ -29,14 +29,14 @@ class PluginTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->getMockBuilder('\OCP\IConfig')-> + $this->config = $this->getMockBuilder(IConfig::class)-> disableOriginalConstructor()-> getMock(); $this->config->expects($this->any())->method('getSystemValue') ->with($this->equalTo('secret')) ->willReturn('mysecret'); - $this->urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')-> + $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)-> disableOriginalConstructor()-> getMock(); @@ -46,7 +46,7 @@ class PluginTest extends TestCase { $root = new SimpleCollection('calendars'); $this->server = new Server($root); /** @var SimpleCollection $node */ - $this->book = $this->getMockBuilder('OCA\DAV\CalDAV\Calendar')-> + $this->book = $this->getMockBuilder(Calendar::class)-> disableOriginalConstructor()-> getMock(); $this->book->method('getName')->willReturn('cal1'); diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php index 56eb00406da..894617781b5 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php @@ -38,11 +38,11 @@ class IMipPluginTest extends TestCase { public function testDelivery() { $mailMessage = new \OC\Mail\Message(new \Swift_Message()); /** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */ - $mailer = $this->getMockBuilder('OC\Mail\Mailer')->disableOriginalConstructor()->getMock(); + $mailer = $this->getMockBuilder(Mailer::class)->disableOriginalConstructor()->getMock(); $mailer->method('createMessage')->willReturn($mailMessage); $mailer->expects($this->once())->method('send'); /** @var ILogger | \PHPUnit_Framework_MockObject_MockObject $logger */ - $logger = $this->getMockBuilder('OC\Log')->disableOriginalConstructor()->getMock(); + $logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock(); $timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock(); $timeFactory->method('getTime')->willReturn(1); @@ -70,11 +70,11 @@ class IMipPluginTest extends TestCase { public function testFailedDelivery() { $mailMessage = new \OC\Mail\Message(new \Swift_Message()); /** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */ - $mailer = $this->getMockBuilder('OC\Mail\Mailer')->disableOriginalConstructor()->getMock(); + $mailer = $this->getMockBuilder(Mailer::class)->disableOriginalConstructor()->getMock(); $mailer->method('createMessage')->willReturn($mailMessage); $mailer->method('send')->willThrowException(new \Exception()); /** @var ILogger | \PHPUnit_Framework_MockObject_MockObject $logger */ - $logger = $this->getMockBuilder('OC\Log')->disableOriginalConstructor()->getMock(); + $logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock(); $timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock(); $timeFactory->method('getTime')->willReturn(1); @@ -105,7 +105,7 @@ class IMipPluginTest extends TestCase { public function testNoMessageSendForPastEvents($veventParams, $expectsMail) { $mailMessage = new \OC\Mail\Message(new \Swift_Message()); /** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */ - $mailer = $this->getMockBuilder('OC\Mail\Mailer')->disableOriginalConstructor()->getMock(); + $mailer = $this->getMockBuilder(Mailer::class)->disableOriginalConstructor()->getMock(); $mailer->method('createMessage')->willReturn($mailMessage); if ($expectsMail) { $mailer->expects($this->once())->method('send'); @@ -113,7 +113,7 @@ class IMipPluginTest extends TestCase { $mailer->expects($this->never())->method('send'); } /** @var ILogger | \PHPUnit_Framework_MockObject_MockObject $logger */ - $logger = $this->getMockBuilder('OC\Log')->disableOriginalConstructor()->getMock(); + $logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock(); $timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock(); $timeFactory->method('getTime')->willReturn(1496912528); |