public function setUp() { $this->connection = \OC::$server->getDatabaseConnection(); $this->userManager = new Manager(null); $userBackend = new Dummy(); $userBackend->createUser('u1', ''); $userBackend->createUser('u2', ''); $this->userManager->registerBackend($userBackend); $this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, $this->getMock('\\OC\\Log')); }
public function setUp() { parent::setUp(); $this->userBackend = new \Test\Util\User\Dummy(); \OC::$server->getUserManager()->registerBackend($this->userBackend); $this->ownerUid = $this->getUniqueID('owner_'); $this->recipientUid = $this->getUniqueID('recipient_'); $this->userBackend->createUser($this->ownerUid, ''); $this->userBackend->createUser($this->recipientUid, ''); $this->loginAsUser($this->ownerUid); Filesystem::mkdir('/foo'); Filesystem::file_put_contents('/foo/bar.txt', 'asd'); $fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId(); \OCP\Share::shareItem('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->recipientUid, 31); $this->loginAsUser($this->recipientUid); $this->assertTrue(Filesystem::file_exists('bar.txt')); }
public function testNewUser() { $user1 = $this->getUniqueID('user_'); $this->userBackend->createUser($user1, ''); $this->loginAsUser($user1); Filesystem::mkdir('/folder'); Filesystem::mkdir('/folder/subfolder'); Filesystem::file_put_contents('/foo.txt', 'asd'); Filesystem::file_put_contents('/folder/bar.txt', 'fgh'); Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl'); $files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt'); $originalEtags = $this->getEtags($files); $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->backgroundScan('/'); $newEtags = $this->getEtags($files); // loop over array and use assertSame over assertEquals to prevent false positives foreach ($originalEtags as $file => $originalEtag) { $this->assertSame($originalEtag, $newEtags[$file]); } }
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')); }
protected function createUser($name, $password) { $this->userBackend->createUser($name, $password); }