2018-03-08 16:44:02 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2019-12-03 21:57:53 +03:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2018-03-08 16:44:02 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
2018-03-08 16:44:02 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2018-03-08 16:44:02 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2019-12-03 21:57:53 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-03-08 16:44:02 +03:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-03-08 16:44:02 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\Tests\Command;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
2019-01-15 15:59:54 +03:00
|
|
|
/** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
|
2018-03-08 16:44:02 +03:00
|
|
|
private $userManager;
|
|
|
|
|
2019-01-15 15:59:54 +03:00
|
|
|
/** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject $l10n */
|
2018-03-08 16:44:02 +03:00
|
|
|
private $calDav;
|
|
|
|
|
|
|
|
/** @var ListCalendars */
|
|
|
|
private $command;
|
|
|
|
|
2020-04-10 17:54:27 +03:00
|
|
|
public const USERNAME = 'username';
|
2018-03-08 16:44:02 +03:00
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2018-03-08 16:44:02 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
$this->calDav = $this->createMock(CalDavBackend::class);
|
|
|
|
|
|
|
|
$this->command = new ListCalendars(
|
|
|
|
$this->userManager,
|
|
|
|
$this->calDav
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
public function testWithBadUser() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2018-03-08 16:44:02 +03:00
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with(self::USERNAME)
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$commandTester = new CommandTester($this->command);
|
|
|
|
$commandTester->execute([
|
2019-01-15 15:59:54 +03:00
|
|
|
'uid' => self::USERNAME,
|
2018-03-08 16:44:02 +03:00
|
|
|
]);
|
|
|
|
$this->assertContains("User <" . self::USERNAME . "> in unknown", $commandTester->getDisplay());
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
public function testWithCorrectUserWithNoCalendars() {
|
2018-03-08 16:44:02 +03:00
|
|
|
$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([
|
2019-01-15 15:59:54 +03:00
|
|
|
'uid' => self::USERNAME,
|
2018-03-08 16:44:02 +03:00
|
|
|
]);
|
|
|
|
$this->assertContains("User <" . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay());
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
public function dataExecute() {
|
2018-03-08 16:44:02 +03:00
|
|
|
return [
|
|
|
|
[false, '✓'],
|
|
|
|
[true, 'x']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataExecute
|
|
|
|
*/
|
2020-04-10 15:19:56 +03:00
|
|
|
public function testWithCorrectUser(bool $readOnly, string $output) {
|
2018-03-08 16:44:02 +03:00
|
|
|
$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([
|
2019-01-15 15:59:54 +03:00
|
|
|
'uid' => self::USERNAME,
|
2018-03-08 16:44:02 +03:00
|
|
|
]);
|
|
|
|
$this->assertContains($output, $commandTester->getDisplay());
|
|
|
|
$this->assertNotContains(BirthdayService::BIRTHDAY_CALENDAR_URI, $commandTester->getDisplay());
|
|
|
|
}
|
|
|
|
}
|