test: get necessary contexts properly

This commit is contained in:
Saw-jan
2024-10-08 12:26:40 +05:45
parent 883d7601b4
commit ca76f79be3
27 changed files with 205 additions and 183 deletions

View File

@@ -0,0 +1,54 @@
<?php declare(strict_types=1);
/**
* ownCloud
*
* @author Sajan Gurung <sajan@jankaritech.com>
* @copyright Copyright (c) 2017 Artur Neumann artur@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 <http://www.gnu.org/licenses/>
*
*/
namespace TestHelpers;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Behat\Behat\Context\Exception\ContextNotFoundException;
use Behat\Behat\Hook\Scope\ScenarioScope;
/**
* Helper for Behat environment configuration
*
*/
class BehatHelper {
/**
* @param ScenarioScope $scope
* @param InitializedContextEnvironment $environment
* @param string $class
*
* @return Context
*/
public static function getContext(ScenarioScope $scope, InitializedContextEnvironment $environment, string $class): Context {
try {
return $environment->getContext($class);
} catch (ContextNotFoundException $e) {
print_r("[INFO] '$class' context not found. Registering...\n");
$context = new $class();
$environment->registerContext($context);
if (\method_exists($context, 'before')) {
$context->before($scope);
}
return $environment->getContext($class);
}
}
}

View File

