diff --git a/tests/TestHelpers/CliHelper.php b/tests/TestHelpers/CliHelper.php new file mode 100644 index 000000000..fee84ad33 --- /dev/null +++ b/tests/TestHelpers/CliHelper.php @@ -0,0 +1,46 @@ + + * @copyright Copyright (c) 2024 Sajan Gurung sajan@jankaritech.com + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, + * as published by the Free Software Foundation; + * either version 3 of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + */ + +namespace TestHelpers; + +use GuzzleHttp\Exception\ConnectException; +use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\Psr7\Request; +use Psr\Http\Message\ResponseInterface; +use TestHelpers\OcisConfigHelper; + +/** + * A helper class for running oCIS CLI commands + */ +class CliHelper { + + /** + * @param array $body + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function runCommand(array $body): ResponseInterface { + $url = OcisConfigHelper::getWrapperUrl() . "/command"; + return OcisConfigHelper::sendRequest($url, "POST", \json_encode($body)); + } +} \ No newline at end of file diff --git a/tests/TestHelpers/OcisConfigHelper.php b/tests/TestHelpers/OcisConfigHelper.php index aa9781d58..70e49b014 100644 --- a/tests/TestHelpers/OcisConfigHelper.php +++ b/tests/TestHelpers/OcisConfigHelper.php @@ -40,7 +40,7 @@ class OcisConfigHelper { * @return ResponseInterface * @throws GuzzleException */ - private static function sendRequest( + public static function sendRequest( string $url, string $method, ?string $body = "" @@ -54,10 +54,18 @@ class OcisConfigHelper { ); try { - return $client->send($request); + $response = $client->send($request); } catch (ConnectException $e) { throw new \Error("Cannot connect to the ociswrapper at the moment, make sure that ociswrapper is running before proceeding with the test run.\n" . $e->getMessage()); + } catch (GuzzleException $ex) { + $response = $ex->getResponse(); + + if ($response === null) { + throw $ex; + } } + + return $response; } /** @@ -90,4 +98,22 @@ class OcisConfigHelper { $url = self::getWrapperUrl() . "/rollback"; return self::sendRequest($url, "DELETE"); } + + /** + * @return ResponseInterface + * @throws GuzzleException + */ + public static function stopOcis(): ResponseInterface { + $url = self::getWrapperUrl() . "/stop"; + return self::sendRequest($url, "POST"); + } + + /** + * @return ResponseInterface + * @throws GuzzleException + */ + public static function startOcis(): ResponseInterface { + $url = self::getWrapperUrl() . "/start"; + return self::sendRequest($url, "POST"); + } } diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 17c1604c1..b3a308d0b 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -368,6 +368,14 @@ default: - SharingNgContext: - SpacesContext: + cliResetPassword: + paths: + - "%paths.base%/../features/cliResetPassword" + context: *common_ldap_suite_context + contexts: + - FeatureContext: *common_feature_context_params + - CliContext: + extensions: rdx\behatvars\BehatVariablesExtension: ~