Merge pull request #7396 from owncloud/tests/remove-unsed-steps
[tests-only] Remove AppConfigurationContext file
This commit is contained in:
@@ -18,10 +18,10 @@ default:
|
|||||||
adminPassword: admin
|
adminPassword: admin
|
||||||
regularUserPassword: 123456
|
regularUserPassword: 123456
|
||||||
ocPath: apps/testing/api/v1/occ
|
ocPath: apps/testing/api/v1/occ
|
||||||
- AppConfigurationContext:
|
|
||||||
- ChecksumContext:
|
- ChecksumContext:
|
||||||
- FilesVersionsContext:
|
- FilesVersionsContext:
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
|
- CapabilitiesContext:
|
||||||
|
|
||||||
coreApiAuth:
|
coreApiAuth:
|
||||||
paths:
|
paths:
|
||||||
@@ -57,7 +57,6 @@ default:
|
|||||||
contexts:
|
contexts:
|
||||||
- FeatureContext: *common_feature_context_params
|
- FeatureContext: *common_feature_context_params
|
||||||
- CapabilitiesContext:
|
- CapabilitiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiFavorites:
|
coreApiFavorites:
|
||||||
paths:
|
paths:
|
||||||
@@ -67,7 +66,6 @@ default:
|
|||||||
- FeatureContext: *common_feature_context_params
|
- FeatureContext: *common_feature_context_params
|
||||||
- FavoritesContext:
|
- FavoritesContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiShareCreateSpecialToShares1:
|
coreApiShareCreateSpecialToShares1:
|
||||||
paths:
|
paths:
|
||||||
@@ -77,7 +75,6 @@ default:
|
|||||||
- FeatureContext: *common_feature_context_params
|
- FeatureContext: *common_feature_context_params
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiShareCreateSpecialToShares2:
|
coreApiShareCreateSpecialToShares2:
|
||||||
paths:
|
paths:
|
||||||
@@ -87,7 +84,6 @@ default:
|
|||||||
- FeatureContext: *common_feature_context_params
|
- FeatureContext: *common_feature_context_params
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiSharees:
|
coreApiSharees:
|
||||||
paths:
|
paths:
|
||||||
@@ -96,7 +92,6 @@ default:
|
|||||||
contexts:
|
contexts:
|
||||||
- FeatureContext: *common_feature_context_params
|
- FeatureContext: *common_feature_context_params
|
||||||
- ShareesContext:
|
- ShareesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiShareManagementToShares:
|
coreApiShareManagementToShares:
|
||||||
paths:
|
paths:
|
||||||
@@ -107,7 +102,6 @@ default:
|
|||||||
- PublicWebDavContext:
|
- PublicWebDavContext:
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
- FilesVersionsContext:
|
- FilesVersionsContext:
|
||||||
|
|
||||||
coreApiShareManagementBasicToShares:
|
coreApiShareManagementBasicToShares:
|
||||||
@@ -150,7 +144,6 @@ default:
|
|||||||
- PublicWebDavContext:
|
- PublicWebDavContext:
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiSharePublicLink2:
|
coreApiSharePublicLink2:
|
||||||
paths:
|
paths:
|
||||||
@@ -161,7 +154,6 @@ default:
|
|||||||
- PublicWebDavContext:
|
- PublicWebDavContext:
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiSharePublicLink3:
|
coreApiSharePublicLink3:
|
||||||
paths:
|
paths:
|
||||||
@@ -172,7 +164,6 @@ default:
|
|||||||
- PublicWebDavContext:
|
- PublicWebDavContext:
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiShareReshareToShares1:
|
coreApiShareReshareToShares1:
|
||||||
paths:
|
paths:
|
||||||
@@ -193,7 +184,6 @@ default:
|
|||||||
- PublicWebDavContext:
|
- PublicWebDavContext:
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiShareReshareToShares3:
|
coreApiShareReshareToShares3:
|
||||||
paths:
|
paths:
|
||||||
@@ -204,7 +194,6 @@ default:
|
|||||||
- PublicWebDavContext:
|
- PublicWebDavContext:
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiShareUpdateToShares:
|
coreApiShareUpdateToShares:
|
||||||
paths:
|
paths:
|
||||||
@@ -215,7 +204,6 @@ default:
|
|||||||
- PublicWebDavContext:
|
- PublicWebDavContext:
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiTrashbin:
|
coreApiTrashbin:
|
||||||
paths:
|
paths:
|
||||||
@@ -224,7 +212,6 @@ default:
|
|||||||
contexts:
|
contexts:
|
||||||
- FeatureContext: *common_feature_context_params
|
- FeatureContext: *common_feature_context_params
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
|
|
||||||
coreApiTrashbinRestore:
|
coreApiTrashbinRestore:
|
||||||
@@ -234,7 +221,6 @@ default:
|
|||||||
contexts:
|
contexts:
|
||||||
- FeatureContext: *common_feature_context_params
|
- FeatureContext: *common_feature_context_params
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
|
|
||||||
coreApiVersions:
|
coreApiVersions:
|
||||||
@@ -246,7 +232,6 @@ default:
|
|||||||
- ChecksumContext:
|
- ChecksumContext:
|
||||||
- FilesVersionsContext:
|
- FilesVersionsContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
|
|
||||||
coreApiWebdavDelete:
|
coreApiWebdavDelete:
|
||||||
@@ -332,7 +317,6 @@ default:
|
|||||||
contexts:
|
contexts:
|
||||||
- FeatureContext: *common_feature_context_params
|
- FeatureContext: *common_feature_context_params
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiWebdavProperties2:
|
coreApiWebdavProperties2:
|
||||||
paths:
|
paths:
|
||||||
@@ -341,7 +325,6 @@ default:
|
|||||||
contexts:
|
contexts:
|
||||||
- FeatureContext: *common_feature_context_params
|
- FeatureContext: *common_feature_context_params
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiWebdavUpload1:
|
coreApiWebdavUpload1:
|
||||||
paths:
|
paths:
|
||||||
@@ -381,7 +364,6 @@ default:
|
|||||||
- PublicWebDavContext:
|
- PublicWebDavContext:
|
||||||
- FilesVersionsContext:
|
- FilesVersionsContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
coreApiWebdavEtagPropagation2:
|
coreApiWebdavEtagPropagation2:
|
||||||
paths:
|
paths:
|
||||||
@@ -393,7 +375,6 @@ default:
|
|||||||
- PublicWebDavContext:
|
- PublicWebDavContext:
|
||||||
- FilesVersionsContext:
|
- FilesVersionsContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- AppConfigurationContext:
|
|
||||||
|
|
||||||
extensions:
|
extensions:
|
||||||
rdx\behatvars\BehatVariablesExtension: ~
|
rdx\behatvars\BehatVariablesExtension: ~
|
||||||
|
|||||||
@@ -1,574 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
/**
|
|
||||||
* ownCloud
|
|
||||||
*
|
|
||||||
* @author Joas Schilling <coding@schilljs.com>
|
|
||||||
* @author Sergio Bertolin <sbertolin@owncloud.com>
|
|
||||||
* @author Phillip Davis <phil@jankaritech.com>
|
|
||||||
* @copyright Copyright (c) 2018, ownCloud GmbH
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
|
||||||
use PHPUnit\Framework\Assert;
|
|
||||||
use TestHelpers\AppConfigHelper;
|
|
||||||
use TestHelpers\OcsApiHelper;
|
|
||||||
use Behat\Gherkin\Node\TableNode;
|
|
||||||
use Behat\Behat\Context\Context;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AppConfiguration trait
|
|
||||||
*/
|
|
||||||
class AppConfigurationContext implements Context {
|
|
||||||
private FeatureContext $featureContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @When /^the administrator sets parameter "([^"]*)" of app "([^"]*)" to ((?:'[^']*')|(?:"[^"]*"))$/
|
|
||||||
*
|
|
||||||
* @param string $parameter
|
|
||||||
* @param string $app
|
|
||||||
* @param string $value
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function adminSetsServerParameterToUsingAPI(
|
|
||||||
string $parameter,
|
|
||||||
string $app,
|
|
||||||
string $value
|
|
||||||
):void {
|
|
||||||
// The capturing group of the regex always includes the quotes at each
|
|
||||||
// end of the captured string, so trim them.
|
|
||||||
$value = \trim($value, $value[0]);
|
|
||||||
$this->modifyAppConfig($app, $parameter, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Then the capabilities setting of :capabilitiesApp path :capabilitiesPath should be :expectedValue
|
|
||||||
* @Given the capabilities setting of :capabilitiesApp path :capabilitiesPath has been confirmed to be :expectedValue
|
|
||||||
*
|
|
||||||
* @param string $capabilitiesApp the "app" name in the capabilities response
|
|
||||||
* @param string $capabilitiesPath the path to the element
|
|
||||||
* @param string $expectedValue
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function theCapabilitiesSettingOfAppParameterShouldBe(
|
|
||||||
string $capabilitiesApp,
|
|
||||||
string $capabilitiesPath,
|
|
||||||
string $expectedValue
|
|
||||||
):void {
|
|
||||||
$this->theAdministratorGetsCapabilitiesCheckResponse();
|
|
||||||
$actualValue = $this->getAppParameter($capabilitiesApp, $capabilitiesPath);
|
|
||||||
|
|
||||||
Assert::assertEquals(
|
|
||||||
$expectedValue,
|
|
||||||
$actualValue,
|
|
||||||
__METHOD__
|
|
||||||
. " $capabilitiesApp path $capabilitiesPath should be $expectedValue but is $actualValue"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $capabilitiesApp the "app" name in the capabilities response
|
|
||||||
* @param string $capabilitiesPath the path to the element
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function getAppParameter(string $capabilitiesApp, string $capabilitiesPath):string {
|
|
||||||
return $this->getParameterValueFromXml(
|
|
||||||
$this->getCapabilitiesXml(__METHOD__),
|
|
||||||
$capabilitiesApp,
|
|
||||||
$capabilitiesPath
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @When user :username retrieves the capabilities using the capabilities API
|
|
||||||
*
|
|
||||||
* @param string $username
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws GuzzleException
|
|
||||||
* @throws JsonException
|
|
||||||
*/
|
|
||||||
public function userRetrievesCapabilities(string $username): void {
|
|
||||||
$user = $this->featureContext->getActualUsername($username);
|
|
||||||
$this->featureContext->setResponse($this->userGetsCapabilities($user, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param string $username
|
|
||||||
* @param boolean $formatJson // if true then formats the response in json
|
|
||||||
*
|
|
||||||
* @return ResponseInterface
|
|
||||||
* @throws GuzzleException
|
|
||||||
* @throws JsonException
|
|
||||||
*/
|
|
||||||
public function userGetsCapabilities(string $username, ?bool $formatJson = false):ResponseInterface {
|
|
||||||
$user = $this->featureContext->getActualUsername($username);
|
|
||||||
$password = $this->featureContext->getPasswordForUser($user);
|
|
||||||
return OcsApiHelper::sendRequest(
|
|
||||||
$this->featureContext->getBaseUrl(),
|
|
||||||
$user,
|
|
||||||
$password,
|
|
||||||
'GET',
|
|
||||||
'/cloud/capabilities' . ($formatJson ? '?format=json' : ''),
|
|
||||||
$this->featureContext->getStepLineRef(),
|
|
||||||
[],
|
|
||||||
$this->featureContext->getOcsApiVersion()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Given user :username has retrieved the capabilities
|
|
||||||
*
|
|
||||||
* @param string $username
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function userGetsCapabilitiesCheckResponse(string $username):void {
|
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $this->userGetsCapabilities($username));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @When the user retrieves the capabilities using the capabilities API
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function theUserGetsCapabilities():void {
|
|
||||||
$this->featureContext->setResponse($this->userGetsCapabilities($this->featureContext->getCurrentUser()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Given the user has retrieved the capabilities
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function theUserGetsCapabilitiesCheckResponse():void {
|
|
||||||
$this->userGetsCapabilitiesCheckResponse($this->featureContext->getCurrentUser());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
* @throws Exception|GuzzleException
|
|
||||||
*/
|
|
||||||
public function getAdminUsernameForCapabilitiesCheck():string {
|
|
||||||
if (\TestHelpers\OcisHelper::isTestingOnReva()) {
|
|
||||||
// When testing on reva we don't have a user called "admin" to use
|
|
||||||
// to access the capabilities. So create an ordinary user on-the-fly
|
|
||||||
// with a default password. That user should be able to get a
|
|
||||||
// capabilities response that the test can process.
|
|
||||||
$adminUsername = "PseudoAdminForRevaTest";
|
|
||||||
$createdUsers = $this->featureContext->getCreatedUsers();
|
|
||||||
if (!\array_key_exists($adminUsername, $createdUsers)) {
|
|
||||||
$this->featureContext->userHasBeenCreated(["userName" => $adminUsername]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$adminUsername = $this->featureContext->getAdminUsername();
|
|
||||||
}
|
|
||||||
return $adminUsername;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @When the administrator retrieves the capabilities using the capabilities API
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function theAdministratorGetsCapabilities():void {
|
|
||||||
$user = $this->getAdminUsernameForCapabilitiesCheck();
|
|
||||||
$this->featureContext->setResponse($this->userGetsCapabilities($user, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Given the administrator has retrieved the capabilities
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function theAdministratorGetsCapabilitiesCheckResponse():void {
|
|
||||||
$this->userGetsCapabilitiesCheckResponse($this->getAdminUsernameForCapabilitiesCheck());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $exceptionText text to put at the front of exception messages
|
|
||||||
*
|
|
||||||
* @return SimpleXMLElement latest retrieved capabilities in XML format
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function getCapabilitiesXml(string $exceptionText = ''): SimpleXMLElement {
|
|
||||||
if ($exceptionText === '') {
|
|
||||||
$exceptionText = __METHOD__;
|
|
||||||
}
|
|
||||||
return $this->featureContext->getResponseXml(null, $exceptionText)->data->capabilities;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $exceptionText text to put at the front of exception messages
|
|
||||||
*
|
|
||||||
* @return SimpleXMLElement latest retrieved version data in XML format
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function getVersionXml(string $exceptionText = ''): SimpleXMLElement {
|
|
||||||
if ($exceptionText === '') {
|
|
||||||
$exceptionText = __METHOD__;
|
|
||||||
}
|
|
||||||
return $this->featureContext->getResponseXml(null, $exceptionText)->data->version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param SimpleXMLElement $xml of the capabilities
|
|
||||||
* @param string $capabilitiesApp the "app" name in the capabilities response
|
|
||||||
* @param string $capabilitiesPath the path to the element
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getParameterValueFromXml(
|
|
||||||
SimpleXMLElement $xml,
|
|
||||||
string $capabilitiesApp,
|
|
||||||
string $capabilitiesPath
|
|
||||||
):string {
|
|
||||||
$path_to_element = \explode('@@@', $capabilitiesPath);
|
|
||||||
$answeredValue = $xml->{$capabilitiesApp};
|
|
||||||
foreach ($path_to_element as $element) {
|
|
||||||
$nameIndexParts = \explode('[', $element);
|
|
||||||
if (isset($nameIndexParts[1])) {
|
|
||||||
// This part of the path should be something like "some_element[1]"
|
|
||||||
// Separately extract the name and the index
|
|
||||||
$name = $nameIndexParts[0];
|
|
||||||
$index = (int) \explode(']', $nameIndexParts[1])[0];
|
|
||||||
// and use those to construct the reference into the next XML level
|
|
||||||
$answeredValue = $answeredValue->{$name}[$index];
|
|
||||||
} else {
|
|
||||||
if ($element !== "") {
|
|
||||||
$answeredValue = $answeredValue->{$element};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (string) $answeredValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param SimpleXMLElement $xml of the capabilities
|
|
||||||
* @param string $capabilitiesApp the "app" name in the capabilities response
|
|
||||||
* @param string $capabilitiesPath the path to the element
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function parameterValueExistsInXml(
|
|
||||||
SimpleXMLElement $xml,
|
|
||||||
string $capabilitiesApp,
|
|
||||||
string $capabilitiesPath
|
|
||||||
):bool {
|
|
||||||
$path_to_element = \explode('@@@', $capabilitiesPath);
|
|
||||||
$answeredValue = $xml->{$capabilitiesApp};
|
|
||||||
|
|
||||||
foreach ($path_to_element as $element) {
|
|
||||||
$nameIndexParts = \explode('[', $element);
|
|
||||||
if (isset($nameIndexParts[1])) {
|
|
||||||
// This part of the path should be something like "some_element[1]"
|
|
||||||
// Separately extract the name and the index
|
|
||||||
$name = $nameIndexParts[0];
|
|
||||||
$index = (int) \explode(']', $nameIndexParts[1])[0];
|
|
||||||
// and use those to construct the reference into the next XML level
|
|
||||||
if (isset($answeredValue->{$name}[$index])) {
|
|
||||||
$answeredValue = $answeredValue->{$name}[$index];
|
|
||||||
} else {
|
|
||||||
// The path ends at this level
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isset($answeredValue->{$element})) {
|
|
||||||
$answeredValue = $answeredValue->{$element};
|
|
||||||
} else {
|
|
||||||
// The path ends at this level
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $app
|
|
||||||
* @param string $parameter
|
|
||||||
* @param string $value
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function modifyAppConfig(string $app, string $parameter, string $value):void {
|
|
||||||
AppConfigHelper::modifyAppConfig(
|
|
||||||
$this->featureContext->getBaseUrl(),
|
|
||||||
$this->featureContext->getAdminUsername(),
|
|
||||||
$this->featureContext->getAdminPassword(),
|
|
||||||
$app,
|
|
||||||
$parameter,
|
|
||||||
$value,
|
|
||||||
$this->featureContext->getStepLineRef(),
|
|
||||||
$this->featureContext->getOcsApiVersion()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $appParameterValues
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function modifyAppConfigs(array $appParameterValues):void {
|
|
||||||
AppConfigHelper::modifyAppConfigs(
|
|
||||||
$this->featureContext->getBaseUrl(),
|
|
||||||
$this->featureContext->getAdminUsername(),
|
|
||||||
$this->featureContext->getAdminPassword(),
|
|
||||||
$appParameterValues,
|
|
||||||
$this->featureContext->getStepLineRef(),
|
|
||||||
$this->featureContext->getOcsApiVersion()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @When the administrator adds url :url as trusted server using the testing API
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws GuzzleException
|
|
||||||
*/
|
|
||||||
public function theAdministratorAddsUrlAsTrustedServerUsingTheTestingApi(string $url):void {
|
|
||||||
$adminUser = $this->featureContext->getAdminUsername();
|
|
||||||
$response = OcsApiHelper::sendRequest(
|
|
||||||
$this->featureContext->getBaseUrl(),
|
|
||||||
$adminUser,
|
|
||||||
$this->featureContext->getAdminPassword(),
|
|
||||||
'POST',
|
|
||||||
"/apps/testing/api/v1/trustedservers",
|
|
||||||
$this->featureContext->getStepLineRef(),
|
|
||||||
['url' => $this->featureContext->substituteInLineCodes($url)]
|
|
||||||
);
|
|
||||||
$this->featureContext->setResponse($response);
|
|
||||||
$this->featureContext->pushToLastStatusCodesArrays();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return text that contains the details of the URL, including any differences due to inline codes
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getUrlStringForMessage(string $url):string {
|
|
||||||
$text = $url;
|
|
||||||
$expectedUrl = $this->featureContext->substituteInLineCodes($url);
|
|
||||||
if ($expectedUrl !== $url) {
|
|
||||||
$text .= " ($expectedUrl)";
|
|
||||||
}
|
|
||||||
return $text;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $url
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getNotTrustedServerMessage(string $url):string {
|
|
||||||
return
|
|
||||||
"URL "
|
|
||||||
. $this->getUrlStringForMessage($url)
|
|
||||||
. " is not a trusted server but should be";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Then url :url should be a trusted server
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function urlShouldBeATrustedServer(string $url):void {
|
|
||||||
$trustedServers = $this->featureContext->getTrustedServers();
|
|
||||||
foreach ($trustedServers as $server => $id) {
|
|
||||||
if ($server === $this->featureContext->substituteInLineCodes($url)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Assert::fail($this->getNotTrustedServerMessage($url));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Then the trusted server list should include these urls:
|
|
||||||
*
|
|
||||||
* @param TableNode $table
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function theTrustedServerListShouldIncludeTheseUrls(TableNode $table):void {
|
|
||||||
$trustedServers = $this->featureContext->getTrustedServers();
|
|
||||||
$expected = $table->getColumnsHash();
|
|
||||||
|
|
||||||
foreach ($expected as $server) {
|
|
||||||
$found = false;
|
|
||||||
foreach ($trustedServers as $url => $id) {
|
|
||||||
if ($url === $this->featureContext->substituteInLineCodes($server['url'])) {
|
|
||||||
$found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$found) {
|
|
||||||
Assert::fail($this->getNotTrustedServerMessage($server['url']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Given the administrator has added url :url as trusted server
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
* @throws GuzzleException
|
|
||||||
*/
|
|
||||||
public function theAdministratorHasAddedUrlAsTrustedServer(string $url):void {
|
|
||||||
$this->theAdministratorAddsUrlAsTrustedServerUsingTheTestingApi($url);
|
|
||||||
$status = $this->featureContext->getResponse()->getStatusCode();
|
|
||||||
if ($status !== 201) {
|
|
||||||
throw new \Exception(
|
|
||||||
__METHOD__ .
|
|
||||||
" Could not add trusted server " . $this->getUrlStringForMessage($url)
|
|
||||||
. ". The request failed with status $status"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @When the administrator deletes url :url from trusted servers using the testing API
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws GuzzleException
|
|
||||||
*/
|
|
||||||
public function theAdministratorDeletesUrlFromTrustedServersUsingTheTestingApi(string $url):void {
|
|
||||||
$adminUser = $this->featureContext->getAdminUsername();
|
|
||||||
$response = OcsApiHelper::sendRequest(
|
|
||||||
$this->featureContext->getBaseUrl(),
|
|
||||||
$adminUser,
|
|
||||||
$this->featureContext->getAdminPassword(),
|
|
||||||
'DELETE',
|
|
||||||
"/apps/testing/api/v1/trustedservers",
|
|
||||||
$this->featureContext->getStepLineRef(),
|
|
||||||
['url' => $this->featureContext->substituteInLineCodes($url)]
|
|
||||||
);
|
|
||||||
$this->featureContext->setResponse($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Then url :url should not be a trusted server
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function urlShouldNotBeATrustedServer(string $url):void {
|
|
||||||
$trustedServers = $this->featureContext->getTrustedServers();
|
|
||||||
foreach ($trustedServers as $server => $id) {
|
|
||||||
if ($server === $this->featureContext->substituteInLineCodes($url)) {
|
|
||||||
Assert::fail(
|
|
||||||
"URL " . $this->getUrlStringForMessage($url)
|
|
||||||
. " is a trusted server but is not expected to be"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @When the administrator deletes all trusted servers using the testing API
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws GuzzleException
|
|
||||||
*/
|
|
||||||
public function theAdministratorDeletesAllTrustedServersUsingTheTestingApi():void {
|
|
||||||
$adminUser = $this->featureContext->getAdminUsername();
|
|
||||||
$response = OcsApiHelper::sendRequest(
|
|
||||||
$this->featureContext->getBaseUrl(),
|
|
||||||
$adminUser,
|
|
||||||
$this->featureContext->getAdminPassword(),
|
|
||||||
'DELETE',
|
|
||||||
"/apps/testing/api/v1/trustedservers/all",
|
|
||||||
$this->featureContext->getStepLineRef()
|
|
||||||
);
|
|
||||||
$this->featureContext->setResponse($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Given the trusted server list is cleared
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function theTrustedServerListIsCleared():void {
|
|
||||||
$this->theAdministratorDeletesAllTrustedServersUsingTheTestingApi();
|
|
||||||
$statusCode = $this->featureContext->getResponse()->getStatusCode();
|
|
||||||
if ($statusCode !== 204) {
|
|
||||||
$contents = $this->featureContext->getResponse()->getBody()->getContents();
|
|
||||||
throw new \Exception(
|
|
||||||
__METHOD__
|
|
||||||
. " Failed to clear all trusted servers" . $contents
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Then the trusted server list should be empty
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function theTrustedServerListShouldBeEmpty():void {
|
|
||||||
$trustedServers = $this->featureContext->getTrustedServers();
|
|
||||||
Assert::assertEmpty(
|
|
||||||
$trustedServers,
|
|
||||||
__METHOD__ . " Trusted server list is not empty"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BeforeScenario
|
|
||||||
*
|
|
||||||
* @param BeforeScenarioScope $scope
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setUpScenario(BeforeScenarioScope $scope):void {
|
|
||||||
// Get the environment
|
|
||||||
$environment = $scope->getEnvironment();
|
|
||||||
// Get all the contexts you need in this context
|
|
||||||
$this->featureContext = $environment->getContext('FeatureContext');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,10 @@
|
|||||||
|
|
||||||
use Behat\Behat\Context\Context;
|
use Behat\Behat\Context\Context;
|
||||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||||
|
use Behat\Gherkin\Node\PyStringNode;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
|
use TestHelpers\OcsApiHelper;
|
||||||
|
|
||||||
require_once 'bootstrap.php';
|
require_once 'bootstrap.php';
|
||||||
|
|
||||||
@@ -34,6 +37,125 @@ require_once 'bootstrap.php';
|
|||||||
class CapabilitiesContext implements Context {
|
class CapabilitiesContext implements Context {
|
||||||
private FeatureContext $featureContext;
|
private FeatureContext $featureContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will run before EVERY scenario.
|
||||||
|
* It will set the properties for this object.
|
||||||
|
*
|
||||||
|
* @BeforeScenario
|
||||||
|
*
|
||||||
|
* @param BeforeScenarioScope $scope
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function before(BeforeScenarioScope $scope):void {
|
||||||
|
// Get the environment
|
||||||
|
$environment = $scope->getEnvironment();
|
||||||
|
// Get all the contexts you need in this context
|
||||||
|
$this->featureContext = $environment->getContext('FeatureContext');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $username
|
||||||
|
* @param boolean $formatJson // if true then formats the response in json
|
||||||
|
*
|
||||||
|
* @return ResponseInterface
|
||||||
|
* @throws GuzzleException
|
||||||
|
* @throws JsonException
|
||||||
|
*/
|
||||||
|
public function userGetsCapabilities(string $username, ?bool $formatJson = false): ResponseInterface {
|
||||||
|
$user = $this->featureContext->getActualUsername($username);
|
||||||
|
$password = $this->featureContext->getPasswordForUser($user);
|
||||||
|
return OcsApiHelper::sendRequest(
|
||||||
|
$this->featureContext->getBaseUrl(),
|
||||||
|
$user,
|
||||||
|
$password,
|
||||||
|
'GET',
|
||||||
|
'/cloud/capabilities' . ($formatJson ? '?format=json' : ''),
|
||||||
|
$this->featureContext->getStepLineRef(),
|
||||||
|
[],
|
||||||
|
$this->featureContext->getOcsApiVersion()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @throws Exception|GuzzleException
|
||||||
|
*/
|
||||||
|
public function getAdminUsernameForCapabilitiesCheck(): string {
|
||||||
|
if (\TestHelpers\OcisHelper::isTestingOnReva()) {
|
||||||
|
// When testing on reva we don't have a user called "admin" to use
|
||||||
|
// to access the capabilities. So create an ordinary user on-the-fly
|
||||||
|
// with a default password. That user should be able to get a
|
||||||
|
// capabilities response that the test can process.
|
||||||
|
$adminUsername = "PseudoAdminForRevaTest";
|
||||||
|
$createdUsers = $this->featureContext->getCreatedUsers();
|
||||||
|
if (!\array_key_exists($adminUsername, $createdUsers)) {
|
||||||
|
$this->featureContext->userHasBeenCreated(["userName" => $adminUsername]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$adminUsername = $this->featureContext->getAdminUsername();
|
||||||
|
}
|
||||||
|
return $adminUsername;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SimpleXMLElement $xml of the capabilities
|
||||||
|
* @param string $capabilitiesApp the "app" name in the capabilities response
|
||||||
|
* @param string $capabilitiesPath the path to the element
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getParameterValueFromXml(
|
||||||
|
SimpleXMLElement $xml,
|
||||||
|
string $capabilitiesApp,
|
||||||
|
string $capabilitiesPath
|
||||||
|
): string {
|
||||||
|
$path_to_element = \explode('@@@', $capabilitiesPath);
|
||||||
|
$answeredValue = $xml->{$capabilitiesApp};
|
||||||
|
foreach ($path_to_element as $element) {
|
||||||
|
$nameIndexParts = \explode('[', $element);
|
||||||
|
if (isset($nameIndexParts[1])) {
|
||||||
|
// This part of the path should be something like "some_element[1]"
|
||||||
|
// Separately extract the name and the index
|
||||||
|
$name = $nameIndexParts[0];
|
||||||
|
$index = (int) \explode(']', $nameIndexParts[1])[0];
|
||||||
|
// and use those to construct the reference into the next XML level
|
||||||
|
$answeredValue = $answeredValue->{$name}[$index];
|
||||||
|
} else {
|
||||||
|
if ($element !== "") {
|
||||||
|
$answeredValue = $answeredValue->{$element};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) $answeredValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When user :username retrieves the capabilities using the capabilities API
|
||||||
|
*
|
||||||
|
* @param string $username
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws GuzzleException
|
||||||
|
* @throws JsonException
|
||||||
|
*/
|
||||||
|
public function userRetrievesCapabilities(string $username): void {
|
||||||
|
$user = $this->featureContext->getActualUsername($username);
|
||||||
|
$this->featureContext->setResponse($this->userGetsCapabilities($user, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When the administrator retrieves the capabilities using the capabilities API
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function theAdministratorGetsCapabilities(): void {
|
||||||
|
$user = $this->getAdminUsernameForCapabilitiesCheck();
|
||||||
|
$this->featureContext->setResponse($this->userGetsCapabilities($user, true));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Then the major-minor-micro version data in the response should match the version string
|
* @Then the major-minor-micro version data in the response should match the version string
|
||||||
*
|
*
|
||||||
@@ -77,48 +199,129 @@ class CapabilitiesContext implements Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Then the :pathToElement capability of files sharing app should be :value
|
* @Then the status.php response should include
|
||||||
*
|
*
|
||||||
* @param string $pathToElement
|
* @param PyStringNode $jsonExpected
|
||||||
* @param string $value
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function theCapabilityOfFilesSharingAppShouldBe(
|
public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void {
|
||||||
string $pathToElement,
|
$jsonExpectedDecoded = \json_decode($jsonExpected->getRaw(), true);
|
||||||
string $value
|
$jsonRespondedDecoded = $this->featureContext->getJsonDecodedResponse();
|
||||||
):void {
|
|
||||||
$this->featureContext->appConfigurationContext->userGetsCapabilitiesCheckResponse(
|
|
||||||
$this->featureContext->getCurrentUser()
|
|
||||||
);
|
|
||||||
$capabilitiesXML = $this->featureContext->appConfigurationContext->getCapabilitiesXml(__METHOD__);
|
|
||||||
$actualValue = $this->featureContext->appConfigurationContext->getParameterValueFromXml(
|
|
||||||
$capabilitiesXML,
|
|
||||||
"files_sharing",
|
|
||||||
$pathToElement
|
|
||||||
);
|
|
||||||
Assert::assertEquals(
|
|
||||||
$value === "EMPTY" ? '' : $value,
|
|
||||||
$actualValue,
|
|
||||||
"Expected $pathToElement capability of files sharing app to be $value, but got $actualValue"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$response = $this->userGetsCapabilities($this->getAdminUsernameForCapabilitiesCheck());
|
||||||
* This will run before EVERY scenario.
|
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
|
||||||
* It will set the properties for this object.
|
$responseXml = $this->featureContext->getResponseXml($response)->data->capabilities;
|
||||||
*
|
$edition = $this->getParameterValueFromXml(
|
||||||
* @BeforeScenario
|
$responseXml,
|
||||||
*
|
'core',
|
||||||
* @param BeforeScenarioScope $scope
|
'status@@@edition'
|
||||||
*
|
);
|
||||||
* @return void
|
|
||||||
*/
|
if (!\strlen($edition)) {
|
||||||
public function before(BeforeScenarioScope $scope):void {
|
Assert::fail(
|
||||||
// Get the environment
|
"Cannot get edition from core capabilities"
|
||||||
$environment = $scope->getEnvironment();
|
);
|
||||||
// Get all the contexts you need in this context
|
}
|
||||||
$this->featureContext = $environment->getContext('FeatureContext');
|
|
||||||
|
$product = $this->getParameterValueFromXml(
|
||||||
|
$responseXml,
|
||||||
|
'core',
|
||||||
|
'status@@@product'
|
||||||
|
);
|
||||||
|
if (!\strlen($product)) {
|
||||||
|
Assert::fail(
|
||||||
|
"Cannot get product from core capabilities"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$productName = $this->getParameterValueFromXml(
|
||||||
|
$responseXml,
|
||||||
|
'core',
|
||||||
|
'status@@@productname'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!\strlen($productName)) {
|
||||||
|
Assert::fail(
|
||||||
|
"Cannot get productname from core capabilities"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$jsonExpectedDecoded['edition'] = $edition;
|
||||||
|
$jsonExpectedDecoded['product'] = $product;
|
||||||
|
$jsonExpectedDecoded['productname'] = $productName;
|
||||||
|
|
||||||
|
// We are on oCIS or reva or some other implementation. We cannot do "occ status".
|
||||||
|
// So get the expected version values by looking in the capabilities response.
|
||||||
|
$version = $this->getParameterValueFromXml(
|
||||||
|
$responseXml,
|
||||||
|
'core',
|
||||||
|
'status@@@version'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!\strlen($version)) {
|
||||||
|
Assert::fail(
|
||||||
|
"Cannot get version from core capabilities"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$versionString = $this->getParameterValueFromXml(
|
||||||
|
$responseXml,
|
||||||
|
'core',
|
||||||
|
'status@@@versionstring'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!\strlen($versionString)) {
|
||||||
|
Assert::fail(
|
||||||
|
"Cannot get versionstring from core capabilities"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$jsonExpectedDecoded['version'] = $version;
|
||||||
|
$jsonExpectedDecoded['versionstring'] = $versionString;
|
||||||
|
$errorMessage = "";
|
||||||
|
$errorFound = false;
|
||||||
|
foreach ($jsonExpectedDecoded as $key => $expectedValue) {
|
||||||
|
if (\array_key_exists($key, $jsonRespondedDecoded)) {
|
||||||
|
$actualValue = $jsonRespondedDecoded[$key];
|
||||||
|
if ($actualValue !== $expectedValue) {
|
||||||
|
$errorMessage .= "$key expected value was $expectedValue but actual value was $actualValue\n";
|
||||||
|
$errorFound = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errorMessage .= "$key was not found in the status response\n";
|
||||||
|
$errorFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Assert::assertFalse($errorFound, $errorMessage);
|
||||||
|
// We have checked that the status.php response has data that matches up with
|
||||||
|
// data found in the capabilities response and/or the "occ status" command output.
|
||||||
|
// But the output might be reported wrongly in all of these in the same way.
|
||||||
|
// So check that the values also seem "reasonable".
|
||||||
|
$version = $jsonExpectedDecoded['version'];
|
||||||
|
$versionString = $jsonExpectedDecoded['versionstring'];
|
||||||
|
Assert::assertMatchesRegularExpression(
|
||||||
|
"/^\d+\.\d+\.\d+\.\d+$/",
|
||||||
|
$version,
|
||||||
|
"version should be in a form like 10.9.8.1 but is $version"
|
||||||
|
);
|
||||||
|
if (\preg_match("/^(\d+\.\d+\.\d+)\.\d+(-[0-9A-Za-z-]+)?(\+[0-9A-Za-z-]+)?$/", $version, $matches)) {
|
||||||
|
// We should have matched something like 10.9.8 - the first 3 numbers in the version.
|
||||||
|
// Ignore pre-releases and meta information
|
||||||
|
Assert::assertArrayHasKey(
|
||||||
|
1,
|
||||||
|
$matches,
|
||||||
|
"version $version could not match the pattern Major.Minor.Patch"
|
||||||
|
);
|
||||||
|
$majorMinorPatchVersion = $matches[1];
|
||||||
|
} else {
|
||||||
|
Assert::fail("version '$version' does not start in a form like 10.9.8");
|
||||||
|
}
|
||||||
|
Assert::assertStringStartsWith(
|
||||||
|
$majorMinorPatchVersion,
|
||||||
|
$versionString,
|
||||||
|
"versionstring should start with $majorMinorPatchVersion but is $versionString"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,7 +163,6 @@ class FeatureContext extends BehatVariablesContext {
|
|||||||
public AuthContext $authContext;
|
public AuthContext $authContext;
|
||||||
public GraphContext $graphContext;
|
public GraphContext $graphContext;
|
||||||
public SpacesContext $spacesContext;
|
public SpacesContext $spacesContext;
|
||||||
public AppConfigurationContext $appConfigurationContext;
|
|
||||||
private array $initialTrustedServer;
|
private array $initialTrustedServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2290,133 +2289,6 @@ class FeatureContext extends BehatVariablesContext {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @Then the status.php response should include
|
|
||||||
*
|
|
||||||
* @param PyStringNode $jsonExpected
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void {
|
|
||||||
$jsonExpectedDecoded = \json_decode($jsonExpected->getRaw(), true);
|
|
||||||
$jsonRespondedDecoded = $this->getJsonDecodedResponse();
|
|
||||||
|
|
||||||
$response = $this->appConfigurationContext->userGetsCapabilities($this->appConfigurationContext->getAdminUsernameForCapabilitiesCheck());
|
|
||||||
$this->theHTTPStatusCodeShouldBe(200, '', $response);
|
|
||||||
$responseXml = $this->getResponseXml($response)->data->capabilities;
|
|
||||||
$edition = $this->appConfigurationContext->getParameterValueFromXml(
|
|
||||||
$responseXml,
|
|
||||||
'core',
|
|
||||||
'status@@@edition'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!\strlen($edition)) {
|
|
||||||
Assert::fail(
|
|
||||||
"Cannot get edition from core capabilities"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$product = $this->appConfigurationContext->getParameterValueFromXml(
|
|
||||||
$responseXml,
|
|
||||||
'core',
|
|
||||||
'status@@@product'
|
|
||||||
);
|
|
||||||
if (!\strlen($product)) {
|
|
||||||
Assert::fail(
|
|
||||||
"Cannot get product from core capabilities"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$productName = $this->appConfigurationContext->getParameterValueFromXml(
|
|
||||||
$responseXml,
|
|
||||||
'core',
|
|
||||||
'status@@@productname'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!\strlen($productName)) {
|
|
||||||
Assert::fail(
|
|
||||||
"Cannot get productname from core capabilities"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$jsonExpectedDecoded['edition'] = $edition;
|
|
||||||
$jsonExpectedDecoded['product'] = $product;
|
|
||||||
$jsonExpectedDecoded['productname'] = $productName;
|
|
||||||
|
|
||||||
// We are on oCIS or reva or some other implementation. We cannot do "occ status".
|
|
||||||
// So get the expected version values by looking in the capabilities response.
|
|
||||||
$version = $this->appConfigurationContext->getParameterValueFromXml(
|
|
||||||
$responseXml,
|
|
||||||
'core',
|
|
||||||
'status@@@version'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!\strlen($version)) {
|
|
||||||
Assert::fail(
|
|
||||||
"Cannot get version from core capabilities"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$versionString = $this->appConfigurationContext->getParameterValueFromXml(
|
|
||||||
$responseXml,
|
|
||||||
'core',
|
|
||||||
'status@@@versionstring'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!\strlen($versionString)) {
|
|
||||||
Assert::fail(
|
|
||||||
"Cannot get versionstring from core capabilities"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$jsonExpectedDecoded['version'] = $version;
|
|
||||||
$jsonExpectedDecoded['versionstring'] = $versionString;
|
|
||||||
$errorMessage = "";
|
|
||||||
$errorFound = false;
|
|
||||||
foreach ($jsonExpectedDecoded as $key => $expectedValue) {
|
|
||||||
if (\array_key_exists($key, $jsonRespondedDecoded)) {
|
|
||||||
$actualValue = $jsonRespondedDecoded[$key];
|
|
||||||
if ($actualValue !== $expectedValue) {
|
|
||||||
$errorMessage .= "$key expected value was $expectedValue but actual value was $actualValue\n";
|
|
||||||
$errorFound = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$errorMessage .= "$key was not found in the status response\n";
|
|
||||||
$errorFound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Assert::assertFalse($errorFound, $errorMessage);
|
|
||||||
// We have checked that the status.php response has data that matches up with
|
|
||||||
// data found in the capabilities response and/or the "occ status" command output.
|
|
||||||
// But the output might be reported wrongly in all of these in the same way.
|
|
||||||
// So check that the values also seem "reasonable".
|
|
||||||
$version = $jsonExpectedDecoded['version'];
|
|
||||||
$versionString = $jsonExpectedDecoded['versionstring'];
|
|
||||||
Assert::assertMatchesRegularExpression(
|
|
||||||
"/^\d+\.\d+\.\d+\.\d+$/",
|
|
||||||
$version,
|
|
||||||
"version should be in a form like 10.9.8.1 but is $version"
|
|
||||||
);
|
|
||||||
if (\preg_match("/^(\d+\.\d+\.\d+)\.\d+(-[0-9A-Za-z-]+)?(\+[0-9A-Za-z-]+)?$/", $version, $matches)) {
|
|
||||||
// We should have matched something like 10.9.8 - the first 3 numbers in the version.
|
|
||||||
// Ignore pre-releases and meta information
|
|
||||||
Assert::assertArrayHasKey(
|
|
||||||
1,
|
|
||||||
$matches,
|
|
||||||
"version $version could not match the pattern Major.Minor.Patch"
|
|
||||||
);
|
|
||||||
$majorMinorPatchVersion = $matches[1];
|
|
||||||
} else {
|
|
||||||
Assert::fail("version '$version' does not start in a form like 10.9.8");
|
|
||||||
}
|
|
||||||
Assert::assertStringStartsWith(
|
|
||||||
$majorMinorPatchVersion,
|
|
||||||
$versionString,
|
|
||||||
"versionstring should start with $majorMinorPatchVersion but is $versionString"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* send request to read a server file for core
|
* send request to read a server file for core
|
||||||
*
|
*
|
||||||
@@ -3237,13 +3109,10 @@ class FeatureContext extends BehatVariablesContext {
|
|||||||
// that calls BasicStructure.php
|
// that calls BasicStructure.php
|
||||||
$this->ocsContext = new OCSContext();
|
$this->ocsContext = new OCSContext();
|
||||||
$this->authContext = new AuthContext();
|
$this->authContext = new AuthContext();
|
||||||
$this->appConfigurationContext = new AppConfigurationContext();
|
|
||||||
$this->ocsContext->before($scope);
|
$this->ocsContext->before($scope);
|
||||||
$this->authContext->setUpScenario($scope);
|
$this->authContext->setUpScenario($scope);
|
||||||
$this->appConfigurationContext->setUpScenario($scope);
|
|
||||||
$environment->registerContext($this->ocsContext);
|
$environment->registerContext($this->ocsContext);
|
||||||
$environment->registerContext($this->authContext);
|
$environment->registerContext($this->authContext);
|
||||||
$environment->registerContext($this->appConfigurationContext);
|
|
||||||
$scenarioLine = $scope->getScenario()->getLine();
|
$scenarioLine = $scope->getScenario()->getLine();
|
||||||
$featureFile = $scope->getFeature()->getFile();
|
$featureFile = $scope->getFeature()->getFile();
|
||||||
$suiteName = $scope->getSuite()->getName();
|
$suiteName = $scope->getSuite()->getName();
|
||||||
@@ -3590,24 +3459,6 @@ class FeatureContext extends BehatVariablesContext {
|
|||||||
return \substr($foundPath, \strlen($davPath) + 1);
|
return \substr($foundPath, \strlen($davPath) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* After Scenario. restore trusted servers
|
|
||||||
*
|
|
||||||
* @param string $server 'LOCAL'/'REMOTE'
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function restoreTrustedServers(string $server): void {
|
|
||||||
$currentTrustedServers = $this->getTrustedServers($server);
|
|
||||||
foreach (\array_diff($currentTrustedServers, $this->initialTrustedServer[$server]) as $url => $id) {
|
|
||||||
$this->appConfigurationContext->theAdministratorDeletesUrlFromTrustedServersUsingTheTestingApi($url);
|
|
||||||
}
|
|
||||||
foreach (\array_diff($this->initialTrustedServer[$server], $currentTrustedServers) as $url => $id) {
|
|
||||||
$this->appConfigurationContext->theAdministratorAddsUrlAsTrustedServerUsingTheTestingApi($url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the array of trusted servers in format ["url" => "id"]
|
* Get the array of trusted servers in format ["url" => "id"]
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user