예제 #1
0
 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();
 }
예제 #2
0
	/**
	 * copies a directory recursively by using streams
	 *
	 * @param string $source
	 * @param \OCP\Files\Folder $target
	 * @return void
	 */
	public static function copyr($source, \OCP\Files\Folder $target) {
		$dir = opendir($source);
		while (false !== ($file = readdir($dir))) {
			if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
				if (is_dir($source . '/' . $file)) {
					$child = $target->newFolder($file);
					self::copyr($source . '/' . $file, $child);
				} else {
					$child = $target->newFile($file);
					stream_copy_to_stream(fopen($source . '/' . $file,'r'), $child->fopen('w'));
				}
			}
		}
		closedir($dir);
	}
예제 #3
0
 /**
  * @param \OCP\Files\Folder $parent
  * @param string $folderName
  * @return \OCP\Files\Folder
  * @throws SetUpException
  */
 private function getOrCreateSubFolder(Folder $parent, $folderName)
 {
     if ($parent->nodeExists($folderName)) {
         return $parent->get($folderName);
     } else {
         return $parent->newFolder($folderName);
     }
 }
예제 #4
0
 /**
  * Creates the folder structure and adds test images
  *
  * This could be refined by adding tests to make sure we have access to the files
  *
  * @param Folder $baseFolder
  * @param array <string|int,string|array> $structure
  */
 private function createStructure($baseFolder, $structure)
 {
     foreach ($structure as $key => $value) {
         if (is_array($value)) {
             $subFolder = $baseFolder->newFolder($key);
             if ($key === $this->sharedFolderName) {
                 $this->sharedFolder = $subFolder;
             }
             if (!empty($value)) {
                 $this->createStructure($subFolder, $value);
             }
         } else {
             $file = $this->addFile($baseFolder, $value, $value);
             if ($value === $this->sharedFileName) {
                 $this->sharedFile = $file;
             }
         }
     }
 }