2015-10-31 03:28:21 +03:00
< ? php
/**
2016-07-21 17:49:16 +03:00
* @ copyright Copyright ( c ) 2016 , ownCloud , Inc .
2017-04-25 20:26:47 +03:00
* @ copyright Copyright ( c ) 2017 Georg Ehrke
2016-07-21 17:49:16 +03:00
*
2020-03-31 11:49:10 +03:00
* @ author Christoph Wurst < christoph @ winzerhof - wurst . at >
* @ author dartcafe < github @ dartcafe . de >
2017-11-06 22:15:27 +03:00
* @ author Georg Ehrke < oc . list @ georgehrke . com >
2016-07-21 17:49:16 +03:00
* @ author Joas Schilling < coding @ schilljs . com >
2020-08-24 15:54:25 +03:00
* @ author Morris Jobke < hey @ morrisjobke . de >
2017-11-06 17:56:42 +03:00
* @ author Robin Appelman < robin @ icewind . nl >
2019-12-03 21:57:53 +03:00
* @ author Roeland Jago Douma < roeland @ famdouma . nl >
2020-03-31 11:49:10 +03:00
* @ author Thomas Citharel < nextcloud @ tcit . fr >
2016-01-12 17:02:16 +03:00
* @ author Thomas Müller < thomas . mueller @ tmit . eu >
2015-10-31 03:28:21 +03:00
*
* @ 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 ,
2019-12-03 21:57:53 +03:00
* along with this program . If not , see < http :// www . gnu . org / licenses />
2015-10-31 03:28:21 +03:00
*
*/
2016-05-25 17:04:15 +03:00
namespace OCA\DAV\Tests\unit\CalDAV ;
2015-10-31 03:28:21 +03:00
use DateTime ;
use DateTimeZone ;
use OCA\DAV\CalDAV\CalDavBackend ;
2016-01-28 19:16:11 +03:00
use OCA\DAV\CalDAV\Calendar ;
2017-10-20 16:09:52 +03:00
use OCP\IConfig ;
2016-04-21 14:36:52 +03:00
use OCP\IL10N ;
2019-11-22 22:52:10 +03:00
use Sabre\DAV\Exception\NotFound ;
2015-10-31 03:28:21 +03:00
use Sabre\DAV\PropPatch ;
2015-11-20 15:35:23 +03:00
use Sabre\DAV\Xml\Property\Href ;
2016-01-28 22:30:40 +03:00
use Sabre\DAVACL\IACL ;
2015-10-31 03:28:21 +03:00
/**
* Class CalDavBackendTest
*
* @ group DB
*
2016-05-25 17:04:15 +03:00
* @ package OCA\DAV\Tests\unit\CalDAV
2015-10-31 03:28:21 +03:00
*/
2017-10-05 13:32:46 +03:00
class CalDavBackendTest extends AbstractCalDavBackend {
2015-10-31 03:28:21 +03:00
public function testCalendarOperations () {
$calendarId = $this -> createTestCalendar ();
// update it's display name
$patch = new PropPatch ([
'{DAV:}displayname' => 'Unit test' ,
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing'
]);
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar' );
2015-10-31 03:28:21 +03:00
$this -> backend -> updateCalendar ( $calendarId , $patch );
$patch -> commit ();
2016-08-30 16:11:33 +03:00
$this -> assertEquals ( 1 , $this -> backend -> getCalendarsForUserCount ( self :: UNIT_TEST_USER ));
2017-03-02 13:45:07 +03:00
$calendars = $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER );
$this -> assertCount ( 1 , $calendars );
$this -> assertEquals ( 'Unit test' , $calendars [ 0 ][ '{DAV:}displayname' ]);
$this -> assertEquals ( 'Calendar used for unit testing' , $calendars [ 0 ][ '{urn:ietf:params:xml:ns:caldav}calendar-description' ]);
2017-04-19 17:18:44 +03:00
$this -> assertEquals ( 'User\'s displayname' , $calendars [ 0 ][ '{http://nextcloud.com/ns}owner-displayname' ]);
2015-10-31 03:28:21 +03:00
// delete the address book
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar' );
2017-03-02 13:45:07 +03:00
$this -> backend -> deleteCalendar ( $calendars [ 0 ][ 'id' ]);
$calendars = $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER );
$this -> assertCount ( 0 , $calendars );
2015-10-31 03:28:21 +03:00
}
2016-01-28 22:30:40 +03:00
public function providesSharingData () {
return [
[ true , true , true , false , [
[
'href' => 'principal:' . self :: UNIT_TEST_USER1 ,
'readOnly' => false
],
[
'href' => 'principal:' . self :: UNIT_TEST_GROUP ,
'readOnly' => true
]
]],
2017-03-02 14:27:59 +03:00
[ true , true , true , false , [
[
'href' => 'principal:' . self :: UNIT_TEST_GROUP ,
'readOnly' => true ,
],
[
'href' => 'principal:' . self :: UNIT_TEST_GROUP2 ,
'readOnly' => false ,
],
]],
[ true , true , true , true , [
[
'href' => 'principal:' . self :: UNIT_TEST_GROUP ,
'readOnly' => false ,
],
[
'href' => 'principal:' . self :: UNIT_TEST_GROUP2 ,
'readOnly' => true ,
],
]],
2016-01-28 22:30:40 +03:00
[ true , false , false , false , [
[
'href' => 'principal:' . self :: UNIT_TEST_USER1 ,
'readOnly' => true
],
]],
];
}
/**
* @ dataProvider providesSharingData
*/
public function testCalendarSharing ( $userCanRead , $userCanWrite , $groupCanRead , $groupCanWrite , $add ) {
2016-01-28 19:16:11 +03:00
2020-08-11 22:32:18 +03:00
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l10n */
2017-03-02 13:45:07 +03:00
$l10n = $this -> createMock ( IL10N :: class );
2016-04-14 16:38:00 +03:00
$l10n
-> expects ( $this -> any ())
-> method ( 't' )
2020-03-26 11:30:18 +03:00
-> willReturnCallback ( function ( $text , $parameters = []) {
2016-04-14 16:38:00 +03:00
return vsprintf ( $text , $parameters );
2020-03-26 00:21:27 +03:00
});
2016-04-14 16:38:00 +03:00
2017-10-20 16:09:52 +03:00
$config = $this -> createMock ( IConfig :: class );
2017-10-05 13:32:46 +03:00
$this -> userManager -> expects ( $this -> any ())
-> method ( 'userExists' )
-> willReturn ( true );
2017-10-09 13:57:41 +03:00
$this -> groupManager -> expects ( $this -> any ())
2017-10-05 13:32:46 +03:00
-> method ( 'groupExists' )
-> willReturn ( true );
2016-01-28 22:30:40 +03:00
$calendarId = $this -> createTestCalendar ();
2017-03-02 13:45:07 +03:00
$calendars = $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER );
$this -> assertCount ( 1 , $calendars );
2017-10-20 16:09:52 +03:00
$calendar = new Calendar ( $this -> backend , $calendars [ 0 ], $l10n , $config );
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::updateShares' );
2016-01-28 22:30:40 +03:00
$this -> backend -> updateShares ( $calendar , $add , []);
2017-03-02 13:45:07 +03:00
$calendars = $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER1 );
$this -> assertCount ( 1 , $calendars );
2017-10-20 16:09:52 +03:00
$calendar = new Calendar ( $this -> backend , $calendars [ 0 ], $l10n , $config );
2016-01-28 22:30:40 +03:00
$acl = $calendar -> getACL ();
$this -> assertAcl ( self :: UNIT_TEST_USER , '{DAV:}read' , $acl );
$this -> assertAcl ( self :: UNIT_TEST_USER , '{DAV:}write' , $acl );
$this -> assertAccess ( $userCanRead , self :: UNIT_TEST_USER1 , '{DAV:}read' , $acl );
$this -> assertAccess ( $userCanWrite , self :: UNIT_TEST_USER1 , '{DAV:}write' , $acl );
$this -> assertEquals ( self :: UNIT_TEST_USER , $calendar -> getOwner ());
// test acls on the child
2017-03-02 13:45:07 +03:00
$uri = static :: getUniqueID ( 'calobj' );
2016-01-28 22:30:40 +03:00
$calData = <<< 'EOD'
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject' );
2016-01-28 22:30:40 +03:00
$this -> backend -> createCalendarObject ( $calendarId , $uri , $calData );
/** @var IACL $child */
$child = $calendar -> getChild ( $uri );
$acl = $child -> getACL ();
$this -> assertAcl ( self :: UNIT_TEST_USER , '{DAV:}read' , $acl );
$this -> assertAcl ( self :: UNIT_TEST_USER , '{DAV:}write' , $acl );
$this -> assertAccess ( $userCanRead , self :: UNIT_TEST_USER1 , '{DAV:}read' , $acl );
$this -> assertAccess ( $userCanWrite , self :: UNIT_TEST_USER1 , '{DAV:}write' , $acl );
2016-01-28 19:16:11 +03:00
// delete the address book
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar' );
2017-03-02 13:45:07 +03:00
$this -> backend -> deleteCalendar ( $calendars [ 0 ][ 'id' ]);
$calendars = $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER );
$this -> assertCount ( 0 , $calendars );
2016-01-28 19:16:11 +03:00
}
2015-10-31 03:28:21 +03:00
public function testCalendarObjectsOperations () {
$calendarId = $this -> createTestCalendar ();
// create a card
2017-03-02 13:45:07 +03:00
$uri = static :: getUniqueID ( 'calobj' );
2015-10-31 03:28:21 +03:00
$calData = <<< 'EOD'
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject' );
2015-10-31 03:28:21 +03:00
$this -> backend -> createCalendarObject ( $calendarId , $uri , $calData );
// get all the cards
$calendarObjects = $this -> backend -> getCalendarObjects ( $calendarId );
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 1 , $calendarObjects );
2015-10-31 03:28:21 +03:00
$this -> assertEquals ( $calendarId , $calendarObjects [ 0 ][ 'calendarid' ]);
2016-05-31 18:16:28 +03:00
$this -> assertArrayHasKey ( 'classification' , $calendarObjects [ 0 ]);
2015-10-31 03:28:21 +03:00
// get the cards
$calendarObject = $this -> backend -> getCalendarObject ( $calendarId , $uri );
$this -> assertNotNull ( $calendarObject );
$this -> assertArrayHasKey ( 'id' , $calendarObject );
$this -> assertArrayHasKey ( 'uri' , $calendarObject );
$this -> assertArrayHasKey ( 'lastmodified' , $calendarObject );
$this -> assertArrayHasKey ( 'etag' , $calendarObject );
$this -> assertArrayHasKey ( 'size' , $calendarObject );
2016-05-31 18:16:28 +03:00
$this -> assertArrayHasKey ( 'classification' , $calendarObject );
2015-10-31 03:28:21 +03:00
$this -> assertEquals ( $calData , $calendarObject [ 'calendardata' ]);
// update the card
$calData = <<< 'EOD'
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
END : VEVENT
END : VCALENDAR
EOD ;
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject' );
2015-10-31 03:28:21 +03:00
$this -> backend -> updateCalendarObject ( $calendarId , $uri , $calData );
$calendarObject = $this -> backend -> getCalendarObject ( $calendarId , $uri );
$this -> assertEquals ( $calData , $calendarObject [ 'calendardata' ]);
// delete the card
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject' );
2015-10-31 03:28:21 +03:00
$this -> backend -> deleteCalendarObject ( $calendarId , $uri );
$calendarObjects = $this -> backend -> getCalendarObjects ( $calendarId );
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 0 , $calendarObjects );
2015-10-31 03:28:21 +03:00
}
2020-07-23 14:38:49 +03:00
2017-11-02 00:00:53 +03:00
public function testMultipleCalendarObjectsWithSameUID () {
2019-11-27 17:27:18 +03:00
$this -> expectException ( \Sabre\DAV\Exception\BadRequest :: class );
$this -> expectExceptionMessage ( 'Calendar object with uid already exists in this calendar collection.' );
2017-11-02 00:00:53 +03:00
$calendarId = $this -> createTestCalendar ();
$calData = <<< 'EOD'
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8 - 1
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
$uri0 = static :: getUniqueID ( 'event' );
$uri1 = static :: getUniqueID ( 'event' );
$this -> backend -> createCalendarObject ( $calendarId , $uri0 , $calData );
$this -> backend -> createCalendarObject ( $calendarId , $uri1 , $calData );
}
2015-10-31 03:28:21 +03:00
public function testMultiCalendarObjects () {
$calendarId = $this -> createTestCalendar ();
// create an event
2017-11-02 00:00:53 +03:00
$calData = [];
$calData [] = <<< 'EOD'
2015-10-31 03:28:21 +03:00
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
2017-11-02 00:00:53 +03:00
UID : 47 d15e3ec8 - 1
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
$calData [] = <<< 'EOD'
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8 - 2
2015-10-31 03:28:21 +03:00
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
2017-11-02 00:00:53 +03:00
$calData [] = <<< 'EOD'
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8 - 3
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
2017-03-02 13:45:07 +03:00
$uri0 = static :: getUniqueID ( 'card' );
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject' );
2017-11-02 00:00:53 +03:00
$this -> backend -> createCalendarObject ( $calendarId , $uri0 , $calData [ 0 ]);
2017-03-02 13:45:07 +03:00
$uri1 = static :: getUniqueID ( 'card' );
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject' );
2017-11-02 00:00:53 +03:00
$this -> backend -> createCalendarObject ( $calendarId , $uri1 , $calData [ 1 ]);
2017-03-02 13:45:07 +03:00
$uri2 = static :: getUniqueID ( 'card' );
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject' );
2017-11-02 00:00:53 +03:00
$this -> backend -> createCalendarObject ( $calendarId , $uri2 , $calData [ 2 ]);
2015-10-31 03:28:21 +03:00
// get all the cards
$calendarObjects = $this -> backend -> getCalendarObjects ( $calendarId );
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 3 , $calendarObjects );
2015-10-31 03:28:21 +03:00
// get the cards
$calendarObjects = $this -> backend -> getMultipleCalendarObjects ( $calendarId , [ $uri1 , $uri2 ]);
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 2 , $calendarObjects );
2020-04-10 15:19:56 +03:00
foreach ( $calendarObjects as $card ) {
2015-10-31 03:28:21 +03:00
$this -> assertArrayHasKey ( 'id' , $card );
$this -> assertArrayHasKey ( 'uri' , $card );
$this -> assertArrayHasKey ( 'lastmodified' , $card );
$this -> assertArrayHasKey ( 'etag' , $card );
$this -> assertArrayHasKey ( 'size' , $card );
2016-05-31 18:16:28 +03:00
$this -> assertArrayHasKey ( 'classification' , $card );
2015-10-31 03:28:21 +03:00
}
2020-04-09 14:53:40 +03:00
usort ( $calendarObjects , function ( $a , $b ) {
2017-11-02 00:00:53 +03:00
return $a [ 'id' ] - $b [ 'id' ];
});
$this -> assertEquals ( $calData [ 1 ], $calendarObjects [ 0 ][ 'calendardata' ]);
$this -> assertEquals ( $calData [ 2 ], $calendarObjects [ 1 ][ 'calendardata' ]);
2015-10-31 03:28:21 +03:00
// delete the card
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject' );
2015-10-31 03:28:21 +03:00
$this -> backend -> deleteCalendarObject ( $calendarId , $uri0 );
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject' );
2015-10-31 03:28:21 +03:00
$this -> backend -> deleteCalendarObject ( $calendarId , $uri1 );
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject' );
2015-10-31 03:28:21 +03:00
$this -> backend -> deleteCalendarObject ( $calendarId , $uri2 );
$calendarObjects = $this -> backend -> getCalendarObjects ( $calendarId );
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 0 , $calendarObjects );
2015-10-31 03:28:21 +03:00
}
/**
* @ dataProvider providesCalendarQueryParameters
*/
public function testCalendarQuery ( $expectedEventsInResult , $propFilters , $compFilter ) {
$calendarId = $this -> createTestCalendar ();
$events = [];
$events [ 0 ] = $this -> createEvent ( $calendarId , '20130912T130000Z' , '20130912T140000Z' );
$events [ 1 ] = $this -> createEvent ( $calendarId , '20130912T150000Z' , '20130912T170000Z' );
$events [ 2 ] = $this -> createEvent ( $calendarId , '20130912T173000Z' , '20130912T220000Z' );
2016-04-25 15:32:41 +03:00
$events [ 3 ] = $this -> createEvent ( $calendarId , '21130912T130000Z' , '22130912T130000Z' );
2015-10-31 03:28:21 +03:00
$result = $this -> backend -> calendarQuery ( $calendarId , [
'name' => '' ,
'prop-filters' => $propFilters ,
'comp-filters' => $compFilter
]);
2020-04-09 14:53:40 +03:00
$expectedEventsInResult = array_map ( function ( $index ) use ( $events ) {
2015-10-31 03:28:21 +03:00
return $events [ $index ];
}, $expectedEventsInResult );
2020-07-23 14:38:49 +03:00
$this -> assertEqualsCanonicalizing ( $expectedEventsInResult , $result );
2015-10-31 03:28:21 +03:00
}
public function testGetCalendarObjectByUID () {
$calendarId = $this -> createTestCalendar ();
2017-11-02 00:00:53 +03:00
$uri = static :: getUniqueID ( 'calobj' );
$calData = <<< 'EOD'
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
$this -> backend -> createCalendarObject ( $calendarId , $uri , $calData );
2015-10-31 03:28:21 +03:00
$co = $this -> backend -> getCalendarObjectByUID ( self :: UNIT_TEST_USER , '47d15e3ec8' );
$this -> assertNotNull ( $co );
}
public function providesCalendarQueryParameters () {
return [
2016-04-25 15:32:41 +03:00
'all' => [[ 0 , 1 , 2 , 3 ], [], []],
2015-10-31 03:28:21 +03:00
'only-todos' => [[], [ 'name' => 'VTODO' ], []],
2016-04-25 15:32:41 +03:00
'only-events' => [[ 0 , 1 , 2 , 3 ], [], [[ 'name' => 'VEVENT' , 'is-not-defined' => false , 'comp-filters' => [], 'time-range' => [ 'start' => null , 'end' => null ], 'prop-filters' => []]],],
'start' => [[ 1 , 2 , 3 ], [], [[ 'name' => 'VEVENT' , 'is-not-defined' => false , 'comp-filters' => [], 'time-range' => [ 'start' => new DateTime ( '2013-09-12 14:00:00' , new DateTimeZone ( 'UTC' )), 'end' => null ], 'prop-filters' => []]],],
2015-10-31 03:28:21 +03:00
'end' => [[ 0 ], [], [[ 'name' => 'VEVENT' , 'is-not-defined' => false , 'comp-filters' => [], 'time-range' => [ 'start' => null , 'end' => new DateTime ( '2013-09-12 14:00:00' , new DateTimeZone ( 'UTC' ))], 'prop-filters' => []]],],
2016-04-25 15:32:41 +03:00
'future' => [[ 3 ], [], [[ 'name' => 'VEVENT' , 'is-not-defined' => false , 'comp-filters' => [], 'time-range' => [ 'start' => new DateTime ( '2099-09-12 14:00:00' , new DateTimeZone ( 'UTC' )), 'end' => null ], 'prop-filters' => []]],],
2015-10-31 03:28:21 +03:00
];
}
public function testSyncSupport () {
$calendarId = $this -> createTestCalendar ();
// fist call without synctoken
$changes = $this -> backend -> getChangesForCalendar ( $calendarId , '' , 1 );
$syncToken = $changes [ 'syncToken' ];
// add a change
$event = $this -> createEvent ( $calendarId , '20130912T130000Z' , '20130912T140000Z' );
// look for changes
$changes = $this -> backend -> getChangesForCalendar ( $calendarId , $syncToken , 1 );
$this -> assertEquals ( $event , $changes [ 'added' ][ 0 ]);
}
2016-07-20 15:08:45 +03:00
public function testPublications () {
2020-07-28 10:35:51 +03:00
$this -> legacyDispatcher -> expects ( $this -> at ( 0 ))
2016-11-03 14:28:12 +03:00
-> method ( 'dispatch' )
-> with ( '\OCA\DAV\CalDAV\CalDavBackend::createCalendar' );
2016-07-20 15:08:45 +03:00
$this -> backend -> createCalendar ( self :: UNIT_TEST_USER , 'Example' , []);
$calendarInfo = $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER )[ 0 ];
2020-08-11 22:32:18 +03:00
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l10n */
2017-03-02 13:45:07 +03:00
$l10n = $this -> createMock ( IL10N :: class );
2017-10-20 16:09:52 +03:00
$config = $this -> createMock ( IConfig :: class );
2016-07-20 15:08:45 +03:00
2017-10-20 16:09:52 +03:00
$calendar = new Calendar ( $this -> backend , $calendarInfo , $l10n , $config );
2016-08-14 20:08:01 +03:00
$calendar -> setPublishStatus ( true );
2016-09-15 18:09:24 +03:00
$this -> assertNotEquals ( false , $calendar -> getPublishStatus ());
2016-07-20 15:08:45 +03:00
$publicCalendars = $this -> backend -> getPublicCalendars ();
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 1 , $publicCalendars );
2016-07-20 15:08:45 +03:00
$this -> assertEquals ( true , $publicCalendars [ 0 ][ '{http://owncloud.org/ns}public' ]);
2017-04-19 17:18:44 +03:00
$this -> assertEquals ( 'User\'s displayname' , $publicCalendars [ 0 ][ '{http://nextcloud.com/ns}owner-displayname' ]);
2016-07-20 15:08:45 +03:00
2016-09-03 11:52:05 +03:00
$publicCalendarURI = $publicCalendars [ 0 ][ 'uri' ];
2016-08-14 20:08:01 +03:00
$publicCalendar = $this -> backend -> getPublicCalendar ( $publicCalendarURI );
$this -> assertEquals ( true , $publicCalendar [ '{http://owncloud.org/ns}public' ]);
$calendar -> setPublishStatus ( false );
$this -> assertEquals ( false , $calendar -> getPublishStatus ());
2018-01-24 20:10:16 +03:00
$this -> expectException ( NotFound :: class );
2016-10-13 12:04:22 +03:00
$this -> backend -> getPublicCalendar ( $publicCalendarURI );
2016-07-20 15:08:45 +03:00
}
2015-10-31 03:28:21 +03:00
public function testSubscriptions () {
$id = $this -> backend -> createSubscription ( self :: UNIT_TEST_USER , 'Subscription' , [
2016-07-01 14:42:35 +03:00
'{http://calendarserver.org/ns/}source' => new Href ( 'test-source' ),
'{http://apple.com/ns/ical/}calendar-color' => '#1C4587' ,
'{http://calendarserver.org/ns/}subscribed-strip-todos' => ''
2015-10-31 03:28:21 +03:00
]);
$subscriptions = $this -> backend -> getSubscriptionsForUser ( self :: UNIT_TEST_USER );
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 1 , $subscriptions );
2016-07-01 14:42:35 +03:00
$this -> assertEquals ( '#1C4587' , $subscriptions [ 0 ][ '{http://apple.com/ns/ical/}calendar-color' ]);
$this -> assertEquals ( true , $subscriptions [ 0 ][ '{http://calendarserver.org/ns/}subscribed-strip-todos' ]);
2015-10-31 03:28:21 +03:00
$this -> assertEquals ( $id , $subscriptions [ 0 ][ 'id' ]);
$patch = new PropPatch ([
2020-04-09 10:22:29 +03:00
'{DAV:}displayname' => 'Unit test' ,
'{http://apple.com/ns/ical/}calendar-color' => '#ac0606' ,
2015-10-31 03:28:21 +03:00
]);
$this -> backend -> updateSubscription ( $id , $patch );
$patch -> commit ();
$subscriptions = $this -> backend -> getSubscriptionsForUser ( self :: UNIT_TEST_USER );
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 1 , $subscriptions );
2015-10-31 03:28:21 +03:00
$this -> assertEquals ( $id , $subscriptions [ 0 ][ 'id' ]);
$this -> assertEquals ( 'Unit test' , $subscriptions [ 0 ][ '{DAV:}displayname' ]);
2016-07-01 14:42:35 +03:00
$this -> assertEquals ( '#ac0606' , $subscriptions [ 0 ][ '{http://apple.com/ns/ical/}calendar-color' ]);
2015-10-31 03:28:21 +03:00
$this -> backend -> deleteSubscription ( $id );
$subscriptions = $this -> backend -> getSubscriptionsForUser ( self :: UNIT_TEST_USER );
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 0 , $subscriptions );
2015-10-31 03:28:21 +03:00
}
2018-02-21 12:18:38 +03:00
public function providesSchedulingData () {
$data =<<< EOS
BEGIN : VCALENDAR
VERSION : 2.0
PRODID :-// Sabre //Sabre VObject 3.5.0//EN
CALSCALE : GREGORIAN
METHOD : REQUEST
BEGIN : VTIMEZONE
TZID : Europe / Warsaw
BEGIN : DAYLIGHT
TZOFFSETFROM :+ 0100
TZOFFSETTO :+ 0200
TZNAME : CEST
DTSTART : 19700329 T020000
RRULE : FREQ = YEARLY ; BYDAY =- 1 SU ; BYMONTH = 3
END : DAYLIGHT
BEGIN : STANDARD
TZOFFSETFROM :+ 0200
TZOFFSETTO :+ 0100
TZNAME : CET
DTSTART : 19701025 T030000
RRULE : FREQ = YEARLY ; BYDAY =- 1 SU ; BYMONTH = 10
END : STANDARD
END : VTIMEZONE
BEGIN : VEVENT
CREATED : 20170320 T131655Z
LAST - MODIFIED : 20170320 T135019Z
DTSTAMP : 20170320 T135019Z
UID : 7e908 a6d - 4 c4e - 48 d7 - bd62 - 59 ab80fbf1a3
SUMMARY : TEST Z pg_escape_bytea
ORGANIZER ; RSVP = TRUE ; PARTSTAT = ACCEPTED ; ROLE = CHAIR : mailto : k . klimczak @ gromar . e
u
ATTENDEE ; RSVP = TRUE ; CN = Zuzanna Leszek ; PARTSTAT = NEEDS - ACTION ; ROLE = REQ - PARTICI
PANT : mailto : z . leszek @ gromar . eu
ATTENDEE ; RSVP = TRUE ; CN = Marcin Pisarski ; PARTSTAT = NEEDS - ACTION ; ROLE = REQ - PARTIC
IPANT : mailto : m . pisarski @ gromar . eu
ATTENDEE ; RSVP = TRUE ; PARTSTAT = NEEDS - ACTION ; ROLE = REQ - PARTICIPANT : mailto : klimcz
ak . k @ gmail . com
ATTENDEE ; RSVP = TRUE ; PARTSTAT = NEEDS - ACTION ; ROLE = REQ - PARTICIPANT : mailto : k_klim
czak @ tlen . pl
DTSTART ; TZID = Europe / Warsaw : 20170325 T150000
DTEND ; TZID = Europe / Warsaw : 20170325 T160000
TRANSP : OPAQUE
DESCRIPTION : Magiczna treść uzyskana za pomocą magicznego proszku . \n\nę
2020-07-27 17:14:15 +03:00
żźćńłóÓŻŹĆŁĘ€śśśŚŚ\n \ , \ ,)))))))) \ ; \ , \n
2018-02-21 12:18:38 +03:00
__ )))))))))))))) \ , \n \\ |/ - \\ ((((( '' '' (((((((( . \n -*-==///
2020-07-27 17:14:15 +03:00
///(('' . `))))))\,\n /|\\ ))| o \;-. '(((((
\ ,( \ , \n ( ` | / ) \ ;)))) '
2018-02-21 12:18:38 +03:00
\ , _ )) ^ \ ;( ~ \n | | | \ ,))(((( _ _____ -
-----~~~-. % \ , \ ;( \ ;( > '\;' ~ \n o_ ) \ ; \ ; )))((( ` ~---
~ `:: \\ %%~~)(v\;(` ( '~\n \; ' '' ' `` ``
2020-07-27 17:14:15 +03:00
`: ` :::| \\\ , __\ , %% ) \ ; ` ' \ ; ~ \n | _
) / `:|` ---- ' `-' \n ______ / \\ /~ |
2018-02-21 12:18:38 +03:00
/ / \n /~ \ ; \ ; . ____ / \ ; \ ; ' / ___ -- \
2020-07-27 17:14:15 +03:00
, - ( ` \ ; \ ; \ ; / \n / // _\;______\;'------~~~~~ /\;\;/\\ /\n
// | | / \; \\\;\;\,\\\n (<_ | \;
/ '\,/-----' _ > \n \\_ | || _
//~\;~~~~~~~~~\n `\\_| (\,~~ -Tua Xiong\n
\\ ~ \\\n
2018-02-21 12:18:38 +03:00
~~ \n\n
SEQUENCE : 1
X - MOZ - GENERATION : 1
END : VEVENT
END : VCALENDAR
EOS ;
return [
'no data' => [ '' ],
'failing on postgres' => [ $data ]
];
}
/**
* @ dataProvider providesSchedulingData
* @ param $objectData
*/
public function testScheduling ( $objectData ) {
$this -> backend -> createSchedulingObject ( self :: UNIT_TEST_USER , 'Sample Schedule' , $objectData );
2015-11-16 17:49:46 +03:00
$sos = $this -> backend -> getSchedulingObjects ( self :: UNIT_TEST_USER );
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 1 , $sos );
2015-11-16 17:49:46 +03:00
$so = $this -> backend -> getSchedulingObject ( self :: UNIT_TEST_USER , 'Sample Schedule' );
$this -> assertNotNull ( $so );
$this -> backend -> deleteSchedulingObject ( self :: UNIT_TEST_USER , 'Sample Schedule' );
$sos = $this -> backend -> getSchedulingObjects ( self :: UNIT_TEST_USER );
2017-03-02 13:45:07 +03:00
$this -> assertCount ( 0 , $sos );
2015-11-16 17:49:46 +03:00
}
2016-01-28 22:30:40 +03:00
2016-03-09 20:13:34 +03:00
/**
* @ dataProvider providesCalDataForGetDenormalizedData
*/
2016-04-19 12:33:37 +03:00
public function testGetDenormalizedData ( $expected , $key , $calData ) {
$actual = $this -> backend -> getDenormalizedData ( $calData );
$this -> assertEquals ( $expected , $actual [ $key ]);
2016-03-09 20:13:34 +03:00
}
public function providesCalDataForGetDenormalizedData () {
return [
2016-10-13 13:15:10 +03:00
'first occurrence before unix epoch starts' => [ 0 , 'firstOccurence' , " BEGIN:VCALENDAR \r \n VERSION:2.0 \r \n PRODID:-//Sabre//Sabre VObject 4.1.1//EN \r \n CALSCALE:GREGORIAN \r \n BEGIN:VEVENT \r \n UID:413F269B-B51B-46B1-AFB6-40055C53A4DC \r \n DTSTAMP:20160309T095056Z \r \n DTSTART;VALUE=DATE:16040222 \r \n DTEND;VALUE=DATE:16040223 \r \n RRULE:FREQ=YEARLY \r \n SUMMARY:SUMMARY \r \n TRANSP:TRANSPARENT \r \n END:VEVENT \r \n END:VCALENDAR \r \n " ],
'no first occurrence because yearly' => [ null , 'firstOccurence' , " BEGIN:VCALENDAR \r \n VERSION:2.0 \r \n PRODID:-//Sabre//Sabre VObject 4.1.1//EN \r \n CALSCALE:GREGORIAN \r \n BEGIN:VEVENT \r \n UID:413F269B-B51B-46B1-AFB6-40055C53A4DC \r \n DTSTAMP:20160309T095056Z \r \n RRULE:FREQ=YEARLY \r \n SUMMARY:SUMMARY \r \n TRANSP:TRANSPARENT \r \n END:VEVENT \r \n END:VCALENDAR \r \n " ],
2016-04-19 12:33:37 +03:00
'CLASS:PRIVATE' => [ CalDavBackend :: CLASSIFICATION_PRIVATE , 'classification' , " BEGIN:VCALENDAR \r \n VERSION:2.0 \r \n PRODID:-//dmfs.org//mimedir.icalendar//EN \r \n BEGIN:VTIMEZONE \r \n TZID:Europe/Berlin \r \n X-LIC-LOCATION:Europe/Berlin \r \n BEGIN:DAYLIGHT \r \n TZOFFSETFROM:+0100 \r \n TZOFFSETTO:+0200 \r \n TZNAME:CEST \r \n DTSTART:19700329T020000 \r \n RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU \r \n END:DAYLIGHT \r \n BEGIN:STANDARD \r \n TZOFFSETFROM:+0200 \r \n TZOFFSETTO:+0100 \r \n TZNAME:CET \r \n DTSTART:19701025T030000 \r \n RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU \r \n END:STANDARD \r \n END:VTIMEZONE \r \n BEGIN:VEVENT \r \n DTSTART;TZID=Europe/Berlin:20160419T130000 \r \n SUMMARY:Test \r \n CLASS:PRIVATE \r \n TRANSP:OPAQUE \r \n STATUS:CONFIRMED \r \n DTEND;TZID=Europe/Berlin:20160419T140000 \r \n LAST-MODIFIED:20160419T074202Z \r \n DTSTAMP:20160419T074202Z \r \n CREATED:20160419T074202Z \r \n UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310 \r \n END:VEVENT \r \n END:VCALENDAR " ],
'CLASS:PUBLIC' => [ CalDavBackend :: CLASSIFICATION_PUBLIC , 'classification' , " BEGIN:VCALENDAR \r \n VERSION:2.0 \r \n PRODID:-//dmfs.org//mimedir.icalendar//EN \r \n BEGIN:VTIMEZONE \r \n TZID:Europe/Berlin \r \n X-LIC-LOCATION:Europe/Berlin \r \n BEGIN:DAYLIGHT \r \n TZOFFSETFROM:+0100 \r \n TZOFFSETTO:+0200 \r \n TZNAME:CEST \r \n DTSTART:19700329T020000 \r \n RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU \r \n END:DAYLIGHT \r \n BEGIN:STANDARD \r \n TZOFFSETFROM:+0200 \r \n TZOFFSETTO:+0100 \r \n TZNAME:CET \r \n DTSTART:19701025T030000 \r \n RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU \r \n END:STANDARD \r \n END:VTIMEZONE \r \n BEGIN:VEVENT \r \n DTSTART;TZID=Europe/Berlin:20160419T130000 \r \n SUMMARY:Test \r \n CLASS:PUBLIC \r \n TRANSP:OPAQUE \r \n STATUS:CONFIRMED \r \n DTEND;TZID=Europe/Berlin:20160419T140000 \r \n LAST-MODIFIED:20160419T074202Z \r \n DTSTAMP:20160419T074202Z \r \n CREATED:20160419T074202Z \r \n UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310 \r \n END:VEVENT \r \n END:VCALENDAR " ],
'CLASS:CONFIDENTIAL' => [ CalDavBackend :: CLASSIFICATION_CONFIDENTIAL , 'classification' , " BEGIN:VCALENDAR \r \n VERSION:2.0 \r \n PRODID:-//dmfs.org//mimedir.icalendar//EN \r \n BEGIN:VTIMEZONE \r \n TZID:Europe/Berlin \r \n X-LIC-LOCATION:Europe/Berlin \r \n BEGIN:DAYLIGHT \r \n TZOFFSETFROM:+0100 \r \n TZOFFSETTO:+0200 \r \n TZNAME:CEST \r \n DTSTART:19700329T020000 \r \n RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU \r \n END:DAYLIGHT \r \n BEGIN:STANDARD \r \n TZOFFSETFROM:+0200 \r \n TZOFFSETTO:+0100 \r \n TZNAME:CET \r \n DTSTART:19701025T030000 \r \n RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU \r \n END:STANDARD \r \n END:VTIMEZONE \r \n BEGIN:VEVENT \r \n DTSTART;TZID=Europe/Berlin:20160419T130000 \r \n SUMMARY:Test \r \n CLASS:CONFIDENTIAL \r \n TRANSP:OPAQUE \r \n STATUS:CONFIRMED \r \n DTEND;TZID=Europe/Berlin:20160419T140000 \r \n LAST-MODIFIED:20160419T074202Z \r \n DTSTAMP:20160419T074202Z \r \n CREATED:20160419T074202Z \r \n UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310 \r \n END:VEVENT \r \n END:VCALENDAR " ],
'no class set -> public' => [ CalDavBackend :: CLASSIFICATION_PUBLIC , 'classification' , " BEGIN:VCALENDAR \r \n VERSION:2.0 \r \n PRODID:-//dmfs.org//mimedir.icalendar//EN \r \n BEGIN:VTIMEZONE \r \n TZID:Europe/Berlin \r \n X-LIC-LOCATION:Europe/Berlin \r \n BEGIN:DAYLIGHT \r \n TZOFFSETFROM:+0100 \r \n TZOFFSETTO:+0200 \r \n TZNAME:CEST \r \n DTSTART:19700329T020000 \r \n RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU \r \n END:DAYLIGHT \r \n BEGIN:STANDARD \r \n TZOFFSETFROM:+0200 \r \n TZOFFSETTO:+0100 \r \n TZNAME:CET \r \n DTSTART:19701025T030000 \r \n RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU \r \n END:STANDARD \r \n END:VTIMEZONE \r \n BEGIN:VEVENT \r \n DTSTART;TZID=Europe/Berlin:20160419T130000 \r \n SUMMARY:Test \r \n TRANSP:OPAQUE \r \n DTEND;TZID=Europe/Berlin:20160419T140000 \r \n LAST-MODIFIED:20160419T074202Z \r \n DTSTAMP:20160419T074202Z \r \n CREATED:20160419T074202Z \r \n UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310 \r \n END:VEVENT \r \n END:VCALENDAR " ],
'unknown class -> private' => [ CalDavBackend :: CLASSIFICATION_PRIVATE , 'classification' , " BEGIN:VCALENDAR \r \n VERSION:2.0 \r \n PRODID:-//dmfs.org//mimedir.icalendar//EN \r \n BEGIN:VTIMEZONE \r \n TZID:Europe/Berlin \r \n X-LIC-LOCATION:Europe/Berlin \r \n BEGIN:DAYLIGHT \r \n TZOFFSETFROM:+0100 \r \n TZOFFSETTO:+0200 \r \n TZNAME:CEST \r \n DTSTART:19700329T020000 \r \n RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU \r \n END:DAYLIGHT \r \n BEGIN:STANDARD \r \n TZOFFSETFROM:+0200 \r \n TZOFFSETTO:+0100 \r \n TZNAME:CET \r \n DTSTART:19701025T030000 \r \n RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU \r \n END:STANDARD \r \n END:VTIMEZONE \r \n BEGIN:VEVENT \r \n DTSTART;TZID=Europe/Berlin:20160419T130000 \r \n SUMMARY:Test \r \n CLASS:VERTRAULICH \r \n TRANSP:OPAQUE \r \n STATUS:CONFIRMED \r \n DTEND;TZID=Europe/Berlin:20160419T140000 \r \n LAST-MODIFIED:20160419T074202Z \r \n DTSTAMP:20160419T074202Z \r \n CREATED:20160419T074202Z \r \n UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310 \r \n END:VEVENT \r \n END:VCALENDAR " ],
2016-03-09 20:13:34 +03:00
];
}
2017-04-25 20:26:47 +03:00
public function testCalendarSearch () {
$calendarId = $this -> createTestCalendar ();
$uri = static :: getUniqueID ( 'calobj' );
$calData = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
$this -> backend -> createCalendarObject ( $calendarId , $uri , $calData );
$search1 = $this -> backend -> calendarSearch ( self :: UNIT_TEST_USER , [
'comps' => [
'VEVENT' ,
'VTODO'
],
'props' => [
'SUMMARY' ,
'LOCATION'
],
'search-term' => 'Test' ,
]);
$this -> assertEquals ( count ( $search1 ), 1 );
// update the card
$calData = <<< 'EOD'
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
2017-05-21 14:18:58 +03:00
SUMMARY : 123 Event 🙈
2017-04-25 20:26:47 +03:00
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
ATTENDEE ; CN = test : mailto : foo @ bar . com
END : VEVENT
END : VCALENDAR
EOD ;
$this -> backend -> updateCalendarObject ( $calendarId , $uri , $calData );
$search2 = $this -> backend -> calendarSearch ( self :: UNIT_TEST_USER , [
'comps' => [
'VEVENT' ,
'VTODO'
],
'props' => [
'SUMMARY' ,
'LOCATION'
],
'search-term' => 'Test' ,
]);
$this -> assertEquals ( count ( $search2 ), 0 );
$search3 = $this -> backend -> calendarSearch ( self :: UNIT_TEST_USER , [
'comps' => [
'VEVENT' ,
'VTODO'
],
'props' => [
'SUMMARY' ,
'LOCATION'
],
'params' => [
[
'property' => 'ATTENDEE' ,
'parameter' => 'CN'
]
],
'search-term' => 'Test' ,
]);
$this -> assertEquals ( count ( $search3 ), 1 );
// t matches both summary and attendee's CN, but we want unique results
$search4 = $this -> backend -> calendarSearch ( self :: UNIT_TEST_USER , [
'comps' => [
'VEVENT' ,
'VTODO'
],
'props' => [
'SUMMARY' ,
'LOCATION'
],
'params' => [
[
'property' => 'ATTENDEE' ,
'parameter' => 'CN'
]
],
'search-term' => 't' ,
]);
$this -> assertEquals ( count ( $search4 ), 1 );
$this -> backend -> deleteCalendarObject ( $calendarId , $uri );
$search5 = $this -> backend -> calendarSearch ( self :: UNIT_TEST_USER , [
'comps' => [
'VEVENT' ,
'VTODO'
],
'props' => [
'SUMMARY' ,
'LOCATION'
],
'params' => [
[
'property' => 'ATTENDEE' ,
'parameter' => 'CN'
]
],
'search-term' => 't' ,
]);
$this -> assertEquals ( count ( $search5 ), 0 );
}
2017-11-07 03:31:28 +03:00
/**
* @ dataProvider searchDataProvider
*/
2020-01-05 23:27:41 +03:00
public function testSearch ( bool $isShared , array $searchOptions , int $count ) {
2017-11-07 03:31:28 +03:00
$calendarId = $this -> createTestCalendar ();
$uris = [];
$calData = [];
$uris [] = static :: getUniqueID ( 'calobj' );
$calData [] = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : Nextcloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8 - 1
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
$uris [] = static :: getUniqueID ( 'calobj' );
$calData [] = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : Nextcloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8 - 2
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : 123
LOCATION : Test
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
$uris [] = static :: getUniqueID ( 'calobj' );
$calData [] = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : Nextcloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8 - 3
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : 123
ATTENDEE ; CN = test : mailto : foo @ bar . com
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PRIVATE
END : VEVENT
END : VCALENDAR
EOD ;
$uris [] = static :: getUniqueID ( 'calobj' );
$calData [] = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : Nextcloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8 - 4
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : 123
ATTENDEE ; CN = foobar : mailto : test @ bar . com
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : CONFIDENTIAL
END : VEVENT
END : VCALENDAR
EOD ;
$uriCount = count ( $uris );
for ( $i = 0 ; $i < $uriCount ; $i ++ ) {
$this -> backend -> createCalendarObject ( $calendarId ,
$uris [ $i ], $calData [ $i ]);
}
$calendarInfo = [
'id' => $calendarId ,
'principaluri' => 'user1' ,
'{http://owncloud.org/ns}owner-principal' => $isShared ? 'user2' : 'user1' ,
];
$result = $this -> backend -> search ( $calendarInfo , 'Test' ,
2020-01-05 23:07:36 +03:00
[ 'SUMMARY' , 'LOCATION' , 'ATTENDEE' ], $searchOptions , null , null );
2017-11-07 03:31:28 +03:00
$this -> assertCount ( $count , $result );
}
public function searchDataProvider () {
return [
2020-01-05 23:27:41 +03:00
[ false , [], 4 ],
[ true , [ 'timerange' => [ 'start' => new DateTime ( '2013-09-12 13:00:00' ), 'end' => new DateTime ( '2013-09-12 14:00:00' )]], 2 ],
[ true , [ 'timerange' => [ 'start' => new DateTime ( '2013-09-12 15:00:00' ), 'end' => new DateTime ( '2013-09-12 16:00:00' )]], 0 ],
2017-11-07 03:31:28 +03:00
];
}
2018-06-28 14:07:33 +03:00
public function testSameUriSameIdForDifferentCalendarTypes () {
$calendarId = $this -> createTestCalendar ();
$subscriptionId = $this -> createTestSubscription ();
$uri = static :: getUniqueID ( 'calobj' );
$calData = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
$calData2 = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event 123
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
$this -> backend -> createCalendarObject ( $calendarId , $uri , $calData );
$this -> backend -> createCalendarObject ( $subscriptionId , $uri , $calData2 , CalDavBackend :: CALENDAR_TYPE_SUBSCRIPTION );
$this -> assertEquals ( $calData , $this -> backend -> getCalendarObject ( $calendarId , $uri , CalDavBackend :: CALENDAR_TYPE_CALENDAR )[ 'calendardata' ]);
$this -> assertEquals ( $calData2 , $this -> backend -> getCalendarObject ( $subscriptionId , $uri , CalDavBackend :: CALENDAR_TYPE_SUBSCRIPTION )[ 'calendardata' ]);
}
public function testPurgeAllCachedEventsForSubscription () {
$subscriptionId = $this -> createTestSubscription ();
$uri = static :: getUniqueID ( 'calobj' );
$calData = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID : ownCloud Calendar
BEGIN : VEVENT
CREATED ; VALUE = DATE - TIME : 20130910 T125139Z
UID : 47 d15e3ec8
LAST - MODIFIED ; VALUE = DATE - TIME : 20130910 T125139Z
DTSTAMP ; VALUE = DATE - TIME : 20130910 T125139Z
SUMMARY : Test Event
DTSTART ; VALUE = DATE - TIME : 20130912 T130000Z
DTEND ; VALUE = DATE - TIME : 20130912 T140000Z
CLASS : PUBLIC
END : VEVENT
END : VCALENDAR
EOD ;
$this -> backend -> createCalendarObject ( $subscriptionId , $uri , $calData , CalDavBackend :: CALENDAR_TYPE_SUBSCRIPTION );
$this -> backend -> purgeAllCachedEventsForSubscription ( $subscriptionId );
$this -> assertEquals ( null , $this -> backend -> getCalendarObject ( $subscriptionId , $uri , CalDavBackend :: CALENDAR_TYPE_SUBSCRIPTION ));
}
2017-07-26 13:33:32 +03:00
2020-04-10 15:19:56 +03:00
public function testCalendarMovement () {
2017-07-26 13:33:32 +03:00
$this -> backend -> createCalendar ( self :: UNIT_TEST_USER , 'Example' , []);
$this -> assertCount ( 1 , $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER ));
$calendarInfoUser = $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER )[ 0 ];
$this -> backend -> moveCalendar ( 'Example' , self :: UNIT_TEST_USER , self :: UNIT_TEST_USER1 );
$this -> assertCount ( 0 , $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER ));
$this -> assertCount ( 1 , $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER1 ));
$calendarInfoUser1 = $this -> backend -> getCalendarsForUser ( self :: UNIT_TEST_USER1 )[ 0 ];
$this -> assertEquals ( $calendarInfoUser [ 'id' ], $calendarInfoUser1 [ 'id' ]);
$this -> assertEquals ( $calendarInfoUser [ 'uri' ], $calendarInfoUser1 [ 'uri' ]);
}
2020-07-27 17:14:15 +03:00
public function testSearchPrincipal () : void {
$myPublic = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID :-// dmfs . org //mimedir.icalendar//EN
BEGIN : VTIMEZONE
TZID : Europe / Berlin
X - LIC - LOCATION : Europe / Berlin
BEGIN : DAYLIGHT
TZOFFSETFROM :+ 0100
TZOFFSETTO :+ 0200
TZNAME : CEST
DTSTART : 19700329 T020000
RRULE : FREQ = YEARLY ; BYMONTH = 3 ; BYDAY =- 1 SU
END : DAYLIGHT
BEGIN : STANDARD
TZOFFSETFROM :+ 0200
TZOFFSETTO :+ 0100
TZNAME : CET
DTSTART : 19701025 T030000
RRULE : FREQ = YEARLY ; BYMONTH = 10 ; BYDAY =- 1 SU
END : STANDARD
END : VTIMEZONE
BEGIN : VEVENT
DTSTART ; TZID = Europe / Berlin : 20160419 T130000
SUMMARY : My Test ( public )
CLASS : PUBLIC
TRANSP : OPAQUE
STATUS : CONFIRMED
DTEND ; TZID = Europe / Berlin : 20160419 T140000
LAST - MODIFIED : 20160419 T074202Z
DTSTAMP : 20160419 T074202Z
CREATED : 20160419 T074202Z
UID : 2e468 c48 - 7860 - 492 e - bc52 - 92 fa0daeeccf . 1461051722310 - 1
END : VEVENT
END : VCALENDAR
EOD ;
$myPrivate = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID :-// dmfs . org //mimedir.icalendar//EN
BEGIN : VTIMEZONE
TZID : Europe / Berlin
X - LIC - LOCATION : Europe / Berlin
BEGIN : DAYLIGHT
TZOFFSETFROM :+ 0100
TZOFFSETTO :+ 0200
TZNAME : CEST
DTSTART : 19700329 T020000
RRULE : FREQ = YEARLY ; BYMONTH = 3 ; BYDAY =- 1 SU
END : DAYLIGHT
BEGIN : STANDARD
TZOFFSETFROM :+ 0200
TZOFFSETTO :+ 0100
TZNAME : CET
DTSTART : 19701025 T030000
RRULE : FREQ = YEARLY ; BYMONTH = 10 ; BYDAY =- 1 SU
END : STANDARD
END : VTIMEZONE
BEGIN : VEVENT
DTSTART ; TZID = Europe / Berlin : 20160419 T130000
SUMMARY : My Test ( private )
CLASS : PRIVATE
TRANSP : OPAQUE
STATUS : CONFIRMED
DTEND ; TZID = Europe / Berlin : 20160419 T140000
LAST - MODIFIED : 20160419 T074202Z
DTSTAMP : 20160419 T074202Z
CREATED : 20160419 T074202Z
UID : 2e468 c48 - 7860 - 492 e - bc52 - 92 fa0daeeccf . 1461051722310 - 2
END : VEVENT
END : VCALENDAR
EOD ;
$myConfidential = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID :-// dmfs . org //mimedir.icalendar//EN
BEGIN : VTIMEZONE
TZID : Europe / Berlin
X - LIC - LOCATION : Europe / Berlin
BEGIN : DAYLIGHT
TZOFFSETFROM :+ 0100
TZOFFSETTO :+ 0200
TZNAME : CEST
DTSTART : 19700329 T020000
RRULE : FREQ = YEARLY ; BYMONTH = 3 ; BYDAY =- 1 SU
END : DAYLIGHT
BEGIN : STANDARD
TZOFFSETFROM :+ 0200
TZOFFSETTO :+ 0100
TZNAME : CET
DTSTART : 19701025 T030000
RRULE : FREQ = YEARLY ; BYMONTH = 10 ; BYDAY =- 1 SU
END : STANDARD
END : VTIMEZONE
BEGIN : VEVENT
DTSTART ; TZID = Europe / Berlin : 20160419 T130000
SUMMARY : My Test ( confidential )
CLASS : CONFIDENTIAL
TRANSP : OPAQUE
STATUS : CONFIRMED
DTEND ; TZID = Europe / Berlin : 20160419 T140000
LAST - MODIFIED : 20160419 T074202Z
DTSTAMP : 20160419 T074202Z
CREATED : 20160419 T074202Z
UID : 2e468 c48 - 7860 - 492 e - bc52 - 92 fa0daeeccf . 1461051722310 - 3
END : VEVENT
END : VCALENDAR
EOD ;
$sharerPublic = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID :-// dmfs . org //mimedir.icalendar//EN
BEGIN : VTIMEZONE
TZID : Europe / Berlin
X - LIC - LOCATION : Europe / Berlin
BEGIN : DAYLIGHT
TZOFFSETFROM :+ 0100
TZOFFSETTO :+ 0200
TZNAME : CEST
DTSTART : 19700329 T020000
RRULE : FREQ = YEARLY ; BYMONTH = 3 ; BYDAY =- 1 SU
END : DAYLIGHT
BEGIN : STANDARD
TZOFFSETFROM :+ 0200
TZOFFSETTO :+ 0100
TZNAME : CET
DTSTART : 19701025 T030000
RRULE : FREQ = YEARLY ; BYMONTH = 10 ; BYDAY =- 1 SU
END : STANDARD
END : VTIMEZONE
BEGIN : VEVENT
DTSTART ; TZID = Europe / Berlin : 20160419 T130000
SUMMARY : Sharer Test ( public )
CLASS : PUBLIC
TRANSP : OPAQUE
STATUS : CONFIRMED
DTEND ; TZID = Europe / Berlin : 20160419 T140000
LAST - MODIFIED : 20160419 T074202Z
DTSTAMP : 20160419 T074202Z
CREATED : 20160419 T074202Z
UID : 2e468 c48 - 7860 - 492 e - bc52 - 92 fa0daeeccf . 1461051722310 - 4
END : VEVENT
END : VCALENDAR
EOD ;
$sharerPrivate = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID :-// dmfs . org //mimedir.icalendar//EN
BEGIN : VTIMEZONE
TZID : Europe / Berlin
X - LIC - LOCATION : Europe / Berlin
BEGIN : DAYLIGHT
TZOFFSETFROM :+ 0100
TZOFFSETTO :+ 0200
TZNAME : CEST
DTSTART : 19700329 T020000
RRULE : FREQ = YEARLY ; BYMONTH = 3 ; BYDAY =- 1 SU
END : DAYLIGHT
BEGIN : STANDARD
TZOFFSETFROM :+ 0200
TZOFFSETTO :+ 0100
TZNAME : CET
DTSTART : 19701025 T030000
RRULE : FREQ = YEARLY ; BYMONTH = 10 ; BYDAY =- 1 SU
END : STANDARD
END : VTIMEZONE
BEGIN : VEVENT
DTSTART ; TZID = Europe / Berlin : 20160419 T130000
SUMMARY : Sharer Test ( private )
CLASS : PRIVATE
TRANSP : OPAQUE
STATUS : CONFIRMED
DTEND ; TZID = Europe / Berlin : 20160419 T140000
LAST - MODIFIED : 20160419 T074202Z
DTSTAMP : 20160419 T074202Z
CREATED : 20160419 T074202Z
UID : 2e468 c48 - 7860 - 492 e - bc52 - 92 fa0daeeccf . 1461051722310 - 5
END : VEVENT
END : VCALENDAR
EOD ;
$sharerConfidential = <<< EOD
BEGIN : VCALENDAR
VERSION : 2.0
PRODID :-// dmfs . org //mimedir.icalendar//EN
BEGIN : VTIMEZONE
TZID : Europe / Berlin
X - LIC - LOCATION : Europe / Berlin
BEGIN : DAYLIGHT
TZOFFSETFROM :+ 0100
TZOFFSETTO :+ 0200
TZNAME : CEST
DTSTART : 19700329 T020000
RRULE : FREQ = YEARLY ; BYMONTH = 3 ; BYDAY =- 1 SU
END : DAYLIGHT
BEGIN : STANDARD
TZOFFSETFROM :+ 0200
TZOFFSETTO :+ 0100
TZNAME : CET
DTSTART : 19701025 T030000
RRULE : FREQ = YEARLY ; BYMONTH = 10 ; BYDAY =- 1 SU
END : STANDARD
END : VTIMEZONE
BEGIN : VEVENT
DTSTART ; TZID = Europe / Berlin : 20160419 T130000
SUMMARY : Sharer Test ( confidential )
CLASS : CONFIDENTIAL
TRANSP : OPAQUE
STATUS : CONFIRMED
DTEND ; TZID = Europe / Berlin : 20160419 T140000
LAST - MODIFIED : 20160419 T074202Z
DTSTAMP : 20160419 T074202Z
CREATED : 20160419 T074202Z
UID : 2e468 c48 - 7860 - 492 e - bc52 - 92 fa0daeeccf . 1461051722310 - 6
END : VEVENT
END : VCALENDAR
EOD ;
$l10n = $this -> createMock ( IL10N :: class );
$l10n
-> expects ( $this -> any ())
-> method ( 't' )
-> willReturnCallback ( function ( $text , $parameters = []) {
return vsprintf ( $text , $parameters );
});
$config = $this -> createMock ( IConfig :: class );
$this -> userManager -> expects ( $this -> any ())
-> method ( 'userExists' )
-> willReturn ( true );
$this -> groupManager -> expects ( $this -> any ())
-> method ( 'groupExists' )
-> willReturn ( true );
$me = self :: UNIT_TEST_USER ;
$sharer = self :: UNIT_TEST_USER1 ;
$this -> backend -> createCalendar ( $me , 'calendar-uri-me' , []);
$this -> backend -> createCalendar ( $sharer , 'calendar-uri-sharer' , []);
$myCalendars = $this -> backend -> getCalendarsForUser ( $me );
$this -> assertCount ( 1 , $myCalendars );
$sharerCalendars = $this -> backend -> getCalendarsForUser ( $sharer );
$this -> assertCount ( 1 , $sharerCalendars );
$sharerCalendar = new Calendar ( $this -> backend , $sharerCalendars [ 0 ], $l10n , $config );
$this -> backend -> updateShares ( $sharerCalendar , [
[
'href' => 'principal:' . $me ,
'readOnly' => false ,
],
], []);
$this -> assertCount ( 2 , $this -> backend -> getCalendarsForUser ( $me ));
$this -> backend -> createCalendarObject ( $myCalendars [ 0 ][ 'id' ], 'event0.ics' , $myPublic );
$this -> backend -> createCalendarObject ( $myCalendars [ 0 ][ 'id' ], 'event1.ics' , $myPrivate );
$this -> backend -> createCalendarObject ( $myCalendars [ 0 ][ 'id' ], 'event2.ics' , $myConfidential );
$this -> backend -> createCalendarObject ( $sharerCalendars [ 0 ][ 'id' ], 'event3.ics' , $sharerPublic );
$this -> backend -> createCalendarObject ( $sharerCalendars [ 0 ][ 'id' ], 'event4.ics' , $sharerPrivate );
$this -> backend -> createCalendarObject ( $sharerCalendars [ 0 ][ 'id' ], 'event5.ics' , $sharerConfidential );
$mySearchResults = $this -> backend -> searchPrincipalUri ( $me , 'Test' , [ 'VEVENT' ], [ 'SUMMARY' ], []);
$sharerSearchResults = $this -> backend -> searchPrincipalUri ( $sharer , 'Test' , [ 'VEVENT' ], [ 'SUMMARY' ], []);
$this -> assertCount ( 4 , $mySearchResults );
$this -> assertCount ( 3 , $sharerSearchResults );
$this -> assertEquals ( $myPublic , $mySearchResults [ 0 ][ 'calendardata' ]);
$this -> assertEquals ( $myPrivate , $mySearchResults [ 1 ][ 'calendardata' ]);
$this -> assertEquals ( $myConfidential , $mySearchResults [ 2 ][ 'calendardata' ]);
$this -> assertEquals ( $sharerPublic , $mySearchResults [ 3 ][ 'calendardata' ]);
$this -> assertEquals ( $sharerPublic , $sharerSearchResults [ 0 ][ 'calendardata' ]);
$this -> assertEquals ( $sharerPrivate , $sharerSearchResults [ 1 ][ 'calendardata' ]);
$this -> assertEquals ( $sharerConfidential , $sharerSearchResults [ 2 ][ 'calendardata' ]);
}
2015-10-31 03:28:21 +03:00
}