コード例 #1
0
 private function checkEntries($entries)
 {
     foreach ($entries as $entry) {
         $data = $this->storage->getCache()->get($entry[0]);
         $this->assertEquals($entry[1], $data['mimetype']);
     }
 }
コード例 #2
0
ファイル: cache.php プロジェクト: olucao/owncloud-core
 function testGetById()
 {
     $storageId = $this->storage->getId();
     $data = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
     $id = $this->cache->put('foo', $data);
     $this->assertEquals(array($storageId, 'foo'), \OC\Files\Cache\Cache::getById($id));
 }
コード例 #3
0
	/**
	 * @param bool $scan
	 * @return \OC\Files\Storage\Storage
	 */
	private function getTestStorage($scan = true) {
		$this->fileSystem = new Temporary(array());
		$this->fileLocker = new LockingWrapper(array('storage' => $this->fileSystem));
		$textData = "dummy file data\n";
		$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
		$this->fileSystem->mkdir('folder');
		$this->fileSystem->file_put_contents('foo.txt', $textData);
		$this->fileSystem->file_put_contents('foo.png', $imgData);
		$this->fileSystem->file_put_contents('folder/bar.txt', $textData);

		if ($scan) {
			$scanner = $this->fileSystem->getScanner();
			$scanner->scan('');
		}
		return $this->fileSystem;
	}
コード例 #4
0
 /**
  * @dataProvider sourceAndTargetDirectoryProvider
  */
 public function testCopyAndMoveFromStorageEncodedFolder($sourceDir, $targetDir)
 {
     $this->sourceStorage->mkdir($sourceDir);
     $this->sourceStorage->mkdir($targetDir);
     $this->sourceStorage->file_put_contents($sourceDir . '/test.txt', 'bar');
     $this->assertTrue($this->instance->copyFromStorage($this->instance, self::NFC_NAME . '1/test.txt', self::NFC_NAME . '2/test.txt'));
     $this->assertTrue($this->instance->file_exists(self::NFC_NAME . '1/test.txt'));
     $this->assertTrue($this->instance->file_exists(self::NFC_NAME . '2/test.txt'));
     $this->assertEquals('bar', $this->instance->file_get_contents(self::NFC_NAME . '2/test.txt'));
     $this->assertTrue($this->instance->moveFromStorage($this->instance, self::NFC_NAME . '1/test.txt', self::NFC_NAME . '2/test2.txt'));
     $this->assertFalse($this->instance->file_exists(self::NFC_NAME . '1/test.txt'));
     $this->assertTrue($this->instance->file_exists(self::NFC_NAME . '2/test2.txt'));
     $this->assertEquals('bar', $this->instance->file_get_contents(self::NFC_NAME . '2/test2.txt'));
 }
コード例 #5
0
ファイル: scanner.php プロジェクト: Combustible/core
 public function testChangePropagator()
 {
     /**
      * @var \OC\Files\Cache\ChangePropagator $propagator
      */
     $propagator = $this->getMock('\\OC\\Files\\Cache\\ChangePropagator', array('propagateChanges'), array(), '', false);
     $storage = new Temporary(array());
     $mount = new Mount($storage, '/foo');
     Filesystem::getMountManager()->addMount($mount);
     $cache = $storage->getCache();
     $storage->mkdir('folder');
     $storage->file_put_contents('foo.txt', 'qwerty');
     $storage->file_put_contents('folder/bar.txt', 'qwerty');
     $scanner = new TestScanner('', \OC::$server->getDatabaseConnection());
     $originalPropagator = $scanner->getPropagator();
     $scanner->setPropagator($propagator);
     $scanner->addMount($mount);
     $scanner->scan('');
     $changes = $propagator->getChanges();
     $parents = $propagator->getAllParents();
     sort($changes);
     sort($parents);
     $this->assertEquals(array('/foo', '/foo/folder', '/foo/folder/bar.txt', '/foo/foo.txt'), $changes);
     $this->assertEquals(array('/', '/foo', '/foo/folder'), $parents);
     $cache->put('foo.txt', array('storage_mtime' => time() - 50));
     $propagator = $this->getMock('\\OC\\Files\\Cache\\ChangePropagator', array('propagateChanges'), array(), '', false);
     $scanner->setPropagator($propagator);
     $storage->file_put_contents('foo.txt', 'asdasd');
     $scanner->scan('');
     $changes = $propagator->getChanges();
     $parents = $propagator->getAllParents();
     $this->assertEquals(array('/foo/foo.txt'), $changes);
     $this->assertEquals(array('/', '/foo'), $parents);
     $scanner->setPropagator($originalPropagator);
     $oldInfo = $cache->get('');
     $cache->put('foo.txt', array('storage_mtime' => time() - 70));
     $storage->file_put_contents('foo.txt', 'asdasd');
     $scanner->scan('');
     $newInfo = $cache->get('');
     $this->assertNotEquals($oldInfo['etag'], $newInfo['etag']);
 }
