2016-01-11 12:09:00 -05:00
|
|
|
<?php
|
2024-05-28 06:34:11 -04:00
|
|
|
|
2025-05-25 16:22:57 -04:00
|
|
|
declare(strict_types=1);
|
2016-01-11 12:09:00 -05:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-01-11 12:09:00 -05:00
|
|
|
*/
|
2016-05-25 10:04:15 -04:00
|
|
|
namespace OCA\DAV\Tests\unit\Comments;
|
2016-01-11 12:09:00 -05:00
|
|
|
|
2019-10-16 06:36:03 -04:00
|
|
|
use OC\EventDispatcher\EventDispatcher;
|
2016-01-11 12:09:00 -05:00
|
|
|
use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\DAV\Comments\RootCollection;
|
2016-02-25 03:08:12 -05:00
|
|
|
use OCP\Comments\CommentsEntityEvent;
|
2017-10-24 09:26:53 -04:00
|
|
|
use OCP\Comments\ICommentsManager;
|
2023-07-11 05:06:29 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2017-10-24 09:26:53 -04:00
|
|
|
use OCP\IUser;
|
|
|
|
|
use OCP\IUserManager;
|
|
|
|
|
use OCP\IUserSession;
|
2025-05-25 16:22:57 -04:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2020-10-08 10:48:03 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2016-01-11 12:09:00 -05:00
|
|
|
|
2016-05-25 10:04:15 -04:00
|
|
|
class RootCollectionTest extends \Test\TestCase {
|
2025-05-25 16:22:57 -04:00
|
|
|
protected ICommentsManager&MockObject $commentsManager;
|
|
|
|
|
protected IUserManager&MockObject $userManager;
|
|
|
|
|
protected LoggerInterface&MockObject $logger;
|
|
|
|
|
protected IUserSession&MockObject $userSession;
|
|
|
|
|
protected IEventDispatcher $dispatcher;
|
|
|
|
|
protected IUser&MockObject $user;
|
|
|
|
|
protected RootCollection $collection;
|
2016-01-11 12:09:00 -05:00
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2025-05-25 16:22:57 -04:00
|
|
|
$this->user = $this->createMock(IUser::class);
|
|
|
|
|
|
|
|
|
|
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
2023-07-11 05:06:29 -04:00
|
|
|
$this->dispatcher = new EventDispatcher(
|
|
|
|
|
new \Symfony\Component\EventDispatcher\EventDispatcher(),
|
|
|
|
|
\OC::$server,
|
2022-03-22 07:41:30 -04:00
|
|
|
$this->logger
|
2019-10-16 06:36:03 -04:00
|
|
|
);
|
2016-01-11 12:09:00 -05:00
|
|
|
|
2024-10-10 06:40:31 -04:00
|
|
|
$this->collection = new RootCollection(
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->commentsManager,
|
|
|
|
|
$this->userManager,
|
|
|
|
|
$this->userSession,
|
2016-02-25 03:08:12 -05:00
|
|
|
$this->dispatcher,
|
2022-03-31 09:34:57 -04:00
|
|
|
$this->logger
|
2016-01-11 12:09:00 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-25 16:22:57 -04:00
|
|
|
protected function prepareForInitCollections(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->user->expects($this->any())
|
|
|
|
|
->method('getUID')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn('alice');
|
2016-01-11 12:09:00 -05:00
|
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
|
->method('getUser')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($this->user);
|
2016-01-11 12:09:00 -05:00
|
|
|
|
2023-07-11 05:06:29 -04:00
|
|
|
$this->dispatcher->addListener(CommentsEntityEvent::class, function (CommentsEntityEvent $event): void {
|
2020-04-09 07:53:40 -04:00
|
|
|
$event->addEntityCollection('files', function () {
|
2016-02-25 03:08:12 -05:00
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-01-11 12:09:00 -05:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testCreateFile(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
|
|
|
|
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->collection->createFile('foo');
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testCreateDirectory(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
|
|
|
|
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->collection->createDirectory('foo');
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetChild(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->prepareForInitCollections();
|
|
|
|
|
$etc = $this->collection->getChild('files');
|
2025-05-25 16:22:57 -04:00
|
|
|
$this->assertInstanceOf(EntityTypeCollectionImplementation::class, $etc);
|
2016-01-11 12:09:00 -05:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetChildInvalid(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
|
|
|
|
|
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->prepareForInitCollections();
|
|
|
|
|
$this->collection->getChild('robots');
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetChildNoAuth(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);
|
|
|
|
|
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->collection->getChild('files');
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetChildren(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->prepareForInitCollections();
|
|
|
|
|
$children = $this->collection->getChildren();
|
|
|
|
|
$this->assertFalse(empty($children));
|
|
|
|
|
foreach ($children as $child) {
|
2025-05-25 16:22:57 -04:00
|
|
|
$this->assertInstanceOf(EntityTypeCollectionImplementation::class, $child);
|
2016-01-11 12:09:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetChildrenNoAuth(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);
|
|
|
|
|
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->collection->getChildren();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testChildExistsYes(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->prepareForInitCollections();
|
|
|
|
|
$this->assertTrue($this->collection->childExists('files'));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testChildExistsNo(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->prepareForInitCollections();
|
|
|
|
|
$this->assertFalse($this->collection->childExists('robots'));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testChildExistsNoAuth(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);
|
|
|
|
|
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->collection->childExists('files');
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testDelete(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
|
|
|
|
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->collection->delete();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetName(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->assertSame('comments', $this->collection->getName());
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testSetName(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
|
|
|
|
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->collection->setName('foobar');
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetLastModified(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->assertSame(null, $this->collection->getLastModified());
|
|
|
|
|
}
|
|
|
|
|
}
|