public function testUpdateFileTags() { $tag1 = 'tag1'; $tag2 = 'tag2'; $subdir = $this->root->newFolder('subdir'); $testFile = $subdir->newFile('test.txt'); $testFile->putContent('test contents'); $fileId = $testFile->getId(); // set tags $this->tagService->updateFileTags('subdir/test.txt', array($tag1, $tag2)); $this->assertEquals(array($fileId), $this->tagger->getIdsForTag($tag1)); $this->assertEquals(array($fileId), $this->tagger->getIdsForTag($tag2)); // remove tag $result = $this->tagService->updateFileTags('subdir/test.txt', array($tag2)); $this->assertEquals(array(), $this->tagger->getIdsForTag($tag1)); $this->assertEquals(array($fileId), $this->tagger->getIdsForTag($tag2)); // clear tags $result = $this->tagService->updateFileTags('subdir/test.txt', array()); $this->assertEquals(array(), $this->tagger->getIdsForTag($tag1)); $this->assertEquals(array(), $this->tagger->getIdsForTag($tag2)); // non-existing file $caught = false; try { $this->tagService->updateFileTags('subdir/unexist.txt', array($tag1)); } catch (\OCP\Files\NotFoundException $e) { $caught = true; } $this->assertTrue($caught); $subdir->delete(); }
/** * Returns a list of all files tagged with the given tag. * * @NoAdminRequired * @CORS * * @param array $tagName tag name to filter by * @return DataResponse */ public function getFilesByTag($tagName) { $files = array(); $fileInfos = $this->tagService->getFilesByTag($tagName); foreach ($fileInfos as &$fileInfo) { $file = \OCA\Files\Helper::formatFileInfo($fileInfo); $parts = explode('/', dirname($fileInfo->getPath()), 4); $file['path'] = '/' . $parts[3]; $file['tags'] = array($tagName); $files[] = $file; } return new DataResponse(array('files' => $files), Http::STATUS_OK); }
/** * Returns a list of all files tagged with the given tag. * * @NoAdminRequired * * @param array|string $tagName tag name to filter by * @return DataResponse */ public function getFilesByTag($tagName) { $files = array(); $fileInfos = $this->tagService->getFilesByTag($tagName); foreach ($fileInfos as &$fileInfo) { $file = \OCA\Files\Helper::formatFileInfo($fileInfo); $parts = explode('/', dirname($fileInfo->getPath()), 4); if (isset($parts[3])) { $file['path'] = '/' . $parts[3]; } else { $file['path'] = '/'; } $file['tags'] = [$tagName]; $files[] = $file; } return new DataResponse(['files' => $files]); }
public function testUpdateFileTagsStorageGenericException() { $this->tagService->expects($this->once())->method('updateFileTags')->with('/path.txt', ['Tag1', 'Tag2'])->will($this->throwException(new \Exception('My error message'))); $expected = new DataResponse(['message' => 'My error message'], Http::STATUS_NOT_FOUND); $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt', ['Tag1', 'Tag2'])); }