Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-06-15 15:10:10 +0300
committerLukas Reschke <lukas@owncloud.com>2015-10-25 19:58:21 +0300
commit13e817e90166d85dbea98043583185778d192212 (patch)
treee6cf6a7ba301b838a2ded0d3e7b9d81e2c655cfc /tests
parenteb10e3abc2cf5d325bc0cd6fecaa64e7665d4b4a (diff)
Throw exception on `getPath` if file does not exist
Currently the `getPath` methods returned `NULL` in case when a file with the specified ID does not exist. This however mandates that developers are checking for the `NULL` case and if they do not the door for bugs with all kind of impact is widely opened. This is especially harmful if used in context with Views where the final result is limited based on the result of `getPath`, if `getPath` returns `NULL` PHP type juggles this to an empty string resulting in all possible kind of bugs. While one could argue that this is a misusage of the API the fact is that it is very often misused and an exception will trigger an immediate stop of execution as well as log this behaviour and show a pretty error page. I also adjusted some usages where I believe that we need to catch these errors, in most cases this is though simply an error that should hard-fail.
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/view.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index c0845a5613c..a84b8badd5a 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -207,15 +207,31 @@ class View extends \Test\TestCase {
$rootView = new \OC\Files\View('');
$cachedData = $rootView->getFileInfo('/foo.txt');
+ /** @var int $id1 */
$id1 = $cachedData['fileid'];
$this->assertEquals('/foo.txt', $rootView->getPath($id1));
$cachedData = $rootView->getFileInfo('/substorage/foo.txt');
+ /** @var int $id2 */
$id2 = $cachedData['fileid'];
$this->assertEquals('/substorage/foo.txt', $rootView->getPath($id2));
$folderView = new \OC\Files\View('/substorage');
$this->assertEquals('/foo.txt', $folderView->getPath($id2));
+ }
+
+ /**
+ * @expectedException \OCP\Files\NotFoundException
+ */
+ function testGetPathNotExisting() {
+ $storage1 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, [], '/');
+
+ $rootView = new \OC\Files\View('');
+ $cachedData = $rootView->getFileInfo('/foo.txt');
+ /** @var int $id1 */
+ $id1 = $cachedData['fileid'];
+ $folderView = new \OC\Files\View('/substorage');
$this->assertNull($folderView->getPath($id1));
}