/** * @dataProvider deleteStorageDataProvider */ public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) { $backend = $this->backendService->getBackend('identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\\Auth\\Mechanism'); $storage = new StorageConfig(255); $storage->setMountPoint('mountpoint'); $storage->setBackend($backend); $storage->setAuthMechanism($authMechanism); $storage->setBackendOptions($backendOptions); $newStorage = $this->service->addStorage($storage); $id = $newStorage->getId(); // manually trigger storage entry because normally it happens on first // access, which isn't possible within this test $storageCache = new \OC\Files\Cache\Storage($rustyStorageId); // get numeric id for later check $numericId = $storageCache->getNumericId(); $this->service->removeStorage($id); $caught = false; try { $this->service->getStorage(1); } catch (NotFoundException $e) { $caught = true; } $this->assertTrue($caught); // storage id was removed from oc_storages $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $storageCheckQuery = $qb->select('*')->from('storages')->where($qb->expr()->eq('numeric_id', $qb->expr()->literal($numericId))); $this->assertCount($expectedCountAfterDeletion, $storageCheckQuery->execute()->fetchAll()); }
/** * Get an external storage entry. * * @param int $id storage id * * @return DataResponse */ public function show($id) { try { $storage = $this->service->getStorage($id); $this->updateStorageStatus($storage); } catch (NotFoundException $e) { return new DataResponse(['message' => (string) $this->l10n->t('Storage with id "%i" not found', array($id))], Http::STATUS_NOT_FOUND); } return new DataResponse($storage, Http::STATUS_OK); }
/** * @expectedException \OCA\Files_External\NotFoundException */ public function testGetAdminStorage() { $backend = $this->backendService->getBackend('identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\\Auth\\Mechanism'); $storage = new StorageConfig(); $storage->setMountPoint('mountpoint'); $storage->setBackend($backend); $storage->setAuthMechanism($authMechanism); $storage->setBackendOptions(['password' => 'testPassword']); $storage->setApplicableUsers([$this->userId]); $newStorage = $this->globalStoragesService->addStorage($storage); $this->assertInstanceOf('\\OCA\\Files_External\\Lib\\StorageConfig', $this->globalStoragesService->getStorage($newStorage->getId())); $this->service->getStorage($newStorage->getId()); }
public function testUpdateStorageMountPoint() { $backend = $this->backendService->getBackend('identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\\Auth\\Mechanism'); $storage = new StorageConfig(); $storage->setMountPoint('mountpoint'); $storage->setBackend($backend); $storage->setAuthMechanism($authMechanism); $storage->setBackendOptions(['password' => 'testPassword']); $savedStorage = $this->service->addStorage($storage); $newAuthMechanism = $this->backendService->getAuthMechanism('identifier:\\Other\\Auth\\Mechanism'); $updatedStorage = new StorageConfig($savedStorage->getId()); $updatedStorage->setMountPoint('mountpoint2'); $updatedStorage->setBackend($backend); $updatedStorage->setAuthMechanism($newAuthMechanism); $updatedStorage->setBackendOptions(['password' => 'password2']); $this->service->updateStorage($updatedStorage); $savedStorage = $this->service->getStorage($updatedStorage->getId()); $this->assertEquals('/mountpoint2', $savedStorage->getMountPoint()); $this->assertEquals($newAuthMechanism, $savedStorage->getAuthMechanism()); $this->assertEquals('password2', $savedStorage->getBackendOption('password')); }