summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-03-23 13:08:17 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-03-23 13:08:17 +0100
commitea07a428f463a866b2c5e44e243a33d8980c8850 (patch)
tree3183f2b62f74d0a139b086d4137a82d433b927ec /tests
parent7800b9dbc82dfcb6f1fe46f89a215d97afec071c (diff)
parent0b0b3253bb75f5fffb39201da39139d4f26d8a22 (diff)
downloadnextcloud-server-ea07a428f463a866b2c5e44e243a33d8980c8850.tar.gz
nextcloud-server-ea07a428f463a866b2c5e44e243a33d8980c8850.zip
Merge pull request #22506 from owncloud/node-get-from-cache
Query the cache when checking if a node exists
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/node/folder.php85
-rw-r--r--tests/lib/files/node/root.php15
2 files changed, 69 insertions, 31 deletions
diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php
index 09bf32561e6..f6d488d6590 100644
--- a/tests/lib/files/node/folder.php
+++ b/tests/lib/files/node/folder.php
@@ -376,6 +376,14 @@ class Folder extends \Test\TestCase {
->method('getCache')
->will($this->returnValue($cache));
+ $mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
+ $mount->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue($storage));
+ $mount->expects($this->once())
+ ->method('getInternalPath')
+ ->will($this->returnValue('foo'));
+
$cache->expects($this->once())
->method('search')
->with('%qw%')
@@ -388,9 +396,10 @@ class Folder extends \Test\TestCase {
->with('/bar/foo')
->will($this->returnValue(array()));
- $view->expects($this->once())
- ->method('resolvePath')
- ->will($this->returnValue(array($storage, 'foo')));
+ $root->expects($this->once())
+ ->method('getMount')
+ ->with('/bar/foo')
+ ->will($this->returnValue($mount));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$result = $node->search('qw');
@@ -404,13 +413,21 @@ class Folder extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn'), array($manager, $view, $this->user));
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
$storage = $this->getMock('\OC\Files\Storage\Storage');
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+ $mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
+ $mount->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue($storage));
+ $mount->expects($this->once())
+ ->method('getInternalPath')
+ ->will($this->returnValue('files'));
+
$storage->expects($this->once())
->method('getCache')
->will($this->returnValue($cache));
@@ -428,9 +445,10 @@ class Folder extends \Test\TestCase {
->with('')
->will($this->returnValue(array()));
- $view->expects($this->once())
- ->method('resolvePath')
- ->will($this->returnValue(array($storage, 'files')));
+ $root->expects($this->once())
+ ->method('getMount')
+ ->with('')
+ ->will($this->returnValue($mount));
$result = $root->search('qw');
$this->assertEquals(1, count($result));
@@ -450,6 +468,14 @@ class Folder extends \Test\TestCase {
$storage = $this->getMock('\OC\Files\Storage\Storage');
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+ $mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
+ $mount->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue($storage));
+ $mount->expects($this->once())
+ ->method('getInternalPath')
+ ->will($this->returnValue(''));
+
$storage->expects($this->once())
->method('getCache')
->will($this->returnValue($cache));
@@ -466,9 +492,10 @@ class Folder extends \Test\TestCase {
->with('/bar')
->will($this->returnValue(array()));
- $view->expects($this->once())
- ->method('resolvePath')
- ->will($this->returnValue(array($storage, '')));
+ $root->expects($this->once())
+ ->method('getMount')
+ ->with('/bar')
+ ->will($this->returnValue($mount));
$node = new \OC\Files\Node\Folder($root, $view, '/bar');
$result = $node->search('qw');
@@ -489,6 +516,14 @@ class Folder extends \Test\TestCase {
$storage = $this->getMock('\OC\Files\Storage\Storage');
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+ $mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
+ $mount->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue($storage));
+ $mount->expects($this->once())
+ ->method('getInternalPath')
+ ->will($this->returnValue('foo'));
+
$storage->expects($this->once())
->method('getCache')
->will($this->returnValue($cache));
@@ -505,9 +540,10 @@ class Folder extends \Test\TestCase {
->with('/bar/foo')
->will($this->returnValue(array()));
- $view->expects($this->once())
- ->method('resolvePath')
- ->will($this->returnValue(array($storage, 'foo')));
+ $root->expects($this->once())
+ ->method('getMount')
+ ->with('/bar/foo')
+ ->will($this->returnValue($mount));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$result = $node->searchByTag('tag1', 'user1');
@@ -531,6 +567,14 @@ class Folder extends \Test\TestCase {
$subStorage = $this->getMock('\OC\Files\Storage\Storage');
$subMount = $this->getMock('\OC\Files\Mount\MountPoint', array(), array(null, ''));
+ $mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
+ $mount->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue($storage));
+ $mount->expects($this->once())
+ ->method('getInternalPath')
+ ->will($this->returnValue('foo'));
+
$subMount->expects($this->once())
->method('getStorage')
->will($this->returnValue($subStorage));
@@ -566,9 +610,10 @@ class Folder extends \Test\TestCase {
->with('/bar/foo')
->will($this->returnValue(array($subMount)));
- $view->expects($this->once())
- ->method('resolvePath')
- ->will($this->returnValue(array($storage, 'foo')));
+ $root->expects($this->once())
+ ->method('getMount')
+ ->with('/bar/foo')
+ ->will($this->returnValue($mount));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
@@ -601,8 +646,8 @@ class Folder extends \Test\TestCase {
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
$view->expects($this->once())
- ->method('file_exists')
- ->will($this->returnValue(true));
+ ->method('getFileInfo')
+ ->will($this->returnValue(new FileInfo('/bar/foo/qwerty', null, 'qwerty', ['mimetype' => 'text/plain'], null)));
$storage->expects($this->once())
->method('getCache')
@@ -683,8 +728,8 @@ class Folder extends \Test\TestCase {
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
$view->expects($this->any())
- ->method('file_exists')
- ->will($this->returnValue(true));
+ ->method('getFileInfo')
+ ->will($this->returnValue(new FileInfo('/bar/foo/qwerty', null, 'qwerty', ['mimetype' => 'plain'], null)));
$storage->expects($this->any())
->method('getCache')
diff --git a/tests/lib/files/node/root.php b/tests/lib/files/node/root.php
index 4b1aea1da4e..9c77959869d 100644
--- a/tests/lib/files/node/root.php
+++ b/tests/lib/files/node/root.php
@@ -12,6 +12,9 @@ use OC\Files\FileInfo;
use OCP\Files\NotPermittedException;
use OC\Files\Mount\Manager;
+/**
+ * @group DB
+ */
class Root extends \Test\TestCase {
private $user;
@@ -41,16 +44,6 @@ class Root extends \Test\TestCase {
->with('/bar/foo')
->will($this->returnValue($this->getFileInfo(array('fileid' => 10, 'path' => 'bar/foo', 'name', 'mimetype' => 'text/plain'))));
- $view->expects($this->once())
- ->method('is_dir')
- ->with('/bar/foo')
- ->will($this->returnValue(false));
-
- $view->expects($this->once())
- ->method('file_exists')
- ->with('/bar/foo')
- ->will($this->returnValue(true));
-
$root->mount($storage, '');
$node = $root->get('/bar/foo');
$this->assertEquals(10, $node->getId());
@@ -73,7 +66,7 @@ class Root extends \Test\TestCase {
$root = new \OC\Files\Node\Root($manager, $view, $this->user);
$view->expects($this->once())
- ->method('file_exists')
+ ->method('getFileInfo')
->with('/bar/foo')
->will($this->returnValue(false));