Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix risky test without assertion #32761

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/private/Encryption/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\Encryption\IEncryptionModule;
use OCP\IConfig;
use OCP\IUser;
use OCP\App\IAppManager;

class Util {
public const HEADER_START = 'HBEGIN';
Expand Down Expand Up @@ -299,7 +300,8 @@ public function getUserWithAccessToMountPoint($users, $groups) {
* @return boolean
*/
public function isSystemWideMountPoint($path, $uid) {
if (\OCP\App::isEnabled("files_external")) {
$appManager = \OC::$server->get(IAppManager::class);
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
if ($appManager->isEnabledForUser('files_external', null)) {
/** @var GlobalStoragesService $storageService */
$storageService = \OC::$server->get(GlobalStoragesService::class);
$storages = $storageService->getAllStorages();
Expand Down
1 change: 0 additions & 1 deletion tests/enable_all.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function enableApp($app) {

enableApp('files_sharing');
enableApp('files_trashbin');
enableApp('files_external');
enableApp('encryption');
enableApp('user_ldap');
enableApp('files_versions');
Expand Down
29 changes: 24 additions & 5 deletions tests/lib/Encryption/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use OC\Encryption\Util;
use OC\Files\View;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\GlobalStoragesService;
use OCP\App\IAppManager;
use OCP\Encryption\IEncryptionModule;
use OCP\IConfig;
use Test\TestCase;
Expand Down Expand Up @@ -207,6 +206,15 @@ public function dataTestIsSystemWideMountPoint() {
* @dataProvider dataTestIsSystemWideMountPoint
*/
public function testIsSystemWideMountPoint($expectedResult, $expectationText, $applicableUsers, $applicableGroups, $mountPointName = '/mp') {
$appManager = $this->createMock(IAppManager::class);
$appManager
->expects($this->once())
->method('isEnabledForUser')
->with('files_external')
->willReturn(true);

$this->overwriteService(IAppManager::class, $appManager);

$this->groupManager->method('isInGroup')
->will($this->returnValueMap([
['user1', 'group1', true], // user is only in group1
Expand All @@ -215,17 +223,28 @@ public function testIsSystemWideMountPoint($expectedResult, $expectationText, $a

$storages = [];

$storageConfig = $this->createMock(StorageConfig::class);
// StorageConfig
$storageConfig = $this->getMockBuilder('OCA\\Files_External\\Lib\\StorageConfig')
->setMethods([
'getMountPoint',
'getApplicableUsers',
'getApplicableGroups',
])
->getMock();
$storageConfig->method('getMountPoint')->willReturn($mountPointName);
$storageConfig->method('getApplicableUsers')->willReturn($applicableUsers);
$storageConfig->method('getApplicableGroups')->willReturn($applicableGroups);
$storages[] = $storageConfig;

$storagesServiceMock = $this->createMock(GlobalStoragesService::class);
$storagesServiceMock = $this->getMockBuilder('OCA\\Files_External\\Service\\GlobalStoragesService')
->setMethods([
'getAllStorages',
])
->getMock();
$storagesServiceMock->expects($this->atLeastOnce())->method('getAllStorages')
->willReturn($storages);

$this->overwriteService(GlobalStoragesService::class, $storagesServiceMock);
$this->overwriteService('OCA\\Files_External\\Service\\GlobalStoragesService', $storagesServiceMock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why for core class you went from string to ::class and for files-external classes you go the other way around?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because core classes are fine. This class might not be loaded as the test is in core and the app is not force enabled nor default enabled

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe some day... owncloud/core#25422


$this->assertEquals($expectedResult, $this->util->isSystemWideMountPoint('/files/mp', 'user1'), 'Test case: ' . $expectationText);
}
Expand Down