favorites tests (#2474)

This commit is contained in:
Viktor Scharf
2026-03-16 14:49:17 +01:00
committed by GitHub
parent 1623a5080c
commit e161069317
12 changed files with 786 additions and 531 deletions
@@ -21,7 +21,6 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
@@ -34,73 +33,6 @@ class FavoritesContext implements Context {
private FeatureContext $featureContext;
private WebDavPropertiesContext $webDavPropertiesContext;
/**
* @param string$user
* @param string $path
* @param string|null $spaceId
*
* @return ResponseInterface
*/
public function userFavoritesElement(string $user, string $path, ?string $spaceId = null): ResponseInterface {
return $this->changeFavStateOfAnElement(
$user,
$path,
1,
$spaceId
);
}
/**
* @When user :user favorites element :path using the WebDAV API
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userFavoritesElementUsingWebDavApi(string $user, string $path): void {
$this->featureContext->setResponse($this->userFavoritesElement($user, $path));
}
/**
* @Given user :user has favorited element :path
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userHasFavoritedElementUsingWebDavApi(string $user, string $path): void {
$this->featureContext->theHTTPStatusCodeShouldBe(207, '', $this->userFavoritesElement($user, $path));
}
/**
* @param string $user
* @param string $path
*
* @return ResponseInterface
*/
public function userUnfavoritesElement(string $user, string $path): ResponseInterface {
return $this->changeFavStateOfAnElement(
$user,
$path,
0,
null,
);
}
/**
* @When user :user unfavorites element :path using the WebDAV API
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userUnfavoritesElementUsingWebDavApi(string $user, string $path): void {
$this->featureContext->setResponse($this->userUnfavoritesElement($user, $path));
}
/**
* @Then /^user "([^"]*)" should (not|)\s?have the following favorited items$/
*
@@ -203,38 +135,6 @@ class FavoritesContext implements Context {
$this->asUserFileOrFolderShouldBeFavorited($user, $path, 0);
}
/**
* Set the elements of a proppatch
*
* @param string $user
* @param string $path
* @param int|null $favOrUnfav 1 = favorite, 0 = unfavorite
* @param string|null $spaceId
*
* @return ResponseInterface
*/
public function changeFavStateOfAnElement(
string $user,
string $path,
?int $favOrUnfav,
?string $spaceId,
): ResponseInterface {
$renamedUser = $this->featureContext->getActualUsername($user);
return WebDavHelper::proppatch(
$this->featureContext->getBaseUrl(),
$renamedUser,
$this->featureContext->getPasswordForUser($user),
$path,
'favorite',
(string)$favOrUnfav,
$this->featureContext->getStepLineRef(),
"oc='http://owncloud.org/ns'",
$this->featureContext->getDavPathVersion(),
'files',
$spaceId
);
}
/**
* This will run before EVERY scenario.
* It will set the properties for this object.
+129
View File
@@ -3207,4 +3207,133 @@ class GraphContext implements Context {
$this->featureContext->setResponse($response);
}
/**
* @param string $user
* @param string $itemId
*
* @return ResponseInterface
*/
public function markFavorite(string $user, string $itemId): ResponseInterface {
$response = GraphHelper::markFavorite(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$itemId
);
$this->featureContext->setResponse($response);
return $response;
}
/**
* @param string $user
* @param string $itemId
*
* @return ResponseInterface
*/
public function unmarkFavorite(string $user, string $itemId): ResponseInterface {
$response = GraphHelper::unmarkFavorite(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$itemId
);
$this->featureContext->setResponse($response);
return $response;
}
/**
* @When user :user marks :item :itemName as favorite from space :spaceName using the Graph API
*
* @param string $user
* @param string $item (file|folder)
* @param string $itemName
* @param string $spaceName
*
* @return void
*/
public function userMarksItemFromSpaceAsFavoriteUsingTheGraphApi(
string $user,
string $item,
string $itemName,
string $spaceName
): void {
$itemId = ($item === 'file')
? $this->spacesContext->getFileId($user, $spaceName, $itemName)
: $this->spacesContext->getResourceId($user, $spaceName, $itemName);
$this->markFavorite($user, $itemId);
}
/**
* @When user :user unmarks :item :itemName as favorite from space :spaceName using the Graph API
*
* @param string $user
* @param string $item (file|folder)
* @param string $itemName
* @param string $spaceName
*
* @return void
*/
public function userUnmarksItemFromSpaceAsFavoriteUsingTheGraphApi(
string $user,
string $item,
string $itemName,
string $spaceName
): void {
$itemId = ($item === 'file')
? $this->spacesContext->getFileId($user, $spaceName, $itemName)
: $this->spacesContext->getResourceId($user, $spaceName, $itemName);
$this->unmarkFavorite($user, $itemId);
}
/**
* @Given user :user has marked :item :itemName as favorite from space :spaceName
*
* @param string $user
* @param string $item (folder|file)
* @param string $itemName
* @param string $spaceName
*
* @return void
*/
public function userHasMarkedItemFromSpaceAsFavoriteUsingTheGraphApi(
string $user,
string $item,
string $itemName,
string $spaceName
): void {
$itemId = ($item === 'file')
? $this->spacesContext->getFileId($user, $spaceName, $itemName)
: $this->spacesContext->getResourceId($user, $spaceName, $itemName);
$response = $this->markFavorite($user, $itemId);
$this->featureContext->theHTTPStatusCodeShouldBe(201, '', $response);
}
/**
* @Given user :user has unmarked :item :itemName as favorite from space :spaceName
*
* @param string $user
* @param string $item (folder|file)
* @param string $itemName
* @param string $spaceName
*
* @return void
*/
public function userHasUnmarkedItemFromSpaceAsFavoriteUsingTheGraphApi(
string $user,
string $item,
string $itemName,
string $spaceName
): void {
$itemId = ($item === 'file')
? $this->spacesContext->getFileId($user, $spaceName, $itemName)
: $this->spacesContext->getResourceId($user, $spaceName, $itemName);
$response = $this->unmarkFavorite($user, $itemId);
$this->featureContext->theHTTPStatusCodeShouldBe(204, '', $response);
}
}