コード例 #6
0
ファイル: updaterlegacy.php プロジェクト: kebenxiaoming/core
 public function testRenameWithMountPoints()
 {
     $storage2 = new \OC\Files\Storage\Temporary(array());
     $cache2 = $storage2->getCache();
     Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
     Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
     $view = new View('/' . self::$user . '/files');
     $this->assertTrue($cache2->inCache('foo.txt'));
     $folderCachedData = $view->getFileInfo('folder');
     $substorageCachedData = $cache2->get('');
     $fooCachedData = $cache2->get('foo.txt');
     Filesystem::rename('folder/substorage/foo.txt', 'folder/substorage/bar.txt');
     $this->assertFalse($cache2->inCache('foo.txt'));
     $this->assertTrue($cache2->inCache('bar.txt'));
     $cachedData = $cache2->get('bar.txt');
     $this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']);
     $mtime = $cachedData['mtime'];
     $cachedData = $cache2->get('');
     $this->assertInternalType('string', $substorageCachedData['etag']);
     $this->assertInternalType('string', $cachedData['etag']);
     $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
     // rename can cause mtime change - invalid assert
     //		$this->assertEquals($mtime, $cachedData['mtime']);
     $cachedData = $view->getFileInfo('folder');
     $this->assertInternalType('string', $folderCachedData['etag']);
     $this->assertInternalType('string', $cachedData['etag']);
     $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
     // rename can cause mtime change - invalid assert
     //		$this->assertEquals($mtime, $cachedData['mtime']);
 }
コード例 #7
0
 public function testGetAvatarValidUser()
 {
     $avatar = $this->avatarManager->getAvatar('valid-user');
     $this->assertInstanceOf('\\OCP\\IAvatar', $avatar);
     $this->assertFalse($this->storage->file_exists('files'));
 }
コード例 #8
0
ファイル: view.php プロジェクト: adolfo2103/hcloudfilem
 public function testRenameOverWrite()
 {
     $storage = new Temporary(array());
     $scanner = $storage->getScanner();
     $storage->mkdir('sub');
     $storage->mkdir('foo');
     $storage->file_put_contents('foo.txt', 'asd');
     $storage->file_put_contents('foo/bar.txt', 'asd');
     $scanner->scan('');
     \OC\Files\Filesystem::mount($storage, array(), '/test/');
     $view = new \OC\Files\View('');
     $this->assertTrue($view->rename('/test/foo.txt', '/test/foo/bar.txt'));
 }
コード例 #9
0
ファイル: manager.php プロジェクト: evanjt/core
 public function getId()
 {
     return 'long:' . str_repeat('foo', 50) . parent::getId();
 }
