/** * Allows us to test private methods/properties * * @param $object * @param $methodName * @param array $parameters * @return mixed * @deprecated Please extend \Test\TestCase and use self::invokePrivate() then */ public static function invokePrivate($object, $methodName, array $parameters = array()) { return parent::invokePrivate($object, $methodName, $parameters); }
protected function tearDown() { \OC_User::setUserId($this->user); foreach ($this->storages as $storage) { $cache = $storage->getCache(); $ids = $cache->getAll(); $cache->clear(); } if ($this->tempStorage && !\OC_Util::runningOnWindows()) { system('rm -rf ' . escapeshellarg($this->tempStorage->getDataDir())); } $this->logout(); $this->userObject->delete(); $this->groupObject->delete(); $mountProviderCollection = \OC::$server->getMountProviderCollection(); \Test\TestCase::invokePrivate($mountProviderCollection, 'providers', [[]]); parent::tearDown(); }
/** * Test locks when moving a mount point */ public function testLockMoveMountPoint() { $this->loginAsUser('test'); $subStorage = $this->getMockBuilder('\\OC\\Files\\Storage\\Temporary')->setMethods([])->getMock(); $mount = $this->getMock('\\Test\\TestMoveableMountPoint', ['moveMount'], [$subStorage, $this->user . '/files/substorage']); $mountProvider = $this->getMock('\\OCP\\Files\\Config\\IMountProvider'); $mountProvider->expects($this->once())->method('getMountsForUser')->will($this->returnValue([$mount])); $mountProviderCollection = \OC::$server->getMountProviderCollection(); $mountProviderCollection->registerProvider($mountProvider); $view = new \OC\Files\View('/' . $this->user . '/files/'); $view->mkdir('subdir'); $sourcePath = 'substorage'; $targetPath = 'subdir/substorage_moved'; $mount->expects($this->once())->method('moveMount')->will($this->returnCallback(function ($target) use($mount, $view, $sourcePath, $targetPath, &$lockTypeSourceDuring, &$lockTypeTargetDuring, &$lockTypeSharedRootDuring) { $lockTypeSourceDuring = $this->getFileLockType($view, $sourcePath, true); $lockTypeTargetDuring = $this->getFileLockType($view, $targetPath, true); $lockTypeSharedRootDuring = $this->getFileLockType($view, $sourcePath, false); $mount->setMountPoint($target); return true; })); $this->connectMockHooks('rename', $view, $sourcePath, $lockTypeSourcePre, $lockTypeSourcePost, true); $this->connectMockHooks('rename', $view, $targetPath, $lockTypeTargetPre, $lockTypeTargetPost, true); // in pre-hook, mount point is still on $sourcePath $this->connectMockHooks('rename', $view, $sourcePath, $lockTypeSharedRootPre, $dummy, false); // in post-hook, mount point is now on $targetPath $this->connectMockHooks('rename', $view, $targetPath, $dummy, $lockTypeSharedRootPost, false); $this->assertNull($this->getFileLockType($view, $sourcePath, false), 'Shared storage root not locked before operation'); $this->assertNull($this->getFileLockType($view, $sourcePath, true), 'Source path not locked before operation'); $this->assertNull($this->getFileLockType($view, $targetPath, true), 'Target path not locked before operation'); $view->rename($sourcePath, $targetPath); $this->assertEquals(ILockingProvider::LOCK_SHARED, $lockTypeSourcePre, 'Source path locked properly during pre-hook'); $this->assertEquals(ILockingProvider::LOCK_EXCLUSIVE, $lockTypeSourceDuring, 'Source path locked properly during operation'); $this->assertEquals(ILockingProvider::LOCK_SHARED, $lockTypeSourcePost, 'Source path locked properly during post-hook'); $this->assertEquals(ILockingProvider::LOCK_SHARED, $lockTypeTargetPre, 'Target path locked properly during pre-hook'); $this->assertEquals(ILockingProvider::LOCK_EXCLUSIVE, $lockTypeTargetDuring, 'Target path locked properly during operation'); $this->assertEquals(ILockingProvider::LOCK_SHARED, $lockTypeTargetPost, 'Target path locked properly during post-hook'); $this->assertNull($lockTypeSharedRootPre, 'Shared storage root not locked during pre-hook'); $this->assertNull($lockTypeSharedRootDuring, 'Shared storage root not locked during move'); $this->assertNull($lockTypeSharedRootPost, 'Shared storage root not locked during post-hook'); $this->assertNull($this->getFileLockType($view, $sourcePath, false), 'Shared storage root not locked after operation'); $this->assertNull($this->getFileLockType($view, $sourcePath, true), 'Source path not locked after operation'); $this->assertNull($this->getFileLockType($view, $targetPath, true), 'Target path not locked after operation'); \Test\TestCase::invokePrivate($mountProviderCollection, 'providers', [[]]); }