Signed-off-by: Georg Ehrke <developer@georgehrke.com> Rebase and delete URI suggestion part Invite to use occ dav:list-calendars instead Signed-off-by: Thomas Citharel <tcit@tcit.fr> Fix autoload Signed-off-by: Thomas Citharel <tcit@tcit.fr> Use injection & test everything And rebase Signed-off-by: Thomas Citharel <tcit@tcit.fr> Add test for ListCalendars and refactoring Signed-off-by: Thomas Citharel <tcit@tcit.fr> Fix indentation Signed-off-by: Thomas Citharel <tcit@tcit.fr>tags/v16.0.0alpha1
@@ -42,6 +42,7 @@ | |||
<command>OCA\DAV\Command\CreateAddressBook</command> | |||
<command>OCA\DAV\Command\CreateCalendar</command> | |||
<command>OCA\DAV\Command\MoveCalendar</command> | |||
<command>OCA\DAV\Command\ListCalendars</command> | |||
<command>OCA\DAV\Command\SyncBirthdayCalendar</command> | |||
<command>OCA\DAV\Command\SyncSystemAddressBook</command> | |||
<command>OCA\DAV\Command\RemoveInvalidShares</command> |
@@ -79,6 +79,8 @@ return array( | |||
'OCA\\DAV\\CardDAV\\Xml\\Groups' => $baseDir . '/../lib/CardDAV/Xml/Groups.php', | |||
'OCA\\DAV\\Command\\CreateAddressBook' => $baseDir . '/../lib/Command/CreateAddressBook.php', | |||
'OCA\\DAV\\Command\\CreateCalendar' => $baseDir . '/../lib/Command/CreateCalendar.php', | |||
'OCA\\DAV\\Command\\ListCalendars' => $baseDir . '/../lib/Command/ListCalendars.php', | |||
'OCA\\DAV\\Command\\MoveCalendar' => $baseDir . '/../lib/Command/MoveCalendar.php', | |||
'OCA\\DAV\\Command\\RemoveInvalidShares' => $baseDir . '/../lib/Command/RemoveInvalidShares.php', | |||
'OCA\\DAV\\Command\\SyncBirthdayCalendar' => $baseDir . '/../lib/Command/SyncBirthdayCalendar.php', | |||
'OCA\\DAV\\Command\\SyncSystemAddressBook' => $baseDir . '/../lib/Command/SyncSystemAddressBook.php', |
@@ -94,6 +94,8 @@ class ComposerStaticInitDAV | |||
'OCA\\DAV\\CardDAV\\Xml\\Groups' => __DIR__ . '/..' . '/../lib/CardDAV/Xml/Groups.php', | |||
'OCA\\DAV\\Command\\CreateAddressBook' => __DIR__ . '/..' . '/../lib/Command/CreateAddressBook.php', | |||
'OCA\\DAV\\Command\\CreateCalendar' => __DIR__ . '/..' . '/../lib/Command/CreateCalendar.php', | |||
'OCA\\DAV\\Command\\ListCalendars' => __DIR__ . '/..' . '/../lib/Command/ListCalendars.php', | |||
'OCA\\DAV\\Command\\MoveCalendar' => __DIR__ . '/..' . '/../lib/Command/MoveCalendar.php', | |||
'OCA\\DAV\\Command\\RemoveInvalidShares' => __DIR__ . '/..' . '/../lib/Command/RemoveInvalidShares.php', | |||
'OCA\\DAV\\Command\\SyncBirthdayCalendar' => __DIR__ . '/..' . '/../lib/Command/SyncBirthdayCalendar.php', | |||
'OCA\\DAV\\Command\\SyncSystemAddressBook' => __DIR__ . '/..' . '/../lib/Command/SyncSystemAddressBook.php', |
@@ -2538,32 +2538,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription | |||
->execute(); | |||
} | |||
/** | |||
* @param string $displayName | |||
* @param string|null $principalUri | |||
* @return array | |||
*/ | |||
public function findCalendarsUrisByDisplayName($displayName, $principalUri = null) | |||
{ | |||
// Ideally $displayName would be sanitized the same way as stringUtility.js does in calendar | |||
$query = $this->db->getQueryBuilder(); | |||
$query->select('uri') | |||
->from('calendars') | |||
->where($query->expr()->iLike('displayname', | |||
$query->createNamedParameter('%'.$this->db->escapeLikeParameter($displayName).'%'))); | |||
if ($principalUri) { | |||
$query->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); | |||
} | |||
$result = $query->execute(); | |||
$calendarUris = []; | |||
while($row = $result->fetch()) { | |||
$calendarUris[] = $row['uri']; | |||
} | |||
return $calendarUris; | |||
} | |||
/** | |||
* read VCalendar data into a VCalendar object | |||
* |
@@ -0,0 +1,108 @@ | |||
<?php | |||
/** | |||
* @copyright Copyright (c) 2018, Georg Ehrke | |||
* | |||
* @author Georg Ehrke <oc.list@georgehrke.com> | |||
* @author Thomas Citharel <tcit@tcit.fr> | |||
* | |||
* @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\Command; | |||
use OCA\DAV\CalDAV\BirthdayService; | |||
use OCA\DAV\CalDAV\CalDavBackend; | |||
use OCA\DAV\Connector\Sabre\Principal; | |||
use OCP\IConfig; | |||
use OCP\IDBConnection; | |||
use OCP\IGroupManager; | |||
use OCP\IUserManager; | |||
use OCP\IUserSession; | |||
use OCP\Share\IManager; | |||
use Symfony\Component\Console\Command\Command; | |||
use Symfony\Component\Console\Helper\Table; | |||
use Symfony\Component\Console\Input\InputArgument; | |||
use Symfony\Component\Console\Input\InputInterface; | |||
use Symfony\Component\Console\Output\OutputInterface; | |||
class ListCalendars extends Command { | |||
/** @var IUserManager */ | |||
protected $userManager; | |||
/** @var CalDavBackend */ | |||
private $caldav; | |||
/** | |||
* @param IUserManager $userManager | |||
* @param CalDavBackend $caldav | |||
*/ | |||
function __construct(IUserManager $userManager, CalDavBackend $caldav) { | |||
parent::__construct(); | |||
$this->userManager = $userManager; | |||
$this->caldav = $caldav; | |||
} | |||
protected function configure() { | |||
$this | |||
->setName('dav:list-calendars') | |||
->setDescription('List all calendars of a user') | |||
->addArgument('user', | |||
InputArgument::REQUIRED, | |||
'User for whom all calendars will be listed'); | |||
} | |||
protected function execute(InputInterface $input, OutputInterface $output) { | |||
$user = $input->getArgument('user'); | |||
if (!$this->userManager->userExists($user)) { | |||
throw new \InvalidArgumentException("User <$user> is unknown."); | |||
} | |||
$calendars = $this->caldav->getCalendarsForUser("principals/users/$user"); | |||
$calendarTableData = []; | |||
foreach($calendars as $calendar) { | |||
// skip birthday calendar | |||
if ($calendar['uri'] === BirthdayService::BIRTHDAY_CALENDAR_URI) { | |||
continue; | |||
} | |||
$readOnly = false; | |||
$readOnlyIndex = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; | |||
if (isset($calendar[$readOnlyIndex])) { | |||
$readOnly = $calendar[$readOnlyIndex]; | |||
} | |||
$calendarTableData[] = [ | |||
$calendar['uri'], | |||
$calendar['{DAV:}displayname'], | |||
$calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'], | |||
$calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'], | |||
$readOnly ? ' x ' : ' ✓ ', | |||
]; | |||
} | |||
if (count($calendarTableData) > 0) { | |||
$table = new Table($output); | |||
$table->setHeaders(['uri', 'displayname', 'owner\'s userid', 'owner\'s displayname', 'writable']) | |||
->setRows($calendarTableData); | |||
$table->render(); | |||
} else { | |||
$output->writeln("<info>User <$user> has no calendars</info>"); | |||
} | |||
} | |||
} |
@@ -22,10 +22,13 @@ namespace OCA\DAV\Command; | |||
use OCA\DAV\CalDAV\CalDavBackend; | |||
use OCA\DAV\CalDAV\Calendar; | |||
use OCA\DAV\Connector\Sabre\Principal; | |||
use OCP\IConfig; | |||
use OCP\IDBConnection; | |||
use OCP\IGroupManager; | |||
use OCP\IL10N; | |||
use OCP\IUserManager; | |||
use OCP\IUserSession; | |||
use OCP\Share\IManager; | |||
use Symfony\Component\Console\Command\Command; | |||
use Symfony\Component\Console\Input\InputArgument; | |||
use Symfony\Component\Console\Input\InputInterface; | |||
@@ -36,37 +39,45 @@ use Symfony\Component\Console\Style\SymfonyStyle; | |||
class MoveCalendar extends Command { | |||
/** @var IUserManager */ | |||
protected $userManager; | |||
private $userManager; | |||
/** @var IGroupManager $groupManager */ | |||
private $groupManager; | |||
/** @var \OCP\IDBConnection */ | |||
protected $dbConnection; | |||
/** @var IConfig $config */ | |||
private $config; | |||
/** @var IL10N */ | |||
protected $l10n; | |||
private $l10n; | |||
/** @var SymfonyStyle */ | |||
private $io; | |||
/** @var CalDavBackend */ | |||
private $caldav; | |||
private $calDav; | |||
const URI_USERS = 'principals/users/'; | |||
/** | |||
* @param IUserManager $userManager | |||
* @param IGroupManager $groupManager | |||
* @param IDBConnection $dbConnection | |||
* @param IConfig $config | |||
* @param IL10N $l10n | |||
* @param CalDavBackend $calDav | |||
*/ | |||
function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection, IL10N $l10n) { | |||
function __construct( | |||
IUserManager $userManager, | |||
IGroupManager $groupManager, | |||
IConfig $config, | |||
IL10N $l10n, | |||
CalDavBackend $calDav | |||
) { | |||
parent::__construct(); | |||
$this->userManager = $userManager; | |||
$this->groupManager = $groupManager; | |||
$this->dbConnection = $dbConnection; | |||
$this->config = $config; | |||
$this->l10n = $l10n; | |||
$this->calDav = $calDav; | |||
} | |||
protected function configure() { | |||
@@ -104,35 +115,21 @@ class MoveCalendar extends Command { | |||
throw new \InvalidArgumentException("User <$userDestination> is unknown."); | |||
} | |||
$principalBackend = new Principal( | |||
$this->userManager, | |||
$this->groupManager | |||
); | |||
$random = \OC::$server->getSecureRandom(); | |||
$dispatcher = \OC::$server->getEventDispatcher(); | |||
$name = $input->getArgument('name'); | |||
$this->caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $random, $dispatcher); | |||
$calendar = $this->caldav->getCalendarByUri(self::URI_USERS . $userOrigin, $name); | |||
$calendar = $this->calDav->getCalendarByUri(self::URI_USERS . $userOrigin, $name); | |||
if (null === $calendar) { | |||
/** If we got no matching calendar with URI, let's try the display names */ | |||
$suggestedUris = $this->caldav->findCalendarsUrisByDisplayName($name, self::URI_USERS . $userOrigin); | |||
if (count($suggestedUris) > 0) { | |||
$this->io->note('No calendar with this URI was found, but you may want to try with these?'); | |||
$this->io->listing($suggestedUris); | |||
} | |||
throw new \InvalidArgumentException("User <$userOrigin> has no calendar named <$name>."); | |||
throw new \InvalidArgumentException("User <$userOrigin> has no calendar named <$name>. You can run occ dav:list-calendars to list calendars URIs for this user."); | |||
} | |||
if (null !== $this->caldav->getCalendarByUri(self::URI_USERS . $userDestination, $name)) { | |||
if (null !== $this->calDav->getCalendarByUri(self::URI_USERS . $userDestination, $name)) { | |||
throw new \InvalidArgumentException("User <$userDestination> already has a calendar named <$name>."); | |||
} | |||
$this->checkShares($calendar, $userDestination, $input->getOption('force')); | |||
$this->caldav->moveCalendar($name, self::URI_USERS . $userOrigin, self::URI_USERS . $userDestination); | |||
$this->calDav->moveCalendar($name, self::URI_USERS . $userOrigin, self::URI_USERS . $userDestination); | |||
$this->io->success("Calendar <$name> was moved from user <$userOrigin> to <$userDestination>"); | |||
} | |||
@@ -147,14 +144,14 @@ class MoveCalendar extends Command { | |||
*/ | |||
private function checkShares($calendar, $userDestination, $force = false) | |||
{ | |||
$shares = $this->caldav->getShares($calendar['id']); | |||
$shares = $this->calDav->getShares($calendar['id']); | |||
foreach ($shares as $share) { | |||
list($prefix, $group) = str_split($share['href'], 28); | |||
if ('principal:principals/groups/' === $prefix && !$this->groupManager->isInGroup($userDestination, $group)) { | |||
list(, $prefix, $group) = explode('/', $share['href'], 3); | |||
if ('groups' === $prefix && !$this->groupManager->isInGroup($userDestination, $group)) { | |||
if ($force) { | |||
$this->caldav->updateShares(new Calendar($this->caldav, $calendar, $this->l10n), [], ['href' => 'principal:principals/groups/' . $group]); | |||
$this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/groups/' . $group]); | |||
} else { | |||
throw new \InvalidArgumentException("User <$userDestination> is not part of the group <$group> with which the calendar <" . $calendar['uri'] . "> was shared. You may use -f to move the calendar while deleting this share."); | |||
throw new \InvalidArgumentException("User <$userDestination> is not part of the group <$group> with whom the calendar <" . $calendar['uri'] . "> was shared. You may use -f to move the calendar while deleting this share."); | |||
} | |||
} | |||
} |
@@ -0,0 +1,139 @@ | |||
<?php | |||
/** | |||
* @author Thomas Citharel <tcit@tcit.fr> | |||
* | |||
* @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\Command; | |||
use InvalidArgumentException; | |||
use OCA\DAV\CalDAV\BirthdayService; | |||
use OCA\DAV\CalDAV\CalDavBackend; | |||
use OCA\DAV\Command\ListCalendars; | |||
use OCP\IUserManager; | |||
use Symfony\Component\Console\Tester\CommandTester; | |||
use Test\TestCase; | |||
/** | |||
* Class ListCalendarsTest | |||
* | |||
* @package OCA\DAV\Tests\Command | |||
*/ | |||
class ListCalendarsTest extends TestCase { | |||
/** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */ | |||
private $userManager; | |||
/** @var CalDavBackend|\PHPUnit_Framework_MockObject_MockObject $l10n */ | |||
private $calDav; | |||
/** @var ListCalendars */ | |||
private $command; | |||
const USERNAME = 'username'; | |||
protected function setUp() { | |||
parent::setUp(); | |||
$this->userManager = $this->createMock(IUserManager::class); | |||
$this->calDav = $this->createMock(CalDavBackend::class); | |||
$this->command = new ListCalendars( | |||
$this->userManager, | |||
$this->calDav | |||
); | |||
} | |||
/** | |||
* @expectedException InvalidArgumentException | |||
*/ | |||
public function testWithBadUser() | |||
{ | |||
$this->userManager->expects($this->once()) | |||
->method('userExists') | |||
->with(self::USERNAME) | |||
->willReturn(false); | |||
$commandTester = new CommandTester($this->command); | |||
$commandTester->execute([ | |||
'user' => self::USERNAME, | |||
]); | |||
$this->assertContains("User <" . self::USERNAME . "> in unknown", $commandTester->getDisplay()); | |||
} | |||
public function testWithCorrectUserWithNoCalendars() | |||
{ | |||
$this->userManager->expects($this->once()) | |||
->method('userExists') | |||
->with(self::USERNAME) | |||
->willReturn(true); | |||
$this->calDav->expects($this->once()) | |||
->method('getCalendarsForUser') | |||
->with('principals/users/' . self::USERNAME) | |||
->willReturn([]); | |||
$commandTester = new CommandTester($this->command); | |||
$commandTester->execute([ | |||
'user' => self::USERNAME, | |||
]); | |||
$this->assertContains("User <" . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay()); | |||
} | |||
public function dataExecute() | |||
{ | |||
return [ | |||
[false, '✓'], | |||
[true, 'x'] | |||
]; | |||
} | |||
/** | |||
* @dataProvider dataExecute | |||
*/ | |||
public function testWithCorrectUser(bool $readOnly, string $output) | |||
{ | |||
$this->userManager->expects($this->once()) | |||
->method('userExists') | |||
->with(self::USERNAME) | |||
->willReturn(true); | |||
$this->calDav->expects($this->once()) | |||
->method('getCalendarsForUser') | |||
->with('principals/users/' . self::USERNAME) | |||
->willReturn([ | |||
[ | |||
'uri' => BirthdayService::BIRTHDAY_CALENDAR_URI, | |||
], | |||
[ | |||
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $readOnly, | |||
'uri' => 'test', | |||
'{DAV:}displayname' => 'dp', | |||
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => 'owner-principal', | |||
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname' => 'owner-dp', | |||
] | |||
]); | |||
$commandTester = new CommandTester($this->command); | |||
$commandTester->execute([ | |||
'user' => self::USERNAME, | |||
]); | |||
$this->assertContains($output, $commandTester->getDisplay()); | |||
$this->assertNotContains(BirthdayService::BIRTHDAY_CALENDAR_URI, $commandTester->getDisplay()); | |||
} | |||
} |
@@ -21,8 +21,9 @@ | |||
namespace OCA\DAV\Tests\Command; | |||
use InvalidArgumentException; | |||
use OCA\DAV\CalDAV\CalDavBackend; | |||
use OCA\DAV\Command\MoveCalendar; | |||
use OCP\IDBConnection; | |||
use OCP\IConfig; | |||
use OCP\IGroupManager; | |||
use OCP\IL10N; | |||
use OCP\IUserManager; | |||
@@ -34,7 +35,6 @@ use Test\TestCase; | |||
* Class MoveCalendarTest | |||
* | |||
* @package OCA\DAV\Tests\Command | |||
* @group DB | |||
*/ | |||
class MoveCalendarTest extends TestCase { | |||
@@ -44,12 +44,15 @@ class MoveCalendarTest extends TestCase { | |||
/** @var \OCP\IGroupManager|\PHPUnit_Framework_MockObject_MockObject $groupManager */ | |||
private $groupManager; | |||
/** @var \OCP\IDBConnection|\PHPUnit_Framework_MockObject_MockObject $dbConnection */ | |||
private $dbConnection; | |||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject $l10n */ | |||
private $config; | |||
/** @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject $l10n */ | |||
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject $l10n */ | |||
private $l10n; | |||
/** @var CalDavBackend|\PHPUnit_Framework_MockObject_MockObject $l10n */ | |||
private $calDav; | |||
/** @var MoveCalendar */ | |||
private $command; | |||
@@ -58,14 +61,16 @@ class MoveCalendarTest extends TestCase { | |||
$this->userManager = $this->createMock(IUserManager::class); | |||
$this->groupManager = $this->createMock(IGroupManager::class); | |||
$this->dbConnection = $this->createMock(IDBConnection::class); | |||
$this->config = $this->createMock(IConfig::class); | |||
$this->l10n = $this->createMock(IL10N::class); | |||
$this->calDav = $this->createMock(CalDavBackend::class); | |||
$this->command = new MoveCalendar( | |||
$this->userManager, | |||
$this->groupManager, | |||
$this->dbConnection, | |||
$this->l10n | |||
$this->config, | |||
$this->l10n, | |||
$this->calDav | |||
); | |||
} | |||
@@ -118,4 +123,229 @@ class MoveCalendarTest extends TestCase { | |||
'userdestination' => 'user2', | |||
]); | |||
} | |||
} | |||
/** | |||
* @expectedException InvalidArgumentException | |||
* @expectedExceptionMessage User <user> has no calendar named <personal>. You can run occ dav:list-calendars to list calendars URIs for this user. | |||
*/ | |||
public function testMoveWithInexistantCalendar() | |||
{ | |||
$this->userManager->expects($this->at(0)) | |||
->method('userExists') | |||
->with('user') | |||
->willReturn(true); | |||
$this->userManager->expects($this->at(1)) | |||
->method('userExists') | |||
->with('user2') | |||
->willReturn(true); | |||
$this->calDav->expects($this->once())->method('getCalendarByUri') | |||
->with('principals/users/user', 'personal') | |||
->willReturn(null); | |||
$commandTester = new CommandTester($this->command); | |||
$commandTester->execute([ | |||
'name' => 'personal', | |||
'userorigin' => 'user', | |||
'userdestination' => 'user2', | |||
]); | |||
} | |||
/** | |||
* @expectedException InvalidArgumentException | |||
* @expectedExceptionMessage User <user2> already has a calendar named <personal>. | |||
*/ | |||
public function testMoveWithExistingDestinationCalendar() | |||
{ | |||
$this->userManager->expects($this->at(0)) | |||
->method('userExists') | |||
->with('user') | |||
->willReturn(true); | |||
$this->userManager->expects($this->at(1)) | |||
->method('userExists') | |||
->with('user2') | |||
->willReturn(true); | |||
$this->calDav->expects($this->at(0))->method('getCalendarByUri') | |||
->with('principals/users/user', 'personal') | |||
->willReturn([ | |||
'id' => 1234, | |||
]); | |||
$this->calDav->expects($this->at(1))->method('getCalendarByUri') | |||
->with('principals/users/user2', 'personal') | |||
->willReturn([ | |||
'id' => 1234, | |||
]); | |||
$commandTester = new CommandTester($this->command); | |||
$commandTester->execute([ | |||
'name' => 'personal', | |||
'userorigin' => 'user', | |||
'userdestination' => 'user2', | |||
]); | |||
} | |||
public function testMove() | |||
{ | |||
$this->userManager->expects($this->at(0)) | |||
->method('userExists') | |||
->with('user') | |||
->willReturn(true); | |||
$this->userManager->expects($this->at(1)) | |||
->method('userExists') | |||
->with('user2') | |||
->willReturn(true); | |||
$this->calDav->expects($this->at(0))->method('getCalendarByUri') | |||
->with('principals/users/user', 'personal') | |||
->willReturn([ | |||
'id' => 1234, | |||
]); | |||
$this->calDav->expects($this->at(1))->method('getCalendarByUri') | |||
->with('principals/users/user2', 'personal') | |||
->willReturn(null); | |||
$this->calDav->expects($this->once())->method('getShares') | |||
->with(1234) | |||
->willReturn([]); | |||
$commandTester = new CommandTester($this->command); | |||
$commandTester->execute([ | |||
'name' => 'personal', | |||
'userorigin' => 'user', | |||
'userdestination' => 'user2', | |||
]); | |||
$this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay()); | |||
} | |||
/** | |||
* @expectedException InvalidArgumentException | |||
* @expectedExceptionMessage User <user2> is not part of the group <nextclouders> with whom the calendar <personal> was shared. You may use -f to move the calendar while deleting this share. | |||
*/ | |||
public function testMoveWithDestinationNotPartOfGroup() | |||
{ | |||
$this->userManager->expects($this->at(0)) | |||
->method('userExists') | |||
->with('user') | |||
->willReturn(true); | |||
$this->userManager->expects($this->at(1)) | |||
->method('userExists') | |||
->with('user2') | |||
->willReturn(true); | |||
$this->calDav->expects($this->at(0))->method('getCalendarByUri') | |||
->with('principals/users/user', 'personal') | |||
->willReturn([ | |||
'id' => 1234, | |||
'uri' => 'personal' | |||
]); | |||
$this->calDav->expects($this->at(1))->method('getCalendarByUri') | |||
->with('principals/users/user2', 'personal') | |||
->willReturn(null); | |||
$this->calDav->expects($this->once())->method('getShares') | |||
->with(1234) | |||
->willReturn([ | |||
['href' => 'principal:principals/groups/nextclouders'] | |||
]); | |||
$commandTester = new CommandTester($this->command); | |||
$commandTester->execute([ | |||
'name' => 'personal', | |||
'userorigin' => 'user', | |||
'userdestination' => 'user2', | |||
]); | |||
} | |||
public function testMoveWithDestinationPartOfGroup() | |||
{ | |||
$this->userManager->expects($this->at(0)) | |||
->method('userExists') | |||
->with('user') | |||
->willReturn(true); | |||
$this->userManager->expects($this->at(1)) | |||
->method('userExists') | |||
->with('user2') | |||
->willReturn(true); | |||
$this->calDav->expects($this->at(0))->method('getCalendarByUri') | |||
->with('principals/users/user', 'personal') | |||
->willReturn([ | |||
'id' => 1234, | |||
'uri' => 'personal' | |||
]); | |||
$this->calDav->expects($this->at(1))->method('getCalendarByUri') | |||
->with('principals/users/user2', 'personal') | |||
->willReturn(null); | |||
$this->calDav->expects($this->once())->method('getShares') | |||
->with(1234) | |||
->willReturn([ | |||
['href' => 'principal:principals/groups/nextclouders'] | |||
]); | |||
$this->groupManager->expects($this->once())->method('isInGroup') | |||
->with('user2', 'nextclouders') | |||
->willReturn(true); | |||
$commandTester = new CommandTester($this->command); | |||
$commandTester->execute([ | |||
'name' => 'personal', | |||
'userorigin' => 'user', | |||
'userdestination' => 'user2', | |||
]); | |||
$this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay()); | |||
} | |||
public function testMoveWithDestinationNotPartOfGroupAndForce() | |||
{ | |||
$this->userManager->expects($this->at(0)) | |||
->method('userExists') | |||
->with('user') | |||
->willReturn(true); | |||
$this->userManager->expects($this->at(1)) | |||
->method('userExists') | |||
->with('user2') | |||
->willReturn(true); | |||
$this->calDav->expects($this->at(0))->method('getCalendarByUri') | |||
->with('principals/users/user', 'personal') | |||
->willReturn([ | |||
'id' => 1234, | |||
'uri' => 'personal', | |||
'{DAV:}displayname' => 'personal' | |||
]); | |||
$this->calDav->expects($this->at(1))->method('getCalendarByUri') | |||
->with('principals/users/user2', 'personal') | |||
->willReturn(null); | |||
$this->calDav->expects($this->once())->method('getShares') | |||
->with(1234) | |||
->willReturn([ | |||
['href' => 'principal:principals/groups/nextclouders'] | |||
]); | |||
$commandTester = new CommandTester($this->command); | |||
$commandTester->execute([ | |||
'name' => 'personal', | |||
'userorigin' => 'user', | |||
'userdestination' => 'user2', | |||
'--force' => true | |||
]); | |||
$this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay()); | |||
} | |||
} |