Skip to content

Commit

Permalink
Add tests for metadata API
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
  • Loading branch information
SystemKeeper committed Dec 3, 2023
1 parent b62d3f8 commit 12ba526
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ protected function getFileFromShare(?Participant $participant, string $shareId):
}

$fileId = $node->getId();
$isPreviewAvailable = $this->previewManager->isAvailable($node);

$data = [
'type' => 'file',
Expand All @@ -734,11 +735,11 @@ protected function getFileFromShare(?Participant $participant, string $shareId):
'etag' => $node->getEtag(),
'permissions' => $node->getPermissions(),
'mimetype' => $node->getMimeType(),
'preview-available' => $this->previewManager->isAvailable($node) ? 'yes' : 'no',
'preview-available' => $isPreviewAvailable ? 'yes' : 'no',
];

// If a preview is available, check if we can get the dimensions of the file from the metadata API
if ($data['preview-available']) {
if ($isPreviewAvailable) {
try {
$metadata = $this->metadataManager->getMetaData($fileId, false);

Expand Down
25 changes: 25 additions & 0 deletions tests/php/Chat/Parser/SystemMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\FilesMetadata\Model\IFilesMetadata;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
Expand Down Expand Up @@ -659,6 +660,22 @@ public function testGetFileFromShareForGuest() {
->with($node)
->willReturn(true);

$metadata = $this->createMock(IFilesMetadata::class);
$metadata->expects($this->once())
->method('hasKey')
->with('photos-size')
->willReturn(true);

$metadata->expects($this->once())
->method('getArray')
->with('photos-size')
->willReturn(['width' => 1234, 'height' => 4567]);

$this->metadataManager->expects($this->once())
->method('getMetaData')
->with(54, false)
->willReturn($metadata);

$participant = $this->createMock(Participant::class);
$participant->expects($this->once())
->method('isGuest')
Expand All @@ -676,6 +693,8 @@ public function testGetFileFromShareForGuest() {
'permissions' => 27,
'mimetype' => 'text/plain',
'preview-available' => 'yes',
'width' => 1234,
'height' => 4567,
], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']));
}

Expand Down Expand Up @@ -728,6 +747,9 @@ public function testGetFileFromShareForOwner() {
])
->willReturn('absolute-link-owner');

$this->metadataManager->expects($this->never())
->method('getMetaData');

$participant = $this->createMock(Participant::class);
$participant->expects($this->once())
->method('isGuest')
Expand Down Expand Up @@ -817,6 +839,9 @@ public function testGetFileFromShareForRecipient() {
->with($file)
->willReturn(false);

$this->metadataManager->expects($this->never())
->method('getMetaData');

$this->url->expects($this->once())
->method('linkToRouteAbsolute')
->with('files.viewcontroller.showFile', [
Expand Down

0 comments on commit 12ba526

Please sign in to comment.