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
|
|
|
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\DAV\Comments\CommentNode;
|
2017-10-24 09:26:53 -04:00
|
|
|
use OCA\DAV\Comments\EntityCollection;
|
|
|
|
|
use OCP\Comments\IComment;
|
|
|
|
|
use OCP\Comments\ICommentsManager;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCP\Comments\NotFoundException;
|
2017-10-24 09:26:53 -04:00
|
|
|
use OCP\IUserManager;
|
|
|
|
|
use OCP\IUserSession;
|
2025-05-25 16:22:57 -04:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2022-03-31 09:34:57 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2017-10-24 09:26:53 -04:00
|
|
|
|
2016-05-25 10:04:15 -04:00
|
|
|
class EntityCollectionTest 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 EntityCollection $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->commentsManager = $this->createMock(ICommentsManager::class);
|
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
2016-01-11 12:09:00 -05:00
|
|
|
|
2024-10-10 06:40:31 -04:00
|
|
|
$this->collection = new EntityCollection(
|
2016-01-11 12:09:00 -05:00
|
|
|
'19',
|
|
|
|
|
'files',
|
|
|
|
|
$this->commentsManager,
|
|
|
|
|
$this->userManager,
|
2016-02-01 11:26:42 -05:00
|
|
|
$this->userSession,
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->logger
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetId(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->assertSame($this->collection->getId(), '19');
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetChild(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->commentsManager->expects($this->once())
|
|
|
|
|
->method('get')
|
|
|
|
|
->with('55')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn(
|
2017-10-24 09:26:53 -04:00
|
|
|
$this->getMockBuilder(IComment::class)
|
2016-07-15 03:52:46 -04:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock()
|
2020-03-25 17:21:27 -04:00
|
|
|
);
|
2016-01-11 12:09:00 -05:00
|
|
|
|
|
|
|
|
$node = $this->collection->getChild('55');
|
2025-05-25 16:22:57 -04:00
|
|
|
$this->assertInstanceOf(CommentNode::class, $node);
|
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 testGetChildException(): 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->commentsManager->expects($this->once())
|
|
|
|
|
->method('get')
|
|
|
|
|
->with('55')
|
2025-06-30 10:56:59 -04:00
|
|
|
->willThrowException(new NotFoundException());
|
2016-01-11 12:09:00 -05:00
|
|
|
|
|
|
|
|
$this->collection->getChild('55');
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetChildren(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->commentsManager->expects($this->once())
|
|
|
|
|
->method('getForObject')
|
|
|
|
|
->with('files', '19')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn([
|
2017-10-24 09:26:53 -04:00
|
|
|
$this->getMockBuilder(IComment::class)
|
2016-07-15 03:52:46 -04:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock()
|
2020-03-25 17:21:27 -04:00
|
|
|
]);
|
2016-01-11 12:09:00 -05:00
|
|
|
|
|
|
|
|
$result = $this->collection->getChildren();
|
|
|
|
|
|
2025-05-25 16:22:57 -04:00
|
|
|
$this->assertCount(1, $result);
|
|
|
|
|
$this->assertInstanceOf(CommentNode::class, $result[0]);
|
2016-01-11 12:09:00 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testFindChildren(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$dt = new \DateTime('2016-01-10 18:48:00');
|
|
|
|
|
$this->commentsManager->expects($this->once())
|
|
|
|
|
->method('getForObject')
|
|
|
|
|
->with('files', '19', 5, 15, $dt)
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn([
|
2017-10-24 09:26:53 -04:00
|
|
|
$this->getMockBuilder(IComment::class)
|
2016-07-15 03:52:46 -04:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock()
|
2020-03-25 17:21:27 -04:00
|
|
|
]);
|
2016-01-11 12:09:00 -05:00
|
|
|
|
|
|
|
|
$result = $this->collection->findChildren(5, 15, $dt);
|
|
|
|
|
|
2025-05-25 16:22:57 -04:00
|
|
|
$this->assertCount(1, $result);
|
|
|
|
|
$this->assertInstanceOf(CommentNode::class, $result[0]);
|
2016-01-11 12:09:00 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testChildExistsTrue(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->assertTrue($this->collection->childExists('44'));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testChildExistsFalse(): void {
|
2016-01-11 12:09:00 -05:00
|
|
|
$this->commentsManager->expects($this->once())
|
|
|
|
|
->method('get')
|
|
|
|
|
->with('44')
|
2025-06-30 10:56:59 -04:00
|
|
|
->willThrowException(new NotFoundException());
|
2016-01-11 12:09:00 -05:00
|
|
|
|
|
|
|
|
$this->assertFalse($this->collection->childExists('44'));
|
|
|
|
|
}
|
|
|
|
|
}
|