コード例 #10
0
ファイル: updater.php プロジェクト: evanjt/core
 public function testMoveFolderCrossStorage()
 {
     $storage2 = new Temporary(array());
     $cache2 = $storage2->getCache();
     Filesystem::mount($storage2, array(), '/bar');
     $this->storage->mkdir('foo');
     $this->storage->mkdir('foo/bar');
     $this->storage->file_put_contents('foo/foo.txt', 'qwerty');
     $this->storage->file_put_contents('foo/bar.txt', 'foo');
     $this->storage->file_put_contents('foo/bar/bar.txt', 'qwertyuiop');
     $this->storage->getScanner()->scan('');
     $this->assertTrue($this->cache->inCache('foo'));
     $this->assertTrue($this->cache->inCache('foo/foo.txt'));
     $this->assertTrue($this->cache->inCache('foo/bar.txt'));
     $this->assertTrue($this->cache->inCache('foo/bar'));
     $this->assertTrue($this->cache->inCache('foo/bar/bar.txt'));
     $cached = [];
     $cached[] = $this->cache->get('foo');
     $cached[] = $this->cache->get('foo/foo.txt');
     $cached[] = $this->cache->get('foo/bar.txt');
     $cached[] = $this->cache->get('foo/bar');
     $cached[] = $this->cache->get('foo/bar/bar.txt');
     // add extension to trigger the possible mimetype change
     $storage2->moveFromStorage($this->storage, 'foo', 'foo.b');
     $storage2->getUpdater()->renameFromStorage($this->storage, 'foo', 'foo.b');
     $this->assertFalse($this->cache->inCache('foo'));
     $this->assertFalse($this->cache->inCache('foo/foo.txt'));
     $this->assertFalse($this->cache->inCache('foo/bar.txt'));
     $this->assertFalse($this->cache->inCache('foo/bar'));
     $this->assertFalse($this->cache->inCache('foo/bar/bar.txt'));
     $this->assertTrue($cache2->inCache('foo.b'));
     $this->assertTrue($cache2->inCache('foo.b/foo.txt'));
     $this->assertTrue($cache2->inCache('foo.b/bar.txt'));
     $this->assertTrue($cache2->inCache('foo.b/bar'));
     $this->assertTrue($cache2->inCache('foo.b/bar/bar.txt'));
     $cachedTarget = [];
     $cachedTarget[] = $cache2->get('foo.b');
     $cachedTarget[] = $cache2->get('foo.b/foo.txt');
     $cachedTarget[] = $cache2->get('foo.b/bar.txt');
     $cachedTarget[] = $cache2->get('foo.b/bar');
     $cachedTarget[] = $cache2->get('foo.b/bar/bar.txt');
     foreach ($cached as $i => $old) {
         $new = $cachedTarget[$i];
         $this->assertEquals($old['mtime'], $new['mtime']);
         $this->assertEquals($old['size'], $new['size']);
         $this->assertEquals($old['etag'], $new['etag']);
         $this->assertEquals($old['fileid'], $new['fileid']);
         $this->assertEquals($old['mimetype'], $new['mimetype']);
     }
 }
コード例 #11
0
ファイル: updaterlegacy.php プロジェクト: ninjasilicon/core
	public function testTouchWithMountPoints() {
		$storage2 = new \OC\Files\Storage\Temporary(array());
		$cache2 = $storage2->getCache();
		Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
		Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
		$this->assertTrue($cache2->inCache('foo.txt'));
		$folderCachedData = $this->cache->get('folder');
		$substorageCachedData = $cache2->get('');
		$fooCachedData = $cache2->get('foo.txt');
		$cachedData = $cache2->get('foo.txt');
		$time = 1371006070;
		$this->cache->put('folder', ['mtime' => $time - 100]);
		Filesystem::touch('folder/substorage/foo.txt', $time);
		$cachedData = $cache2->get('foo.txt');
		$this->assertInternalType('string', $fooCachedData['etag']);
		$this->assertInternalType('string', $cachedData['etag']);
		$this->assertNotSame($fooCachedData['etag'], $cachedData['etag']);
		$this->assertEquals($time, $cachedData['mtime']);

		$cachedData = $cache2->get('');
		$this->assertInternalType('string', $substorageCachedData['etag']);
		$this->assertInternalType('string', $cachedData['etag']);
		$this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);

		$cachedData = $this->cache->get('folder');
		$this->assertInternalType('string', $folderCachedData['etag']);
		$this->assertInternalType('string', $cachedData['etag']);
		$this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
		$this->assertEquals($time, $cachedData['mtime']);
	}
