Fix mimetype filter in getDirectoryContent

This commit is contained in:
Robin Appelman 2015-12-02 16:48:15 +01:00
parent df5872ec50
commit 19b2fe6a3a
2 changed files with 37 additions and 6 deletions

View File

@ -1427,13 +1427,9 @@ class View {
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;
}
});
}

View File

@ -2389,4 +2389,39 @@ class View extends \Test\TestCase {
$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);
}
}