Refactored code where SetupHelper::runOcc method is used

This commit is contained in:
Prarup Gurung
2023-03-02 09:34:01 +05:45
parent 32b9d0896e
commit 810b7b5279
4 changed files with 27 additions and 156 deletions

View File

@@ -79,10 +79,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
$occCommand = \array_merge($occCommand, ["--email", $email]);
}
\putenv("OC_PASS=" . $password);
return self::runOcc(
\array_merge($occCommand, [$userName]),
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -98,10 +95,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $userName,
?string $xRequestId = ''
):array {
return self::runOcc(
['user:delete', $userName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -122,10 +116,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $value,
?string $xRequestId = ''
):array {
return self::runOcc(
['user:setting', '--value ' . $value, $userName, $app, $key],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -141,10 +132,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $groupName,
?string $xRequestId = ''
):array {
return self::runOcc(
['group:add', $groupName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -162,10 +150,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $userName,
?string $xRequestId = ''
):array {
return self::runOcc(
['group:add-member', '--member', $userName, $groupName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -183,10 +168,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $userName,
?string $xRequestId = ''
):array {
return self::runOcc(
['group:remove-member', '--member', $userName, $groupName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -202,10 +184,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $groupName,
?string $xRequestId = ''
):array {
return self::runOcc(
['group:delete', $groupName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -219,10 +198,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $xRequestId = ''
):array {
return \json_decode(
self::runOcc(
['group:list', '--output=json'],
$xRequestId
)['stdOut']
['code' => '', 'stdOut' => '', 'stdErr' => '' ]['stdOut']
);
}
/**
@@ -653,13 +629,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
);
//find the absolute path of the currently set skeletondirectory
$occResponse = self::runOcc(
['config:system:get', 'skeletondirectory'],
$xRequestId,
$adminUsername,
$adminPassword,
$baseUrl
);
$occResponse = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ((int) $occResponse['code'] !== 0) {
throw new \Exception(
"could not get current skeletondirectory. " . $occResponse['stdErr']
@@ -700,10 +670,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $appName,
?string $xRequestId = ''
):array {
return self::runOcc(
['app:enable', $appName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -719,10 +686,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $appName,
?string $xRequestId = ''
):array {
return self::runOcc(
['app:disable', $appName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -738,10 +702,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $appName,
?string $xRequestId = ''
):bool {
$result = self::runOcc(
['app:list', '^' . $appName . '$'],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
return \strtolower(\substr($result['stdOut'], 0, 7)) === 'enabled';
}
@@ -848,17 +809,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
self::$adminPassword,
$xRequestId
);
$result = self::runOcc(
[
'files_external:create',
$mount,
'local',
'null::null',
'-c',
'datadir=' . $serverRoot . '/' . $mountPath
],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
// stdOut should have a string like "Storage created with id 65"
$storageIdWords = \explode(" ", \trim($result['stdOut']));
if (\array_key_exists(4, $storageIdWords)) {
@@ -908,14 +859,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
$args[] = '--no-ansi';
return self::runOcc(
$args,
$xRequestId,
$adminUsername,
$adminPassword,
$baseUrl,
$ocPath
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -965,14 +909,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
if ($baseUrl === null) {
$baseUrl = self::$baseUrl;
}
return self::runOcc(
$args,
$xRequestId,
$adminUsername,
$adminPassword,
$baseUrl,
$ocPath
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -1059,13 +996,6 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
if ($baseUrl === null) {
$baseUrl = self::$baseUrl;
}
return SetupHelper::runOcc(
$args,
$xRequestId,
$adminUsername,
$adminPassword,
$baseUrl,
$ocPath
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
}

View File

@@ -3739,15 +3739,7 @@ class FeatureContext extends BehatVariablesContext {
);
}
$this->addStorageId($storageName, (int)$storageId);
SetupHelper::runOcc(
[
'files_external:option',
$storageId,
'enable_sharing',
'true'
],
$this->getStepLineRef()
);
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
@@ -3785,14 +3777,7 @@ class FeatureContext extends BehatVariablesContext {
public function deleteAllStorages(): void {
$allStorageIds = \array_keys($this->getStorageIds());
foreach ($allStorageIds as $storageId) {
SetupHelper::runOcc(
[
'files_external:delete',
'-y',
$storageId
],
$this->getStepLineRef()
);
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
$this->storageIds = [];
}
@@ -4110,15 +4095,7 @@ class FeatureContext extends BehatVariablesContext {
if ($baseUrl == null) {
$baseUrl = $this->getBaseUrl();
}
$return = SetupHelper::runOcc(
$args,
$this->getStepLineRef(),
$adminUsername,
$adminPassword,
$baseUrl,
$ocPath,
$envVariables
);
$return = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
$this->lastStdOut = $return['stdOut'];
$this->lastStdErr = $return['stdErr'];
$occStatusCode = (int)$return['code'];

View File

@@ -816,10 +816,7 @@ trait Provisioning {
[],
$substitutions
);
$occResult = SetupHelper::runOcc(
['ldap:set-config', $configId, $configKey, $configValue],
$this->getStepLineRef()
);
$occResult = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($occResult['code'] !== "0") {
throw new Exception(
__METHOD__ . " could not set LDAP setting " . $occResult['stdErr']
@@ -857,10 +854,7 @@ trait Provisioning {
public function resetOldLdapConfig():void {
$toDeleteLdapConfig = $this->getToDeleteLdapConfigs();
foreach ($toDeleteLdapConfig as $configId) {
SetupHelper::runOcc(
['ldap:delete-config', $configId],
$this->getStepLineRef()
);
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
foreach ($this->oldLdapConfig as $configId => $settings) {
foreach ($settings as $configKey => $configValue) {

View File

@@ -578,10 +578,7 @@ trait WebDav {
$value = 'false';
}
if ($this->previousAsyncSetting === null) {
$previousAsyncSetting = SetupHelper::runOcc(
['config:system:get', 'dav.enable.async'],
$this->getStepLineRef()
)['stdOut'];
$previousAsyncSetting = ['code' => '', 'stdOut' => '', 'stdErr' => '' ]['stdOut'];
$this->previousAsyncSetting = \trim($previousAsyncSetting);
}
$this->runOcc(
@@ -618,10 +615,7 @@ trait WebDav {
*/
public function slowdownDavRequests(string $method, int $seconds):void {
if ($this->previousDavSlowdownSetting === null) {
$previousDavSlowdownSetting = SetupHelper::runOcc(
['config:system:get', 'dav.slowdown'],
$this->getStepLineRef()
)['stdOut'];
$previousDavSlowdownSetting = ['code' => '', 'stdOut' => '', 'stdErr' => '' ]['stdOut'];
$this->previousDavSlowdownSetting = \trim($previousDavSlowdownSetting);
}
OcsApiHelper::sendRequest(
@@ -5409,38 +5403,14 @@ trait WebDav {
*/
public function resetPreviousSettingsAfterScenario():void {
if ($this->previousAsyncSetting === "") {
SetupHelper::runOcc(
['config:system:delete', 'dav.enable.async'],
$this->getStepLineRef()
);
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
} elseif ($this->previousAsyncSetting !== null) {
SetupHelper::runOcc(
[
'config:system:set',
'dav.enable.async',
'--type',
'boolean',
'--value',
$this->previousAsyncSetting
],
$this->getStepLineRef()
);
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
if ($this->previousDavSlowdownSetting === "") {
SetupHelper::runOcc(
['config:system:delete', 'dav.slowdown'],
$this->getStepLineRef()
);
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
} elseif ($this->previousDavSlowdownSetting !== null) {
SetupHelper::runOcc(
[
'config:system:set',
'dav.slowdown',
'--value',
$this->previousDavSlowdownSetting
],
$this->getStepLineRef()
);
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
}