diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-12-04 14:01:15 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-12-11 17:38:50 +0100 |
commit | 25dde7e93bc648ec8cd14b8f2711d50f77d8d1bf (patch) | |
tree | f45b35dd647870b6c3aeded3e8e11faa41effcba /tests/lib | |
parent | 745d8706b973ff0494af54f183acc0da361f0e83 (diff) | |
download | nextcloud-server-25dde7e93bc648ec8cd14b8f2711d50f77d8d1bf.tar.gz nextcloud-server-25dde7e93bc648ec8cd14b8f2711d50f77d8d1bf.zip |
Added searchByTags to view, storage and cache
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/files/cache/cache.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php index 7e44cb898ac..1af8e4da960 100644 --- a/tests/lib/files/cache/cache.php +++ b/tests/lib/files/cache/cache.php @@ -270,6 +270,63 @@ class Cache extends \Test\TestCase { $this->assertEquals(2, count($this->cache->searchByMime('foo/file'))); } + function testSearchByTag() { + $userId = $this->getUniqueId('user'); + \OC_User::createUser($userId, $userId); + $this->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')); + + // use tag name + $results = $this->cache->searchByTag('tag1', $userId); + + $this->assertEquals(2, count($results)); + + $this->assertEquals('folder', $results[0]['name']); + $this->assertEquals('foo', $results[1]['name']); + + // use tag id + $tags = $tagManager->getTagsForUser($userId); + $this->assertNotEmpty($tags); + $tags = array_filter($tags, function($tag) { return $tag->getName() === 'tag2'; }); + $results = $this->cache->searchByTag(current($tags)->getId(), $userId); + $this->assertEquals(3, count($results)); + + $this->assertEquals('folder', $results[0]['name']); + $this->assertEquals('foobar', $results[1]['name']); + $this->assertEquals('foo2', $results[2]['name']); + + $tagManager->delete('tag1'); + $tagManager->delete('tag2'); + + $this->logout(); + \OC_User::deleteUser($userId); + } + function testMove() { $file1 = 'folder'; $file2 = 'folder/bar'; |