コード例 #12
0
ファイル: scanner.php プロジェクト: evanjt/core
 public function testScanSubMount()
 {
     $uid = $this->getUniqueID();
     $this->userBackend->createUser($uid, 'test');
     $mountProvider = $this->getMock('\\OCP\\Files\\Config\\IMountProvider');
     $storage = new Temporary(array());
     $mount = new MountPoint($storage, '/' . $uid . '/files/foo');
     $mountProvider->expects($this->any())->method('getMountsForUser')->will($this->returnCallback(function (IUser $user, IStorageFactory $storageFactory) use($mount, $uid) {
         if ($user->getUID() === $uid) {
             return [$mount];
         } else {
             return [];
         }
     }));
     \OC::$server->getMountProviderCollection()->registerProvider($mountProvider);
     $cache = $storage->getCache();
     $storage->mkdir('folder');
     $storage->file_put_contents('foo.txt', 'qwerty');
     $storage->file_put_contents('folder/bar.txt', 'qwerty');
     $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
     $this->assertFalse($cache->inCache('folder/bar.txt'));
     $scanner->scan('/' . $uid . '/files/foo');
     $this->assertTrue($cache->inCache('folder/bar.txt'));
 }
コード例 #13
0
 public function testFopenExistingFileNoUpdate()
 {
     $this->sourceStorage->touch('foo');
     $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
     $this->assertFalse($storage->fopen('foo', 'w'));
 }
コード例 #14
0
ファイル: ViewTest.php プロジェクト: rchicoli/owncloud-core
 public function testDeleteGhostFolder()
 {
     $storage = new Temporary(array());
     $scanner = $storage->getScanner();
     $cache = $storage->getCache();
     $storage->mkdir('foo');
     $storage->file_put_contents('foo/foo.txt', 'bar');
     \OC\Files\Filesystem::mount($storage, array(), '/test/');
     $scanner->scan('');
     $storage->rmdir('foo');
     $this->assertTrue($cache->inCache('foo'));
     $this->assertTrue($cache->inCache('foo/foo.txt'));
     $view = new \OC\Files\View('/test');
     $rootInfo = $view->getFileInfo('');
     $this->assertEquals(3, $rootInfo->getSize());
     $view->rmdir('foo');
     $newInfo = $view->getFileInfo('');
     $this->assertFalse($cache->inCache('foo'));
     $this->assertFalse($cache->inCache('foo/foo.txt'));
     $this->assertNotEquals($rootInfo->getEtag(), $newInfo->getEtag());
     $this->assertEquals(0, $newInfo->getSize());
 }
コード例 #15
0
 public function testIsCached()
 {
     $sourceFile = __DIR__ . '/../data/testimage.png';
     $userId = $this->getUniqueID();
     $this->createUser($userId, 'pass');
     $storage = new Temporary();
     $storage->mkdir('files');
     $this->registerMount($userId, $storage, '/' . $userId);
     \OC_Util::tearDownFS();
     \OC_Util::setupFS($userId);
     $preview = new \OC\Preview($userId, 'files');
     $view = new View('/' . $userId . '/files');
     $view->file_put_contents('test.png', file_get_contents($sourceFile));
     $info = $view->getFileInfo('test.png');
     $preview->setFile('test.png', $info);
     $preview->setMaxX(64);
     $preview->setMaxY(64);
     $this->assertFalse($preview->isCached($info->getId()));
     $preview->getPreview();
     $this->assertEquals('thumbnails/' . $info->getId() . '/64-64.png', $preview->isCached($info->getId()));
 }
コード例 #16
0
ファイル: jail.php プロジェクト: ninjasilicon/core
	public function testFilePutContentsRooted() {
		$this->instance->file_put_contents('bar', 'asd');
		$this->assertEquals('asd', $this->sourceStorage->file_get_contents('foo/bar'));
	}
