summaryrefslogtreecommitdiffstats
path: root/tests/lib/Files
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2016-07-22 14:37:37 +0200
committerRobin Appelman <robin@icewind.nl>2016-07-22 14:39:32 +0200
commite321ecd592fef123772c6e61e175b6a34a3c5044 (patch)
tree017e79025c2f9431d4631667886173f9f5df0281 /tests/lib/Files
parentd499f68fd72bb6839023aa91fb2028587a62c496 (diff)
downloadnextcloud-server-e321ecd592fef123772c6e61e175b6a34a3c5044.tar.gz
nextcloud-server-e321ecd592fef123772c6e61e175b6a34a3c5044.zip
add recent files to node api
Diffstat (limited to 'tests/lib/Files')
-rw-r--r--tests/lib/Files/Node/FolderTest.php171
1 files changed, 167 insertions, 4 deletions
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index 7ce9fff1419..cae6b4a80c0 100644
--- a/tests/lib/Files/Node/FolderTest.php
+++ b/tests/lib/Files/Node/FolderTest.php
@@ -12,6 +12,8 @@ use OC\Files\Cache\Cache;
use OC\Files\FileInfo;
use OC\Files\Mount\MountPoint;
use OC\Files\Node\Node;
+use OC\Files\Storage\Temporary;
+use OC\Files\Storage\Wrapper\Jail;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OC\Files\View;
@@ -760,9 +762,9 @@ class FolderTest extends \Test\TestCase {
public function uniqueNameProvider() {
return [
// input, existing, expected
- ['foo', [] , 'foo'],
- ['foo', ['foo'] , 'foo (2)'],
- ['foo', ['foo', 'foo (2)'] , 'foo (3)']
+ ['foo', [], 'foo'],
+ ['foo', ['foo'], 'foo (2)'],
+ ['foo', ['foo', 'foo (2)'], 'foo (3)']
];
}
@@ -782,7 +784,7 @@ class FolderTest extends \Test\TestCase {
->method('file_exists')
->will($this->returnCallback(function ($path) use ($existingFiles, $folderPath) {
foreach ($existingFiles as $existing) {
- if ($folderPath . '/' . $existing === $path){
+ if ($folderPath . '/' . $existing === $path) {
return true;
}
}
@@ -792,4 +794,165 @@ class FolderTest extends \Test\TestCase {
$node = new \OC\Files\Node\Folder($root, $view, $folderPath);
$this->assertEquals($expected, $node->getNonExistingName($name));
}
+
+ public function testRecent() {
+ $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $folderPath = '/bar/foo';
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
+ $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
+ ->disableOriginalConstructor()->getMock();
+
+ $baseTime = 1000;
+ $storage = new Temporary();
+ $mount = new MountPoint($storage, '');
+
+ $folderInfo->expects($this->any())
+ ->method('getMountPoint')
+ ->will($this->returnValue($mount));
+
+ $cache = $storage->getCache();
+
+ $id1 = $cache->put('bar/foo/inside.txt', [
+ 'storage_mtime' => $baseTime,
+ 'mtime' => $baseTime,
+ 'mimetype' => 'text/plain',
+ 'size' => 3
+ ]);
+ $id2 = $cache->put('bar/foo/old.txt', [
+ 'storage_mtime' => $baseTime - 100,
+ 'mtime' => $baseTime - 100,
+ 'mimetype' => 'text/plain',
+ 'size' => 3
+ ]);
+ $cache->put('bar/asd/outside.txt', [
+ 'storage_mtime' => $baseTime,
+ 'mtime' => $baseTime,
+ 'mimetype' => 'text/plain',
+ 'size' => 3
+ ]);
+ $cache->put('bar/foo/toold.txt', [
+ 'storage_mtime' => $baseTime - 600,
+ 'mtime' => $baseTime - 600,
+ 'mimetype' => 'text/plain',
+ 'size' => 3
+ ]);
+
+ $node = new \OC\Files\Node\Folder($root, $view, $folderPath, $folderInfo);
+
+
+ $nodes = $node->getRecent($baseTime - 500);
+ $ids = array_map(function (Node $node) {
+ return (int)$node->getId();
+ }, $nodes);
+ $this->assertEquals([$id1, $id2], $ids);
+ }
+
+ public function testRecentFolder() {
+ $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $folderPath = '/bar/foo';
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
+ $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
+ ->disableOriginalConstructor()->getMock();
+
+ $baseTime = 1000;
+ $storage = new Temporary();
+ $mount = new MountPoint($storage, '');
+
+ $folderInfo->expects($this->any())
+ ->method('getMountPoint')
+ ->will($this->returnValue($mount));
+
+ $cache = $storage->getCache();
+
+ $id1 = $cache->put('bar/foo/folder', [
+ 'storage_mtime' => $baseTime,
+ 'mtime' => $baseTime,
+ 'mimetype' => \OCP\Files\FileInfo::MIMETYPE_FOLDER,
+ 'size' => 3
+ ]);
+ $id2 = $cache->put('bar/foo/folder/bar.txt', [
+ 'storage_mtime' => $baseTime,
+ 'mtime' => $baseTime,
+ 'mimetype' => 'text/plain',
+ 'size' => 3,
+ 'parent' => $id1
+ ]);
+ $id3 = $cache->put('bar/foo/folder/asd.txt', [
+ 'storage_mtime' => $baseTime,
+ 'mtime' => $baseTime - 100,
+ 'mimetype' => 'text/plain',
+ 'size' => 3,
+ 'parent' => $id1
+ ]);
+
+ $node = new \OC\Files\Node\Folder($root, $view, $folderPath, $folderInfo);
+
+
+ $nodes = $node->getRecent($baseTime - 500);
+ $ids = array_map(function (Node $node) {
+ return (int)$node->getId();
+ }, $nodes);
+ $this->assertEquals([$id2, $id1, $id3], $ids);// sort folders before files with the same mtime, folders get the lowest child mtime
+ }
+
+ public function testRecentJail() {
+ $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $folderPath = '/bar/foo';
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
+ $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
+ ->disableOriginalConstructor()->getMock();
+
+ $baseTime = 1000;
+ $storage = new Temporary();
+ $jail = new Jail([
+ 'storage' => $storage,
+ 'root' => 'folder'
+ ]);
+ $mount = new MountPoint($jail, '/bar/foo');
+
+ $folderInfo->expects($this->any())
+ ->method('getMountPoint')
+ ->will($this->returnValue($mount));
+
+ $cache = $storage->getCache();
+
+ $id1 = $cache->put('folder/inside.txt', [
+ 'storage_mtime' => $baseTime,
+ 'mtime' => $baseTime,
+ 'mimetype' => 'text/plain',
+ 'size' => 3
+ ]);
+ $cache->put('outside.txt', [
+ 'storage_mtime' => $baseTime - 100,
+ 'mtime' => $baseTime - 100,
+ 'mimetype' => 'text/plain',
+ 'size' => 3
+ ]);
+
+ $node = new \OC\Files\Node\Folder($root, $view, $folderPath, $folderInfo);
+
+ $nodes = $node->getRecent($baseTime - 500);
+ $ids = array_map(function (Node $node) {
+ return (int)$node->getId();
+ }, $nodes);
+ $this->assertEquals([$id1], $ids);
+ }
}