/** * Returns an array with the favorites * * @param string $user * @return array * @throws \RuntimeException when too many or no favorites where found */ public function getFavoriteFilePaths($user) { $tags = $this->tagManager->load('files', [], false, $user); $favorites = $tags->getFavorites(); if (empty($favorites)) { throw new \RuntimeException('No favorites', 1); } else { if (isset($favorites[self::FAVORITE_LIMIT])) { throw new \RuntimeException('Too many favorites', 2); } } // Can not DI because the user is not known on instantiation $rootFolder = \OC::$server->getUserFolder($user); $folders = $items = []; foreach ($favorites as $favorite) { $nodes = $rootFolder->getById($favorite); if (!empty($nodes)) { /** @var \OCP\Files\Node $node */ $node = array_shift($nodes); $path = substr($node->getPath(), strlen($user . '/files/')); $items[] = $path; if ($node instanceof Folder) { $folders[] = $path; } } } if (empty($items)) { throw new \RuntimeException('No favorites', 1); } return ['items' => $items, 'folders' => $folders]; }
/** * Returns the tagger * * @return \OCP\ITags tagger */ private function getTagger() { if (!$this->tagger) { $this->tagger = $this->tagManager->load('files'); } return $this->tagger; }
public function setUp() { parent::setUp(); $this->server = new \Sabre\DAV\Server(); $this->tree = $this->getMockBuilder('\\Sabre\\DAV\\ObjectTree')->disableOriginalConstructor()->getMock(); $this->tagger = $this->getMock('\\OCP\\ITags'); $this->tagManager = $this->getMock('\\OCP\\ITagManager'); $this->tagManager->expects($this->any())->method('load')->with('files')->will($this->returnValue($this->tagger)); $this->plugin = new \OC\Connector\Sabre\TagsPlugin($this->tree, $this->tagManager); $this->plugin->initialize($this->server); }
public function testShareTags() { $testTag = 'TestTag'; OCP\Share::registerBackend('test', 'Test_Share_Backend'); $tagger = $this->tagMgr->load('test'); $tagger->tagAs(1, $testTag); $otherUserId = $this->getUniqueID('user2_'); OC_User::createUser($otherUserId, 'pass'); OC_User::setUserId($otherUserId); $otherUserSession = $this->getMock('\OCP\IUserSession'); $otherUserSession ->expects($this->any()) ->method('getUser') ->will($this->returnValue(new OC\User\User($otherUserId, null))); $otherTagMgr = new OC\TagManager($this->tagMapper, $otherUserSession); $otherTagger = $otherTagMgr->load('test'); $this->assertFalse($otherTagger->hasTag($testTag)); OC_User::setUserId($this->user->getUID()); OCP\Share::shareItem('test', 1, OCP\Share::SHARE_TYPE_USER, $otherUserId, \OCP\Constants::PERMISSION_READ); OC_User::setUserId($otherUserId); $otherTagger = $otherTagMgr->load('test', array(), true); // Update tags, load shared ones. $this->assertTrue($otherTagger->hasTag($testTag)); $this->assertContains(1, $otherTagger->getIdsForTag($testTag)); }