コード例 #17
0
ファイル: scanner.php プロジェクト: stweil/owncloud-core
 public function testPropagateEtag()
 {
     $storage = new Temporary(array());
     $mount = new MountPoint($storage, '');
     Filesystem::getMountManager()->addMount($mount);
     $cache = $storage->getCache();
     $storage->mkdir('folder');
     $storage->file_put_contents('folder/bar.txt', 'qwerty');
     $storage->touch('folder/bar.txt', time() - 200);
     $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
     $scanner->addMount($mount);
     $scanner->scan('');
     $this->assertTrue($cache->inCache('folder/bar.txt'));
     $oldRoot = $cache->get('');
     $storage->file_put_contents('folder/bar.txt', 'qwerty');
     $scanner->scan('');
     $newRoot = $cache->get('');
     $this->assertNotEquals($oldRoot->getEtag(), $newRoot->getEtag());
 }
コード例 #18
0
ファイル: view.php プロジェクト: heldernl/owncloud8-extended
 public function testRenameCrossStoragePreserveMtime()
 {
     $storage1 = new Temporary(array());
     $storage2 = new Temporary(array());
     $scanner1 = $storage1->getScanner();
     $scanner2 = $storage2->getScanner();
     $storage1->mkdir('sub');
     $storage1->mkdir('foo');
     $storage1->file_put_contents('foo.txt', 'asd');
     $storage1->file_put_contents('foo/bar.txt', 'asd');
     \OC\Files\Filesystem::mount($storage1, array(), '/test/');
     \OC\Files\Filesystem::mount($storage2, array(), '/test/sub/storage');
     $view = new \OC\Files\View('');
     $time = time() - 200;
     $view->touch('/test/foo.txt', $time);
     $view->touch('/test/foo', $time);
     $view->touch('/test/foo/bar.txt', $time);
     $view->rename('/test/foo.txt', '/test/sub/storage/foo.txt');
     $this->assertEquals($time, $view->filemtime('/test/sub/storage/foo.txt'));
     $view->rename('/test/foo', '/test/sub/storage/foo');
     $this->assertEquals($time, $view->filemtime('/test/sub/storage/foo/bar.txt'));
 }
コード例 #19
0
ファイル: view.php プロジェクト: riso/owncloud-core
 public function testWatcherEtagCrossStorage()
 {
     $storage1 = new Temporary(array());
     $storage2 = new Temporary(array());
     $scanner1 = $storage1->getScanner();
     $scanner2 = $storage2->getScanner();
     $storage1->mkdir('sub');
     \OC\Files\Filesystem::mount($storage1, array(), '/test/');
     \OC\Files\Filesystem::mount($storage2, array(), '/test/sub/storage');
     $past = time() - 100;
     $storage2->file_put_contents('test.txt', 'foobar');
     $scanner1->scan('');
     $scanner2->scan('');
     $view = new \OC\Files\View('');
     $storage2->getWatcher('')->setPolicy(Watcher::CHECK_ALWAYS);
     $oldFileInfo = $view->getFileInfo('/test/sub/storage/test.txt');
     $oldFolderInfo = $view->getFileInfo('/test');
     $storage2->getCache()->update($oldFileInfo->getId(), array('storage_mtime' => $past));
     $view->getFileInfo('/test/sub/storage/test.txt');
     $newFolderInfo = $view->getFileInfo('/test');
     $this->assertNotEquals($newFolderInfo->getEtag(), $oldFolderInfo->getEtag());
 }
コード例 #20
0
ファイル: view.php プロジェクト: stweil/owncloud-core
 public function testFilePutContentsClearsChecksum()
 {
     $storage = new Temporary(array());
     $scanner = $storage->getScanner();
     $storage->file_put_contents('foo.txt', 'bar');
     \OC\Files\Filesystem::mount($storage, array(), '/test/');
     $scanner->scan('');
     $view = new \OC\Files\View('/test/foo.txt');
     $view->putFileInfo('.', ['checksum' => '42']);
     $this->assertEquals('bar', $view->file_get_contents(''));
     $fh = tmpfile();
     fwrite($fh, 'fooo');
     rewind($fh);
     $view->file_put_contents('', $fh);
     $this->assertEquals('fooo', $view->file_get_contents(''));
     $data = $view->getFileInfo('.');
     $this->assertEquals('', $data->getChecksum());
 }