@@ -26,6 +26,7 @@ use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\GuzzleException;
use TestHelpers\HttpRequestHelper;
use TestHelpers\SetupHelper;
use TestHelpers\BehatHelper;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use splitbrain\PHPArchive\Tar;
@@ -52,17 +53,11 @@ class ArchiverContext implements Context {
*
* @throws Exception
*/
public function setUpScenario(BeforeScenarioScope $scope): 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');
SetupHelper::init(
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$this->featureContext->getBaseUrl(),
$this->featureContext->getOcPath()
);
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
/**

View File

@@ -20,11 +20,12 @@
*/
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use TestHelpers\HttpRequestHelper;
use Behat\Gherkin\Node\TableNode;
use Behat\Behat\Context\Context;
use TestHelpers\SetupHelper;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use TestHelpers\SetupHelper;
use TestHelpers\BehatHelper;
use TestHelpers\WebDavHelper;
/**
@@ -40,22 +41,11 @@ class AuthContext implements Context {
*
* @return void
*/
public function setUpScenario(BeforeScenarioScope $scope):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');
// Reset ResponseXml
$this->featureContext->setResponseXml([]);
// Initialize SetupHelper class
SetupHelper::init(
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$this->featureContext->getBaseUrl(),
$this->featureContext->getOcPath()
);
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
/**

View File

@@ -28,6 +28,7 @@ use Behat\Gherkin\Node\PyStringNode;
use Psr\Http\Message\ResponseInterface;
use PHPUnit\Framework\Assert;
use TestHelpers\OcsApiHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -51,7 +52,7 @@ class CapabilitiesContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
/**

View File

@@ -22,8 +22,9 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use PHPUnit\Framework\Assert;
use TestHelpers\WebDavHelper;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -485,6 +486,6 @@ class ChecksumContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
}

View File

@@ -22,10 +22,11 @@
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;
use TestHelpers\CliHelper;
use TestHelpers\OcisConfigHelper;
use Behat\Gherkin\Node\TableNode;
use TestHelpers\BehatHelper;
/**
* CLI context
@@ -41,12 +42,12 @@ class CliContext implements Context {
*
* @return void
*/
public function setUpScenario(BeforeScenarioScope $scope): 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');
$this->spacesContext = $environment->getContext('SpacesContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
}
/**

View File

@@ -27,6 +27,7 @@ use GuzzleHttp\Exception\GuzzleException;
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\CollaborationHelper;
use TestHelpers\BehatHelper;
/**
* steps needed to re-configure oCIS server
@@ -50,8 +51,8 @@ class CollaborationContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context from here
$this->featureContext = $environment->getContext('FeatureContext');
$this->spacesContext = $environment->getContext('SpacesContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
}
/**

View File

@@ -25,6 +25,7 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -245,8 +246,10 @@ class FavoritesContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->webDavPropertiesContext = $environment->getContext(
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->webDavPropertiesContext = BehatHelper::getContext(
$scope,
$environment,
'WebDavPropertiesContext'
);
}

View File

@@ -43,6 +43,7 @@ use TestHelpers\GraphHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\SettingsHelper;
use TestHelpers\OcisConfigHelper;
use TestHelpers\BehatHelper;
use Swaggest\JsonSchema\InvalidValue as JsonSchemaException;
use Swaggest\JsonSchema\Exception\ArrayException;
use Swaggest\JsonSchema\Exception\ConstException;
@@ -2617,36 +2618,23 @@ class FeatureContext extends BehatVariablesContext {
*/
public function before(BeforeScenarioScope $scope): void {
$this->scenarioStartTime = \time();
// Get the environment
$environment = $scope->getEnvironment();
// registers context in every suite, as every suite has FeatureContext
// that calls BasicStructure.php
$this->ocsContext = new OCSContext();
$this->authContext = new AuthContext();
$this->tusContext = new TUSContext();
$this->ocmContext = new OcmContext();
$this->ocsContext->before($scope);
$this->authContext->setUpScenario($scope);
$this->tusContext->setUpScenario($scope);
$environment->registerContext($this->ocsContext);
$environment->registerContext($this->authContext);
$environment->registerContext($this->tusContext);
$environment->registerContext($this->ocmContext);
// Get all the contexts you need in this context
$this->ocsContext = BehatHelper::getContext($scope, $environment, 'OCSContext');
$this->authContext = BehatHelper::getContext($scope, $environment, 'AuthContext');
$this->tusContext = BehatHelper::getContext($scope, $environment, 'TUSContext');
$this->ocmContext = BehatHelper::getContext($scope, $environment, 'OcmContext');
$this->graphContext = BehatHelper::getContext($scope, $environment, 'GraphContext');
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
$scenarioLine = $scope->getScenario()->getLine();
$featureFile = $scope->getFeature()->getFile();
$suiteName = $scope->getSuite()->getName();
$featureFileName = \basename($featureFile);
if (!OcisHelper::isTestingOnReva()) {
$this->spacesContext = new SpacesContext();
$this->spacesContext->setUpScenario($scope);
$environment->registerContext($this->spacesContext);
}
if (HttpRequestHelper::sendScenarioLineReferencesInXRequestId()) {
$this->scenarioString = $suiteName . '/' . $featureFileName . ':' . $scenarioLine;
} else {
$this->scenarioString = '';
}
// Initialize SetupHelper
@@ -2661,10 +2649,6 @@ class FeatureContext extends BehatVariablesContext {
$suiteParameters = SetupHelper::getSuiteParameters($scope);
$this->connectToLdap($suiteParameters);
}
$this->graphContext = new GraphContext();
$this->graphContext->before($scope);
$environment->registerContext($this->graphContext);
}
/**

View File

@@ -24,9 +24,10 @@ use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -571,6 +572,6 @@ class FilesVersionsContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
}

View File

@@ -13,11 +13,12 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\GraphHelper;
use TestHelpers\WebDavHelper;
use PHPUnit\Framework\Assert;
use TestHelpers\HttpRequestHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -47,10 +48,8 @@ class GraphContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context from here
$this->featureContext = $environment->getContext('FeatureContext');
if (!\TestHelpers\OcisHelper::isTestingOnReva()) {
$this->spacesContext = $environment->getContext('SpacesContext');
}
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
}
/**

View File

@@ -8,15 +8,16 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use TestHelpers\OcsApiHelper;
use Behat\Gherkin\Node\PyStringNode;
use TestHelpers\EmailHelper;
use PHPUnit\Framework\Assert;
use TestHelpers\GraphHelper;
use TestHelpers\SettingsHelper;
use Behat\Gherkin\Node\TableNode;
use Behat\Gherkin\Node\PyStringNode;
use PHPUnit\Framework\Assert;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\EmailHelper;
use TestHelpers\OcsApiHelper;
use TestHelpers\GraphHelper;
use TestHelpers\SettingsHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -94,13 +95,13 @@ class NotificationContext implements Context {
* @return void
* @throws Exception
*/
public function setUpScenario(BeforeScenarioScope $scope):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');
$this->spacesContext = $environment->getContext('SpacesContext');
$this->settingsContext = $environment->getContext('SettingsContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
$this->settingsContext = BehatHelper::getContext($scope, $environment, 'SettingsContext');
}
/**

View File

@@ -28,6 +28,7 @@ use Psr\Http\Message\ResponseInterface;
use PHPUnit\Framework\Assert;
use TestHelpers\OcsApiHelper;
use TestHelpers\TranslationHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -658,6 +659,6 @@ class OCSContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
}

View File

@@ -26,6 +26,7 @@ use Psr\Http\Message\ResponseInterface;
use TestHelpers\OcisHelper;
use TestHelpers\OcmHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
/**
* Acceptance test steps related to testing federation share(ocm) features
@@ -45,13 +46,10 @@ class OcmContext implements Context {
* @return void
*/
public function before(BeforeScenarioScope $scope): void {
if (OcisHelper::isTestingOnReva()) {
return;
}
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context from here
$this->featureContext = $environment->getContext('FeatureContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
/**
@@ -332,5 +330,4 @@ class OcmContext implements Context {
$ocmUser['idp']
);
}
}

View File

@@ -24,9 +24,10 @@ use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -1797,11 +1798,11 @@ class PublicWebDavContext implements Context {
*
* @return void
*/
public function setUpScenario(BeforeScenarioScope $scope):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');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
/**

View File

@@ -26,6 +26,7 @@ use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;
use TestHelpers\WebDavHelper;
use TestHelpers\HttpRequestHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -181,7 +182,7 @@ class SearchContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
/**

View File

@@ -12,11 +12,12 @@ declare(strict_types=1);
use Behat\Behat\Context\Context;
use GuzzleHttp\Exception\GuzzleException;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use TestHelpers\SettingsHelper;
use Behat\Gherkin\Node\TableNode;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -25,7 +26,6 @@ require_once 'bootstrap.php';
*/
class SettingsContext implements Context {
private FeatureContext $featureContext;
private string $baseUrl;
private string $settingsUrl = '/api/v0/settings/';
/**
@@ -42,8 +42,7 @@ class SettingsContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context from here
$this->featureContext = $environment->getContext('FeatureContext');
$this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/");
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
/**
@@ -56,7 +55,7 @@ class SettingsContext implements Context {
*/
public function getRoles(string $user): ResponseInterface {
return SettingsHelper::getRolesList(
$this->baseUrl,
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$this->featureContext->getStepLineRef()
@@ -90,7 +89,7 @@ class SettingsContext implements Context {
*/
public function assignRoleToUser(string $user, string $userId, string $roleId): ResponseInterface {
return SettingsHelper::assignRoleToUser(
$this->baseUrl,
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$userId,
@@ -110,7 +109,7 @@ class SettingsContext implements Context {
*/
public function getAssignmentsList(string $user, string $userId): ResponseInterface {
return SettingsHelper::getAssignmentsList(
$this->baseUrl,
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$userId,
@@ -294,7 +293,7 @@ class SettingsContext implements Context {
*/
public function sendRequestGetBundlesList(string $user): ResponseInterface {
return SettingsHelper::getBundlesList(
$this->baseUrl,
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$this->featureContext->getStepLineRef(),
@@ -312,7 +311,7 @@ class SettingsContext implements Context {
*/
public function getBundleByName(string $user, string $bundleName): array {
return SettingsHelper::getBundleByName(
$this->baseUrl,
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$bundleName,
@@ -331,7 +330,7 @@ class SettingsContext implements Context {
*/
public function sendRequestGetSettingsValuesList(string $user, array $headers = null): ResponseInterface {
return SettingsHelper::getValuesList(
$this->baseUrl,
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$this->featureContext->getStepLineRef(),
@@ -407,7 +406,7 @@ class SettingsContext implements Context {
JSON_THROW_ON_ERROR
);
return SettingsHelper::updateSettings(
$this->baseUrl,
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$body,
@@ -460,7 +459,7 @@ class SettingsContext implements Context {
);
return SettingsHelper::updateSettings(
$this->baseUrl,
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$body,

View File

@@ -27,6 +27,7 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Psr\Http\Message\ResponseInterface;
use PHPUnit\Framework\Assert;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -231,7 +232,7 @@ class ShareesContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->ocsContext = $environment->getContext('OCSContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->ocsContext = BehatHelper::getContext($scope, $environment, 'OCSContext');
}
}

View File

@@ -21,14 +21,15 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\GraphHelper;
use TestHelpers\OcisHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\HttpRequestHelper;
use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -50,14 +51,11 @@ class SharingNgContext implements Context {
* @return void
*/
public function before(BeforeScenarioScope $scope): void {
if (OcisHelper::isTestingOnReva()) {
return;
}
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context from here
$this->featureContext = $environment->getContext('FeatureContext');
$this->spacesContext = $environment->getContext('SpacesContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
}
/**

View File

@@ -27,12 +27,14 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\SetupHelper;
use TestHelpers\GraphHelper;
use PHPUnit\Framework\Assert;
use TestHelpers\OcisHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -47,7 +49,6 @@ class SpacesContext implements Context {
private FavoritesContext $favoritesContext;
private ChecksumContext $checksumContext;
private FilesVersionsContext $filesVersionsContext;
private string $baseUrl;
/**
* key is space name and value is the username that created the space
@@ -266,7 +267,7 @@ class SpacesContext implements Context {
*/
public function getFileData(string $user, string $spaceName, string $fileName): ResponseInterface {
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . $this->davSpacesUrl . $space["id"] . "/" . $fileName;
$fullUrl = $this->featureContext->getBaseUrl() . $this->davSpacesUrl . $space["id"] . "/" . $fileName;
return HttpRequestHelper::get(
$fullUrl,
@@ -388,32 +389,17 @@ class SpacesContext implements Context {
*
* @throws Exception
*/
public function setUpScenario(BeforeScenarioScope $scope): void {
public function before(BeforeScenarioScope $scope): void {
// Get the environment
$environment = $scope->getEnvironment();
// register new context
$this->trashbinContext = new TrashbinContext();
$this->webDavPropertiesContext = new WebDavPropertiesContext();
$this->favoritesContext = new FavoritesContext();
$this->checksumContext = new ChecksumContext();
$this->filesVersionsContext = new FilesVersionsContext();
$environment->registerContext($this->trashbinContext);
$environment->registerContext($this->webDavPropertiesContext);
$environment->registerContext($this->favoritesContext);
$environment->registerContext($this->checksumContext);
$environment->registerContext($this->filesVersionsContext);
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->ocsContext = $environment->getContext('OCSContext');
// Run the BeforeScenario function in OCSContext to set it up correctly
$this->ocsContext->before($scope);
$this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/");
SetupHelper::init(
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$this->baseUrl,
$this->featureContext->getOcPath()
);
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->ocsContext = BehatHelper::getContext($scope, $environment, 'OCSContext');
$this->trashbinContext = BehatHelper::getContext($scope, $environment, 'TrashbinContext');
$this->webDavPropertiesContext = BehatHelper::getContext($scope, $environment, 'WebDavPropertiesContext');
$this->favoritesContext = BehatHelper::getContext($scope, $environment, 'FavoritesContext');
$this->checksumContext = BehatHelper::getContext($scope, $environment, 'ChecksumContext');
$this->filesVersionsContext = BehatHelper::getContext($scope, $environment, 'FilesVersionsContext');
}
/**
@@ -424,6 +410,9 @@ class SpacesContext implements Context {
* @throws Exception|GuzzleException
*/
public function cleanDataAfterTests(): void {
if (OcisHelper::isTestingOnReva()) {
return;
}
$this->deleteAllProjectSpaces();
}
@@ -2135,7 +2124,7 @@ class SpacesContext implements Context {
"expireDate" => $rows["expireDate"]
];
$fullUrl = $this->baseUrl . $this->ocsApiUrl;
$fullUrl = $this->featureContext->getBaseUrl() . $this->ocsApiUrl;
return $this->sendPostRequestToUrl(
$fullUrl,
@@ -2197,7 +2186,7 @@ class SpacesContext implements Context {
$body["permissions"] = $rows["permissions"];
}
$fullUrl = $this->baseUrl . $this->ocsApiUrl;
$fullUrl = $this->featureContext->getBaseUrl() . $this->ocsApiUrl;
$response = $this->sendPostRequestToUrl(
$fullUrl,
$user,
@@ -2278,7 +2267,7 @@ class SpacesContext implements Context {
*/
public function updateSharedResource(string $user, array $rows):ResponseInterface {
$shareId = ($this->featureContext->isUsingSharingNG()) ? $this->featureContext->shareNgGetLastCreatedUserGroupShareID() : $this->featureContext->getLastCreatedUserGroupShareId();
$fullUrl = $this->baseUrl . $this->ocsApiUrl . '/' . $shareId;
$fullUrl = $this->featureContext->getBaseUrl() . $this->ocsApiUrl . '/' . $shareId;
return HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
@@ -2358,7 +2347,7 @@ class SpacesContext implements Context {
"expireDate" => $rows["expireDate"]
];
$fullUrl = $this->baseUrl . $this->ocsApiUrl;
$fullUrl = $this->featureContext->getBaseUrl() . $this->ocsApiUrl;
$response = $this->sendPostRequestToUrl(
$fullUrl,
@@ -2487,7 +2476,7 @@ class SpacesContext implements Context {
string $recipient
): ResponseInterface {
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . $this->ocsApiUrl . "/" . $space['id'] . "?shareWith=" . $recipient;
$fullUrl = $this->featureContext->getBaseUrl() . $this->ocsApiUrl . "/" . $space['id'] . "?shareWith=" . $recipient;
return HttpRequestHelper::delete(
$fullUrl,
@@ -2794,7 +2783,7 @@ class SpacesContext implements Context {
string $spaceName
): ResponseInterface {
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . $this->davSpacesUrl . "trash-bin/" . $space["id"];
$fullUrl = $this->featureContext->getBaseUrl() . $this->davSpacesUrl . "trash-bin/" . $space["id"];
return HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
@@ -2837,7 +2826,7 @@ class SpacesContext implements Context {
): void {
// get space by admin user
$space = $this->getSpaceByName($this->featureContext->getAdminUserName(), $spaceName);
$fullUrl = $this->baseUrl . $this->davSpacesUrl . "trash-bin/" . $space["id"];
$fullUrl = $this->featureContext->getBaseUrl() . $this->davSpacesUrl . "trash-bin/" . $space["id"];
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest($fullUrl, $this->featureContext->getStepLineRef(), 'PROPFIND', $user, $this->featureContext->getPasswordForUser($user))
);
@@ -2942,10 +2931,10 @@ class SpacesContext implements Context {
throw new Exception(__METHOD__ . " Object '$object' was not found in the trashbin of space '$spaceName' by user '$user'");
}
$destination = $this->baseUrl . $this->davSpacesUrl . $space["id"] . $destination;
$destination = $this->featureContext->getBaseUrl() . $this->davSpacesUrl . $space["id"] . $destination;
$header = ["Destination" => $destination, "Overwrite" => "F"];
$fullUrl = $this->baseUrl . $pathToDeletedObject;
$fullUrl = $this->featureContext->getBaseUrl() . $pathToDeletedObject;
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
@@ -2989,7 +2978,7 @@ class SpacesContext implements Context {
throw new Exception(__METHOD__ . " Object '$object' was not found in the trashbin of space '$spaceName' by user '$user'");
}
$fullUrl = $this->baseUrl . $pathToDeletedObject;
$fullUrl = $this->featureContext->getBaseUrl() . $pathToDeletedObject;
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
@@ -3036,7 +3025,7 @@ class SpacesContext implements Context {
$urlParameters = \http_build_query($urlParameters, '', '&');
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . $this->davSpacesUrl . $space['id'] . '/' . $fileName . '?' . $urlParameters;
$fullUrl = $this->featureContext->getBaseUrl() . $this->davSpacesUrl . $space['id'] . '/' . $fileName . '?' . $urlParameters;
$this->featureContext->setResponse(
HttpRequestHelper::get(
@@ -3331,7 +3320,7 @@ class SpacesContext implements Context {
"expireDate" => $rows["expireDate"]
];
$fullUrl = $this->baseUrl . $this->ocsApiUrl;
$fullUrl = $this->featureContext->getBaseUrl() . $this->ocsApiUrl;
$response = $this->sendPostRequestToUrl(
$fullUrl,

View File

@@ -11,10 +11,11 @@ declare(strict_types=1);
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use GuzzleHttp\Exception\GuzzleException;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -40,9 +41,9 @@ class SpacesTUSContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context from here
$this->featureContext = $environment->getContext('FeatureContext');
$this->spacesContext = $environment->getContext('SpacesContext');
$this->tusContext = $environment->getContext('TUSContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
$this->tusContext = BehatHelper::getContext($scope, $environment, 'TUSContext');
}
/**

View File

@@ -24,13 +24,14 @@ use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\GuzzleException;
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use TusPhp\Exception\ConnectionException;
use TusPhp\Exception\TusException;
use TusPhp\Tus\Client;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -458,11 +459,11 @@ class TUSContext implements Context {
*
* @return void
*/
public function setUpScenario(BeforeScenarioScope $scope): 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');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
// clear TUS locations cache
$this->tusResourceLocations = [];
}

View File

@@ -23,8 +23,9 @@ use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;
use TestHelpers\GraphHelper;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\GraphHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -49,8 +50,8 @@ class TagContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context from here
$this->featureContext = $environment->getContext('FeatureContext');
$this->spacesContext = $environment->getContext('SpacesContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
}
/**

View File

@@ -27,6 +27,7 @@ use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -1120,7 +1121,7 @@ class TrashbinContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
/**

View File

@@ -25,10 +25,11 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\OcisHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -991,10 +992,8 @@ class WebDavLockingContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->publicWebDavContext = $environment->getContext('PublicWebDavContext');
if (!OcisHelper::isTestingOnReva()) {
$this->spacesContext = $environment->getContext('SpacesContext');
}
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->publicWebDavContext = BehatHelper::getContext($scope, $environment, 'PublicWebDavContext');
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
}
}

View File

@@ -24,9 +24,10 @@ use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\Asserts\WebDav as WebDavTest;
use TestHelpers\WebDavHelper;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -1463,6 +1464,6 @@ class WebDavPropertiesContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}
}

View File

@@ -13,15 +13,15 @@ default:
ldapGroupsOU: TestGroups
ldapInitialUserFilePath: /../config/ldap-users.ldif
contexts:
- SettingsContext:
- GraphContext:
- SpacesContext:
- FeatureContext: &common_feature_context_params
baseUrl: http://localhost:8080
adminUsername: admin
adminPassword: admin
regularUserPassword: 123456
ocPath: apps/testing/api/v1/occ
- SettingsContext:
- GraphContext:
- SpacesContext:
- CapabilitiesContext:
- FilesVersionsContext:
- NotificationContext:
@@ -33,9 +33,9 @@ default:
- "%paths.base%/../features/apiSpaces"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- SettingsContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- CapabilitiesContext:
- FilesVersionsContext:
- NotificationContext:
@@ -54,9 +54,9 @@ default:
- "%paths.base%/../features/apiSpacesShares"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- SettingsContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- CapabilitiesContext:
- ChecksumContext:
- FavoritesContext:
@@ -77,9 +77,9 @@ default:
- "%paths.base%/../features/apiContract"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- SettingsContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- CapabilitiesContext:
- FilesVersionsContext:
- OCSContext:
@@ -95,10 +95,10 @@ default:
- "%paths.base%/../features/apiArchiver"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- SettingsContext:
- ArchiverContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- CapabilitiesContext:
- FilesVersionsContext:
- OCSContext:
@@ -111,10 +111,10 @@ default:
- "%paths.base%/../features/apiGraph"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- SettingsContext:
- GraphContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- CapabilitiesContext:
- FilesVersionsContext:
- OCSContext:
@@ -130,10 +130,10 @@ default:
- "%paths.base%/../features/apiGraphUserGroup"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- SettingsContext:
- GraphContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- CapabilitiesContext:
- FilesVersionsContext:
- OCSContext:
@@ -149,8 +149,8 @@ default:
- "%paths.base%/../features/apiCors"
context: *common_ldap_suite_context
contexts:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- SpacesContext:
- FilesVersionsContext:
- OCSContext:
- GraphContext:
@@ -164,8 +164,8 @@ default:
- "%paths.base%/../features/apiDepthInfinity"
context: *common_ldap_suite_context
contexts:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- SpacesContext:
- OCSContext:
- GraphContext:
- PublicWebDavContext:
@@ -178,8 +178,8 @@ default:
- "%paths.base%/../features/apiAsyncUpload"
context: *common_ldap_suite_context
contexts:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- SpacesContext:
- WebDavPropertiesContext:
- FilesVersionsContext:
- OCSContext:
@@ -192,8 +192,8 @@ default:
context: *common_ldap_suite_context
contexts:
- NotificationContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- SpacesContext:
- OCSContext:
- GraphContext:
- FilesVersionsContext:
@@ -207,9 +207,9 @@ default:
- "%paths.base%/../features/apiAntivirus"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- NotificationContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- OCSContext:
- GraphContext:
- FilesVersionsContext:
@@ -223,9 +223,9 @@ default:
- "%paths.base%/../features/apiDownloads"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- NotificationContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- WebDavPropertiesContext:
- OCSContext:
- GraphContext:
@@ -262,10 +262,10 @@ default:
- "%paths.base%/../features/apiSearch2"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- SettingsContext:
- GraphContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- FilesVersionsContext:
- SearchContext:
- OCSContext:
@@ -280,11 +280,11 @@ default:
- "%paths.base%/../features/apiSearchContent"
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- SettingsContext:
- GraphContext:
- SpacesContext:
- PublicWebDavContext:
- FeatureContext: *common_feature_context_params
- SearchContext:
- CapabilitiesContext:
- FilesVersionsContext: