/** * @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; }
/** * @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')); }
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()); }
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 MountPoint($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']); }
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')); }
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')); }
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()); }
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')); }
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()); }