api-tests: search for favorites (#2487)

This commit is contained in:
Viktor Scharf
2026-03-18 11:10:09 +01:00
committed by GitHub
parent e161069317
commit 627f9a742e
3 changed files with 182 additions and 69 deletions
@@ -20,8 +20,6 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
require_once 'bootstrap.php';
@@ -30,72 +28,8 @@ require_once 'bootstrap.php';
* context containing favorites related API steps
*/
class FavoritesContext implements Context {
private FeatureContext $featureContext;
private WebDavPropertiesContext $webDavPropertiesContext;
/**
* @Then /^user "([^"]*)" should (not|)\s?have the following favorited items$/
*
* @param string $user
* @param string $shouldOrNot (not|)
* @param TableNode $expectedElements
*
* @return void
*/
public function checkFavoritedElements(
string $user,
string $shouldOrNot,
TableNode $expectedElements
): void {
$user = $this->featureContext->getActualUsername($user);
$this->userListsFavorites($user);
$this->featureContext->propfindResultShouldContainEntries(
$shouldOrNot,
$expectedElements,
$user
);
}
/**
* @When /^user "([^"]*)" lists the favorites and limits the result to ([\d*]) elements using the WebDAV API$/
*
* @param string $user
* @param int|null $limit
*
* @return void
*/
public function userListsFavorites(string $user, ?int $limit = null): void {
$renamedUser = $this->featureContext->getActualUsername($user);
$baseUrl = $this->featureContext->getBaseUrl();
$password = $this->featureContext->getPasswordForUser($user);
$body
= "<?xml version='1.0' encoding='utf-8' ?>\n" .
" <oc:filter-files xmlns:a='DAV:' xmlns:oc='http://owncloud.org/ns' >\n" .
" <a:prop><oc:favorite/></a:prop>\n" .
" <oc:filter-rules><oc:favorite>1</oc:favorite></oc:filter-rules>\n";
if ($limit !== null) {
$body .= " <oc:search>\n" .
" <oc:limit>$limit</oc:limit>\n" .
" </oc:search>\n";
}
$body .= " </oc:filter-files>";
$response = WebDavHelper::makeDavRequest(
$baseUrl,
$renamedUser,
$password,
"REPORT",
"/",
null,
null,
$this->featureContext->getStepLineRef(),
$body,
$this->featureContext->getDavPathVersion()
);
$this->featureContext->setResponse($response);
}
/**
* @Then /^as user "([^"]*)" (?:file|folder|entry) "([^"]*)" should be favorited$/
*
@@ -149,7 +83,6 @@ class FavoritesContext implements Context {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
$this->webDavPropertiesContext = BehatHelper::getContext(
$scope,
$environment,