mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-07 15:43:11 -04:00
Implement user drive information
This commit is contained in:
committed by
Phil Davis
parent
46575abe11
commit
e15afb04d4
@@ -26,16 +26,43 @@ class GraphHelper {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getUUIDv4Regex(): string {
|
||||
return '[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return int (1 = true | 0 = false)
|
||||
*/
|
||||
public static function isUUIDv4(string $id): int {
|
||||
$regex = '/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i';
|
||||
$regex = "/^" . self::getUUIDv4Regex() . "/i";
|
||||
return preg_match($regex, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $spaceId
|
||||
*
|
||||
* @return int (1 = true | 0 = false)
|
||||
*/
|
||||
public static function isSpaceId(string $spaceId): int {
|
||||
$regex = "/^" . self::getUUIDv4Regex() . '\\$' . self::getUUIDv4Regex() . "/i";
|
||||
return preg_match($regex, $spaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function isUUIDv44(string $id): string {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $path
|
||||
|
||||
@@ -61,27 +61,33 @@ Feature: get users
|
||||
| displayName | id | mail | onPremisesSamAccountName |
|
||||
| Brian Murphy | %uuid_v4% | brian@example.org | Brian |
|
||||
And the user retrieve API response should contain the following drive information:
|
||||
# | driveType | personal |
|
||||
# | driveAlias | personal/brian |
|
||||
# | id | %space_id% |
|
||||
# | name | Brian Murphy |
|
||||
| driveType | personal |
|
||||
| driveAlias | personal/brian |
|
||||
| id | %space_id% |
|
||||
| name | Brian Murphy |
|
||||
| owner@@@user@@@id | %user_id% |
|
||||
# | quota@@@state | normal |
|
||||
# | root@@@id | %space_id% |
|
||||
# | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
|
||||
# | webUrl | %base_url%/f/%space_id% |
|
||||
| quota@@@state | normal |
|
||||
| root@@@id | %space_id% |
|
||||
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
|
||||
| webUrl | %base_url%/f/%space_id% |
|
||||
|
||||
|
||||
# Scenario: normal user tries to get hid/her own drive information
|
||||
# Given these users have been created with default attributes and without skeleton files:
|
||||
# | username |
|
||||
# | Brian |
|
||||
# When the user "Brian" tries to get his drive information using Graph API
|
||||
# Then the HTTP status code should be "200"
|
||||
# And the user retrieve API response should contain the following information:
|
||||
# | displayName | id | mail | onPremisesSamAccountName |
|
||||
# | Brian Murphy | %uuid_v4% | brian@example.org | Brian |
|
||||
# And the response should contain the following drive information:
|
||||
# | driveType | personal |
|
||||
# | driveAlias | personal/brian |
|
||||
# | name | Brian Murphy |
|
||||
Scenario: normal user tries to get hid/her own drive information
|
||||
Given these users have been created with default attributes and without skeleton files:
|
||||
| username |
|
||||
| Brian |
|
||||
When the user "Brian" tries to get his drive information using Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the user retrieve API response should contain the following information:
|
||||
| displayName | id | mail | onPremisesSamAccountName |
|
||||
| Brian Murphy | %uuid_v4% | brian@example.org | Brian |
|
||||
And the user retrieve API response should contain the following drive information:
|
||||
| driveType | personal |
|
||||
| driveAlias | personal/brian |
|
||||
| id | %space_id% |
|
||||
| name | Brian Murphy |
|
||||
| owner@@@user@@@id | %user_id% |
|
||||
| quota@@@state | normal |
|
||||
| root@@@id | %space_id% |
|
||||
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
|
||||
| webUrl | %base_url%/f/%space_id% |
|
||||
|
||||
@@ -28,10 +28,10 @@ class GraphContext implements Context {
|
||||
*/
|
||||
private FeatureContext $featureContext;
|
||||
|
||||
/**
|
||||
* @var SpacesContext
|
||||
*/
|
||||
private SpacesContext $spacesContext;
|
||||
/**
|
||||
* @var SpacesContext
|
||||
*/
|
||||
private SpacesContext $spacesContext;
|
||||
|
||||
/**
|
||||
* This will run before EVERY scenario.
|
||||
@@ -1363,44 +1363,82 @@ class GraphContext implements Context {
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $driveInformation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSpaceIdFromActualDriveinformation(array $driveInformation): string {
|
||||
return $driveInformation['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $expectedDriveInformation
|
||||
* @param array $actualValueDriveInformation
|
||||
*
|
||||
* @throws GuzzleException
|
||||
* @return void
|
||||
*/
|
||||
public function checkUserDriveInformation(array $expectedDriveInformation, array $actualValueDriveInformation):void {
|
||||
foreach (array_keys($expectedDriveInformation) as $keyName) {
|
||||
// break the segment with @@@ here
|
||||
$separatedKey = explode("@@@",$keyName);
|
||||
$actualKeyAvalue = null;
|
||||
$actualKeyAvalue = $actualValueDriveInformation['owner'];
|
||||
var_dump(
|
||||
$actualKeyAvalue
|
||||
);
|
||||
foreach ($separatedKey as $key) {
|
||||
// this loop sets and get the actual keyvalue from the actual API response
|
||||
$actualKeyAvalue = $actualValueDriveInformation[$key];
|
||||
}
|
||||
var_dump(
|
||||
$actualKeyAvalue
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* check if single drive information is correct
|
||||
*
|
||||
* @param array $expectedDriveInformation
|
||||
* @param array $actualValueDriveInformation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function checkUserDriveInformation(array $expectedDriveInformation, array $actualValueDriveInformation):void {
|
||||
foreach (array_keys($expectedDriveInformation) as $keyName) {
|
||||
// break the segment with @@@ to find the actual value from the drive infromation from response
|
||||
$separatedKey = explode("@@@", $keyName);
|
||||
// this stores the actual value of each key from drive information response used for assertion
|
||||
$actualKeyValueFromDriveInformation = null;
|
||||
$tempDriveInfo = $actualValueDriveInformation;
|
||||
|
||||
foreach ($separatedKey as $key) {
|
||||
$actualKeyValueFromDriveInformation = $tempDriveInfo[$key];
|
||||
$tempDriveInfo = $actualKeyValueFromDriveInformation;
|
||||
}
|
||||
switch ($expectedDriveInformation[$keyName]) {
|
||||
case '%user_id%':
|
||||
Assert::assertEquals(
|
||||
1,
|
||||
GraphHelper::isUUIDv4($actualKeyValueFromDriveInformation),
|
||||
__METHOD__ .
|
||||
' Expected user_id to have UUIDv4 pattern but found: ' . $actualKeyValueFromDriveInformation
|
||||
);
|
||||
break;
|
||||
case '%space_id%':
|
||||
Assert::assertEquals(
|
||||
1,
|
||||
GraphHelper::isSpaceId($actualKeyValueFromDriveInformation),
|
||||
__METHOD__ .
|
||||
' Expected user_id to have UUIDv4 pattern but found: ' . $actualKeyValueFromDriveInformation
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$expectedDriveInformation[$keyName] = $this->featureContext->substituteInLineCodes(
|
||||
$expectedDriveInformation[$keyName],
|
||||
$this->featureContext->getCurrentUser(),
|
||||
[],
|
||||
[
|
||||
[
|
||||
"code" => "%space_id%",
|
||||
"function" =>
|
||||
[$this, "getSpaceIdFromActualDriveinformation"],
|
||||
"parameter" => [$actualValueDriveInformation]
|
||||
],
|
||||
]
|
||||
);
|
||||
Assert::assertEquals($expectedDriveInformation[$keyName], $actualKeyValueFromDriveInformation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Then the user retrieve API response should contain the following drive information:
|
||||
*/
|
||||
public function theResponseShouldContainTheFollowingDriveInformation(TableNode $table)
|
||||
{
|
||||
$expectedDriveInformation = $table->getRowsHash();
|
||||
// array of user drive information (Personal Drive Information Only)
|
||||
$actualDriveInformation = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['drive'];
|
||||
$this->checkUserDriveInformation($expectedDriveInformation, $actualDriveInformation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @Then the user retrieve API response should contain the following drive information:
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theResponseShouldContainTheFollowingDriveInformation(TableNode $table): void {
|
||||
$expectedDriveInformation = $table->getRowsHash();
|
||||
// array of user drive information (Personal Drive Information Only)
|
||||
$actualDriveInformation = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['drive'];
|
||||
$this->checkUserDriveInformation($expectedDriveInformation, $actualDriveInformation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -913,9 +913,6 @@ class SpacesContext implements Context {
|
||||
foreach ($table->getHash() as $row) {
|
||||
// remember the original Space Array
|
||||
$original = $spaceAsArray;
|
||||
var_dump(
|
||||
$original
|
||||
);
|
||||
$row['value'] = $this->featureContext->substituteInLineCodes(
|
||||
$row['value'],
|
||||
$this->featureContext->getCurrentUser(),
|
||||
|
||||
Reference in New Issue
Block a user