diff options
author | Robin Appelman <robin@icewind.nl> | 2017-03-08 15:17:39 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-03-08 16:30:55 +0100 |
commit | e61606a767cd6e2c28e3897e7e913e39371078e5 (patch) | |
tree | b2d0cf869dae5f4cce698ca647f827aab178aaa0 /tests/lib | |
parent | 2a8e922d67a1246e101f926f1b0ab287db71929e (diff) | |
download | nextcloud-server-e61606a767cd6e2c28e3897e7e913e39371078e5.tar.gz nextcloud-server-e61606a767cd6e2c28e3897e7e913e39371078e5.zip |
Allow searching for favorites
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/Files/Cache/CacheTest.php | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index 1bcf8832c63..0038cef1f63 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -14,6 +14,7 @@ use OC\Files\Cache\Cache; use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchQuery; use OCP\Files\Search\ISearchComparison; +use OCP\IUser; class LongId extends \OC\Files\Storage\Temporary { public function getId() { @@ -397,6 +398,61 @@ class CacheTest extends \Test\TestCase { } } + function testSearchQueryByTag() { + $userId = static::getUniqueID('user'); + \OC::$server->getUserManager()->createUser($userId, $userId); + static::loginAsUser($userId); + $user = new \OC\User\User($userId, null); + + $file1 = 'folder'; + $file2 = 'folder/foobar'; + $file3 = 'folder/foo'; + $file4 = 'folder/foo2'; + $file5 = 'folder/foo3'; + $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'); + $fileData = array(); + $fileData['foobar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file'); + $fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file'); + $fileData['foo2'] = array('size' => 25, 'mtime' => 28, 'mimetype' => 'foo/file'); + $fileData['foo3'] = array('size' => 88, 'mtime' => 34, 'mimetype' => 'foo/file'); + + $id1 = $this->cache->put($file1, $data1); + $id2 = $this->cache->put($file2, $fileData['foobar']); + $id3 = $this->cache->put($file3, $fileData['foo']); + $id4 = $this->cache->put($file4, $fileData['foo2']); + $id5 = $this->cache->put($file5, $fileData['foo3']); + + $tagManager = \OC::$server->getTagManager()->load('files', null, null, $userId); + $this->assertTrue($tagManager->tagAs($id1, 'tag1')); + $this->assertTrue($tagManager->tagAs($id1, 'tag2')); + $this->assertTrue($tagManager->tagAs($id2, 'tag2')); + $this->assertTrue($tagManager->tagAs($id3, 'tag1')); + $this->assertTrue($tagManager->tagAs($id4, 'tag2')); + + $results = $this->cache->searchQuery(new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'tagname', 'tag2'), + 0, 0, [], $user + )); + $this->assertEquals(3, count($results)); + + usort($results, function ($value1, $value2) { + return $value1['name'] >= $value2['name']; + }); + + $this->assertEquals('folder', $results[0]['name']); + $this->assertEquals('foo2', $results[1]['name']); + $this->assertEquals('foobar', $results[2]['name']); + + $tagManager->delete('tag1'); + $tagManager->delete('tag2'); + + static::logout(); + $user = \OC::$server->getUserManager()->get($userId); + if ($user !== null) { + $user->delete(); + } + } + function testSearchByQuery() { $file1 = 'folder'; $file2 = 'folder/foobar'; @@ -409,25 +465,27 @@ class CacheTest extends \Test\TestCase { $this->cache->put($file1, $data1); $this->cache->put($file2, $fileData['foobar']); $this->cache->put($file3, $fileData['foo']); + /** @var IUser $user */ + $user = $this->createMock(IUser::class); $this->assertCount(1, $this->cache->searchQuery(new SearchQuery( new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foo') - , 10, 0, []))); + , 10, 0, [], $user))); $this->assertCount(2, $this->cache->searchQuery(new SearchQuery( new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', 'foo%') - , 10, 0, []))); + , 10, 0, [], $user))); $this->assertCount(2, $this->cache->searchQuery(new SearchQuery( new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', 'foo/file') - , 10, 0, []))); + , 10, 0, [], $user))); $this->assertCount(3, $this->cache->searchQuery(new SearchQuery( new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', 'foo/%') - , 10, 0, []))); + , 10, 0, [], $user))); $this->assertCount(1, $this->cache->searchQuery(new SearchQuery( new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'size', 100) - , 10, 0, []))); + , 10, 0, [], $user))); $this->assertCount(2, $this->cache->searchQuery(new SearchQuery( new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN_EQUAL, 'size', 100) - , 10, 0, []))); + , 10, 0, [], $user))); } function testMove() { |