protected function setupUser($name, $password) { $this->userBackend->createUser($name, $password); \OC::$server->getMountProviderCollection()->registerProvider($this->getMountProvider($name, ['/' . $name => new Temporary()])); $this->loginAsUser($name); return new View('/' . $name . '/files'); }
protected function setUp() { parent::setUp(); $userBackend = new \OC_User_Dummy(); $userBackend->createUser(self::TEST_FILESYSTEM_USER1, self::TEST_FILESYSTEM_USER1); $userBackend->createUser(self::TEST_FILESYSTEM_USER2, self::TEST_FILESYSTEM_USER2); \OC::$server->getUserManager()->registerBackend($userBackend); $this->loginAsUser(); }
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()); $this->assertFalse($cache->inCache('folder/bar.txt')); $scanner->scan('/' . $uid . '/files/foo'); $this->assertTrue($cache->inCache('folder/bar.txt')); }
public function setUp() { parent::setUp(); $this->userBackend = new \OC_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()); $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 testNewUser() { $user1 = uniqid('user_'); $this->userBackend->createUser($user1, ''); \OC_Util::tearDownFS(); \OC_User::setUserId($user1); \OC_Util::setupFS($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); $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]); } }
/** * @param string $user * @param bool $create * @param bool $password */ public static function loginHelper($user, $create = false) { if ($create) { $backend = new \OC_User_Dummy(); $backend->createUser($user, $user); \OC::$server->getUserManager()->registerBackend($backend); } $storage = new \ReflectionClass('\\OC\\Files\\Storage\\Shared'); $isInitialized = $storage->getProperty('isInitialized'); $isInitialized->setAccessible(true); $isInitialized->setValue(array()); $isInitialized->setAccessible(false); \OC_Util::tearDownFS(); \OC_User::setUserId(''); \OC\Files\Filesystem::tearDown(); \OC_User::setUserId($user); \OC_Util::setupFS($user); \OC::$server->getUserFolder($user); }
protected function createUser($name, $password) { $this->userBackend->createUser($name, $password); }
public function testDeleteUser() { $manager = new \OC\User\Manager(); $backend = new \OC_User_Dummy(); $backend->createUser('foo', 'bar'); $manager->registerBackend($backend); $this->assertTrue($manager->userExists('foo')); $manager->get('foo')->delete(); $this->assertFalse($manager->userExists('foo')); }