Skip to content

Commit

Permalink
Merge pull request #20904 from owncloud/view-mime-filter
Browse files Browse the repository at this point in the history
Fix mimetype filter in getDirectoryContent
  • Loading branch information
DeepDiver1975 committed Dec 7, 2015
2 parents e1f2965 + 19b2fe6 commit 0c3d979
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/private/files/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -1427,13 +1427,9 @@ public function getDirectoryContent($directory, $mimetype_filter = '') {
if ($mimetype_filter) {
$files = array_filter($files, function (FileInfo $file) use ($mimetype_filter) {
if (strpos($mimetype_filter, '/')) {
if ($file->getMimetype() === $mimetype_filter) {
$result[] = $file;
}
return $file->getMimetype() === $mimetype_filter;
} else {
if ($file->getMimePart() === $mimetype_filter) {
$result[] = $file;
}
return $file->getMimePart() === $mimetype_filter;
}
});
}
Expand Down
35 changes: 35 additions & 0 deletions tests/lib/files/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -2389,4 +2389,39 @@ public function testRemoveMoveableMountPoint() {
$view = new \OC\Files\View('/' . $this->user . '/files');
$this->assertEquals('foo', $view->rmdir('mount'));
}

public function mimeFilterProvider() {
return [
[null, ['test1.txt', 'test2.txt', 'test3.md', 'test4.png']],
['text/plain', ['test1.txt', 'test2.txt']],
['text/markdown', ['test3.md']],
['text', ['test1.txt', 'test2.txt', 'test3.md']],
];
}

/**
* @param string $filter
* @param string[] $expected
* @dataProvider mimeFilterProvider
*/
public function testGetDirectoryContentMimeFilter($filter, $expected) {
$storage1 = new Temporary();
$root = $this->getUniqueID('/');
\OC\Files\Filesystem::mount($storage1, array(), $root . '/');
$view = new \OC\Files\View($root);

$view->file_put_contents('test1.txt', 'asd');
$view->file_put_contents('test2.txt', 'asd');
$view->file_put_contents('test3.md', 'asd');
$view->file_put_contents('test4.png', '');

$content = $view->getDirectoryContent('', $filter);

$files = array_map(function(FileInfo $info) {
return $info->getName();
}, $content);
sort($files);

$this->assertEquals($expected, $files);
}
}

0 comments on commit 0c3d979

Please sign in to comment.