Skip to content

Commit 190f6c8

Browse files
committed
Adjust unit tests
Signed-off-by: Joas Schilling <[email protected]>
1 parent 09446c2 commit 190f6c8

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

tests/Controller/APIv2Test.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -651,18 +651,18 @@ public function testGetPreviewInvalidPaths($author, $fileId, $path, $returnedPat
651651
]);
652652
$controller->expects($this->any())
653653
->method('getPreviewFromPath')
654-
->with($path)
654+
->with($fileId, $path)
655655
->willReturn(['getPreviewFromPath']);
656656

657657
$this->assertSame(['getPreviewFromPath'], self::invokePrivate($controller, 'getPreview', [$author, $fileId, $path]));
658658
}
659659

660660
public function dataGetPreview() {
661661
return [
662-
['author', 42, '/path', '/currentPath', true, true, false, '/preview/dir', true],
663-
['author', 42, '/file.txt', '/currentFile.txt', false, true, false, '/preview/mpeg', true],
664-
['author', 42, '/file.txt', '/currentFile.txt', false, true, true, '/preview/currentFile.txt', false],
665-
['author', 42, '/file.txt', '/currentFile.txt', false, false, true, 'source::getPreviewFromPath', true],
662+
['author', 42, '/path', '/currentPath', true, true, false, '/preview/dir', true, 'dir'],
663+
['author', 42, '/file.txt', '/currentFile.txt', false, true, false, '/preview/mpeg', true, 'audio/mp3'],
664+
['author', 42, '/file.txt', '/currentFile.txt', false, true, true, '/preview/currentFile.txt', false, 'text/plain'],
665+
['author', 42, '/file.txt', '/currentFile.txt', false, false, true, 'source::getPreviewFromPath', true, 'text/plain'],
666666
];
667667
}
668668

@@ -678,8 +678,9 @@ public function dataGetPreview() {
678678
* @param bool $isMimeSup
679679
* @param string $source
680680
* @param bool $isMimeTypeIcon
681+
* @param string $mimeType
681682
*/
682-
public function testGetPreview($author, $fileId, $path, $returnedPath, $isDir, $validFileInfo, $isMimeSup, $source, $isMimeTypeIcon) {
683+
public function testGetPreview($author, $fileId, $path, $returnedPath, $isDir, $validFileInfo, $isMimeSup, $source, $isMimeTypeIcon, $mimeType) {
683684

684685
$controller = $this->getController([
685686
'getPreviewLink',
@@ -726,7 +727,7 @@ public function testGetPreview($author, $fileId, $path, $returnedPath, $isDir, $
726727
->willReturn($isMimeSup);
727728

728729
if (!$isMimeSup) {
729-
$fileInfo->expects($this->once())
730+
$fileInfo->expects($this->atLeastOnce())
730731
->method('getMimetype')
731732
->willReturn('audio/mp3');
732733

@@ -735,6 +736,10 @@ public function testGetPreview($author, $fileId, $path, $returnedPath, $isDir, $
735736
->with('audio/mp3')
736737
->willReturn('/preview/mpeg');
737738
} else {
739+
$fileInfo->expects($this->atLeastOnce())
740+
->method('getMimetype')
741+
->willReturn('text/plain');
742+
738743
$this->urlGenerator->expects($this->once())
739744
->method('linkToRouteAbsolute')
740745
->with('core.Preview.getPreview', $this->anything())
@@ -753,33 +758,44 @@ public function testGetPreview($author, $fileId, $path, $returnedPath, $isDir, $
753758

754759
$controller->expects($this->once())
755760
->method('getPreviewFromPath')
756-
->with($path, $this->anything())
757-
->willReturn(['source' => 'source::getPreviewFromPath']);
761+
->with($fileId, $path, $this->anything())
762+
->willReturn([
763+
'link' => '/preview' . $returnedPath,
764+
'source' => 'source::getPreviewFromPath',
765+
'mimeType' => $mimeType,
766+
'isMimeTypeIcon' => $isMimeTypeIcon,
767+
'fileId' => $fileId,
768+
'view' => 'files',
769+
]);
758770
}
759771

760772
$this->assertSame([
761773
'link' => '/preview' . $returnedPath,
762774
'source' => $source,
775+
'mimeType' => $mimeType,
763776
'isMimeTypeIcon' => $isMimeTypeIcon,
777+
'fileId' => $fileId,
778+
'view' => 'files',
764779
], self::invokePrivate($controller, 'getPreview', [$author, $fileId, $path]));
765780
}
766781

767782
public function dataGetPreviewFromPath() {
768783
return [
769-
['dir', 'dir', true, ''],
770-
['test.txt', 'text/plain', false, 'trashbin'],
771-
['test.mp3', 'audio/mpeg', false, ''],
784+
[23, 'dir', 'dir', true, ''],
785+
[42, 'test.txt', 'text/plain', false, 'trashbin'],
786+
[128, 'test.mp3', 'audio/mpeg', false, ''],
772787
];
773788
}
774789

775790
/**
776791
* @dataProvider dataGetPreviewFromPath
792+
* @param int $fileId
777793
* @param string $filePath
778794
* @param string $mimeType
779795
* @param bool $isDir
780796
* @param string $view
781797
*/
782-
public function testGetPreviewFromPath($filePath, $mimeType, $isDir, $view) {
798+
public function testGetPreviewFromPath($fileId, $filePath, $mimeType, $isDir, $view) {
783799
$controller = $this->getController([
784800
'getPreviewPathFromMimeType',
785801
'getPreviewLink',
@@ -801,9 +817,12 @@ public function testGetPreviewFromPath($filePath, $mimeType, $isDir, $view) {
801817
[
802818
'link' => 'target-link',
803819
'source' => 'mime-type-icon',
820+
'mimeType' => $mimeType,
804821
'isMimeTypeIcon' => true,
822+
'fileId' => $fileId,
823+
'view' => $view ?: 'files',
805824
],
806-
self::invokePrivate($controller, 'getPreviewFromPath', [$filePath, ['path' => $filePath, 'is_dir' => $isDir, 'view' => $view]])
825+
self::invokePrivate($controller, 'getPreviewFromPath', [$fileId, $filePath, ['path' => $filePath, 'is_dir' => $isDir, 'view' => $view]])
807826
);
808827
}
809828

0 commit comments

Comments
 (0)